public function random(array $array) { if ($array === []) { return null; } $randomIndex = array_rand($array); return $array[$randomIndex]; }
/** * @test * @dataProvider randomExamples */ public function randomWorks($array, $expected) { $helper = new ArrayHelper(); $result = $helper->random($array); $this->assertEquals($expected, in_array($result, $array)); }