1
0
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:
David Stensland 2014-03-06 08:27:08 -05:00
parent a68fa66941
commit 6d2253cc56
2 changed files with 10 additions and 1 deletions

View File

@ -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];
}
/**

View File

@ -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, '#');