1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
<?php
declare(strict_types=1);
namespace Ramsey\Uuid\Test\Generator;
use Mockery;
use Mockery\MockInterface;
use Ramsey\Uuid\Generator\RandomLibAdapter;
use Ramsey\Uuid\Test\TestCase;
use RandomLib\Factory as RandomLibFactory;
use RandomLib\Generator;
class RandomLibAdapterTest extends TestCase
{
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testAdapterWithGeneratorDoesNotCreateGenerator(): void
{
$factory = Mockery::mock('overload:' . RandomLibFactory::class);
$factory->shouldNotReceive('getHighStrengthGenerator');
$generator = $this->getMockBuilder(Generator::class)
->disableOriginalConstructor()
->getMock();
$this->assertInstanceOf(RandomLibAdapter::class, new RandomLibAdapter($generator));
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testAdapterWithoutGeneratorGreatesGenerator(): void
{
$generator = Mockery::mock(Generator::class);
/** @var RandomLibFactory&MockInterface $factory */
$factory = Mockery::mock('overload:' . RandomLibFactory::class);
$factory->expects()->getHighStrengthGenerator()->andReturns($generator);
$this->assertInstanceOf(RandomLibAdapter::class, new RandomLibAdapter());
}
public function testGenerateUsesGenerator(): void
{
$length = 10;
$generator = $this->getMockBuilder(Generator::class)
->disableOriginalConstructor()
->getMock();
$generator->expects($this->once())
->method('generate')
->with($length)
->willReturn('foo');
$adapter = new RandomLibAdapter($generator);
$adapter->generate($length);
}
public function testGenerateReturnsString(): void
{
$generator = $this->getMockBuilder(Generator::class)
->disableOriginalConstructor()
->getMock();
$generator->expects($this->once())
->method('generate')
->willReturn('random-string');
$adapter = new RandomLibAdapter($generator);
$result = $adapter->generate(1);
$this->assertSame('random-string', $result);
}
}
|