From 761e5115be27ec003a262baa25a79e43b1dfc906 Mon Sep 17 00:00:00 2001 From: Jessica Mauerhan Date: Tue, 4 Oct 2016 16:23:36 -0400 Subject: [PATCH 1/3] Add function mock test for systems without libsodium --- composer.json | 3 ++- tests/Generator/SodiumRandomGeneratorTest.php | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 678b01a..7c0bf08 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,8 @@ "apigen/apigen": "^4.1", "mockery/mockery": "^0.9.4", "goaop/framework": "1.0.0-alpha.2", - "codeception/aspect-mock": "1.0.0" + "codeception/aspect-mock": "1.0.0", + "php-mock/php-mock-phpunit": "^1.1" }, "suggest": { "ircmaxell/random-lib": "Provides RandomLib for use with the RandomLibAdapter", diff --git a/tests/Generator/SodiumRandomGeneratorTest.php b/tests/Generator/SodiumRandomGeneratorTest.php index 9579b18..b421d3c 100644 --- a/tests/Generator/SodiumRandomGeneratorTest.php +++ b/tests/Generator/SodiumRandomGeneratorTest.php @@ -2,12 +2,15 @@ namespace Ramsey\Uuid\Test\Generator; +use phpmock\phpunit\PHPMock; use Ramsey\Uuid\Test\TestCase; use Ramsey\Uuid\Generator\SodiumRandomGenerator; class SodiumRandomGeneratorTest extends TestCase { - protected function setUp() + use PHPMock; + + protected function skipIfLibsodiumExtensionNotLoaded() { if (!extension_loaded('libsodium')) { $this->markTestSkipped( @@ -18,6 +21,7 @@ class SodiumRandomGeneratorTest extends TestCase public function testGenerateReturnsBytes() { + $this->skipIfLibsodiumExtensionNotLoaded(); $generator = new SodiumRandomGenerator(); $bytes = $generator->generate(16); @@ -28,6 +32,7 @@ class SodiumRandomGeneratorTest extends TestCase public function testFactoryUsesSodiumRandomGenerator() { + $this->skipIfLibsodiumExtensionNotLoaded(); $uuidFactory = new \Ramsey\Uuid\UuidFactory(); $uuidFactory->setRandomGenerator(new SodiumRandomGenerator()); \Ramsey\Uuid\Uuid::setFactory($uuidFactory); @@ -39,4 +44,18 @@ class SodiumRandomGeneratorTest extends TestCase $uuid->getFactory()->getRandomGenerator() ); } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testGenerateUsesSodiumLibrary() + { + $randomBytesFunc = $this->getFunctionMock('Sodium', 'randombytes_buf'); + $randomBytesFunc->expects($this->once()) + ->with(10); + $generator = new SodiumRandomGenerator(); + $generator->generate(10); + } + } From ae2d1f8ca963ecd5261cd6e8e7f17104f870140f Mon Sep 17 00:00:00 2001 From: Jessica Mauerhan Date: Thu, 6 Oct 2016 11:00:35 -0400 Subject: [PATCH 2/3] Add older version of phpmock --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7c0bf08..b18335b 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "mockery/mockery": "^0.9.4", "goaop/framework": "1.0.0-alpha.2", "codeception/aspect-mock": "1.0.0", - "php-mock/php-mock-phpunit": "^1.1" + "php-mock/php-mock-phpunit": "^0.3|^1.1" }, "suggest": { "ircmaxell/random-lib": "Provides RandomLib for use with the RandomLibAdapter", From e0c2ff2a09536c5680cc40a6c0a4c41b44fdc580 Mon Sep 17 00:00:00 2001 From: Jessica Mauerhan Date: Thu, 6 Oct 2016 11:10:40 -0400 Subject: [PATCH 3/3] Fix code style --- tests/Generator/SodiumRandomGeneratorTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Generator/SodiumRandomGeneratorTest.php b/tests/Generator/SodiumRandomGeneratorTest.php index b421d3c..d118fd3 100644 --- a/tests/Generator/SodiumRandomGeneratorTest.php +++ b/tests/Generator/SodiumRandomGeneratorTest.php @@ -57,5 +57,4 @@ class SodiumRandomGeneratorTest extends TestCase $generator = new SodiumRandomGenerator(); $generator->generate(10); } - }