mirror of
https://github.com/fzaninotto/Faker.git
synced 2025-03-20 23:39:51 +01:00
Rewrite randomElement to use randomElements, and add test
This commit is contained in:
parent
a68fa66941
commit
6d2253cc56
@ -167,7 +167,11 @@ class Base
|
||||
*/
|
||||
public static function randomElement($array = array('a', 'b', 'c'))
|
||||
{
|
||||
return $array ? $array[self::randomKey($array)] : null;
|
||||
if (!$array) {
|
||||
return null;
|
||||
}
|
||||
$elements = static::randomElements($array, 1);
|
||||
return $elements[0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,6 +84,11 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue(strpos($lowercaseLetters, BaseProvider::randomLetter()) !== false);
|
||||
}
|
||||
|
||||
public function testRandomElementReturnsNullWhenArrayEmpty()
|
||||
{
|
||||
$this->assertNull(BaseProvider::randomElement(array()));
|
||||
}
|
||||
|
||||
public function testRandomElementReturnsElementFromArray()
|
||||
{
|
||||
$elements = array('23', 'e', 32, '#');
|
||||
|
Loading…
x
Reference in New Issue
Block a user