mirror of
https://github.com/fzaninotto/Faker.git
synced 2025-03-24 09:19:50 +01:00
Returns a random element from a passed indexed and associative array
This commit is contained in:
parent
4ad4bc4b5c
commit
c23e499e83
@ -124,7 +124,9 @@ class Base
|
||||
*/
|
||||
public static function randomElement($array = array('a', 'b', 'c'))
|
||||
{
|
||||
return $array[mt_rand(0, count($array) - 1)];
|
||||
$key = array_rand($array);
|
||||
|
||||
return $array[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,6 +90,12 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertContains(BaseProvider::randomElement($elements), $elements);
|
||||
}
|
||||
|
||||
public function testRandomElementReturnsElementFromAssociativeArray()
|
||||
{
|
||||
$elements = array('tata' => '23', 'toto' => 'e', 'tutu' => 32, 'titi' => '#');
|
||||
$this->assertContains(BaseProvider::randomElement($elements), $elements);
|
||||
}
|
||||
|
||||
public function testNumerifyReturnsSameStringWhenItContainsNoHashSign()
|
||||
{
|
||||
$this->assertEquals('fooBar?', BaseProvider::numerify('fooBar?'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user