mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
Merge pull request #138 from jmauerhan/master
Unit Tests: Add function mock test for systems without libsodium
This commit is contained in:
+2
-1
@@ -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": "^0.3|^1.1"
|
||||
},
|
||||
"suggest": {
|
||||
"ircmaxell/random-lib": "Provides RandomLib for use with the RandomLibAdapter",
|
||||
|
||||
@@ -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,17 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user