/** * Tests Text::random() as well as possible * * Obviously you can't compare a randomly generated string against a * pre-generated one and check that they are the same as this goes * against the whole ethos of random. * * This test just makes sure that the value returned is of the correct * values and length * * @test * @dataProvider provider_random */ public function test_random($type, $length) { if ($type === null) { $type = 'alnum'; } $pool = (string) $type; switch ($pool) { case 'alnum': $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'alpha': $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'hexdec': $pool = '0123456789abcdef'; break; case 'numeric': $pool = '0123456789'; break; case 'nozero': $pool = '123456789'; break; case 'distinct': $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ'; break; } $this->assertRegExp('/^[' . $pool . ']{' . $length . '}$/u', Text::random($type, $length)); }