From f93018f756507cbd89f97a527fa2e70a4bdf7439 Mon Sep 17 00:00:00 2001 From: Jessica Mauerhan Date: Wed, 23 Mar 2016 08:37:20 -0400 Subject: [PATCH] added open ssl generator tests --- tests/src/Generator/OpenSslGeneratorTest.php | 59 ++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/src/Generator/OpenSslGeneratorTest.php diff --git a/tests/src/Generator/OpenSslGeneratorTest.php b/tests/src/Generator/OpenSslGeneratorTest.php new file mode 100644 index 0000000..4ab3e1c --- /dev/null +++ b/tests/src/Generator/OpenSslGeneratorTest.php @@ -0,0 +1,59 @@ +skipIfHhvm(); + parent::setUp(); + } + + public function tearDown() + { + parent::tearDown(); + AspectMock::clean(); + } + + public function lengthAndHexDataProvider() + { + return [ + [6, '005340670735'], + [10, '292be7f7e462b2b2d24a'], + [12, 'a9e3504ed48cffefe412eb70'] + ]; + } + + /** + * @dataProvider lengthAndHexDataProvider + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testGenerateUsesOpenSsl($length, $hex) + { + $bytes = hex2bin($hex); + $openSsl = AspectMock::func('Ramsey\Uuid\Generator', 'openssl_random_pseudo_bytes', $bytes); + $generator = new OpenSslGenerator(); + $generator->generate($length); + + $openSsl->verifyInvokedOnce([$length]); + } + + /** + * @dataProvider lengthAndHexDataProvider + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testGenerateReturnsRandomBytes($length, $hex) + { + $bytes = hex2bin($hex); + AspectMock::func('Ramsey\Uuid\Generator', 'openssl_random_pseudo_bytes', $bytes); + $generator = new OpenSslGenerator(); + $this->assertEquals($bytes, $generator->generate($length)); + } +}