Files
php-uuid/tests/Generator/RandomBytesGeneratorTest.php
T
Martin Hujer f3e0fed2d7 Drop remnants of HHVM from tests
It was removed from Travis in c479cdd42f
2019-11-30 09:10:09 -08:00

57 lines
1.5 KiB
PHP

<?php
namespace Ramsey\Uuid\Test\Generator;
use Ramsey\Uuid\Generator\RandomBytesGenerator;
use Ramsey\Uuid\Test\TestCase;
use AspectMock\Test as AspectMock;
/**
* Class RandomBytesGeneratorTest
* @package Ramsey\Uuid\Test\Generator
* @covers Ramsey\Uuid\Generator\RandomBytesGenerator
*/
class RandomBytesGeneratorTest extends TestCase
{
public function lengthAndHexDataProvider()
{
return [
[6, '4f17dd046fb8'],
[10, '4d25f6fe5327cb04267a'],
[12, '1ea89f83bd49cacfdf119e24']
];
}
/**
* @dataProvider lengthAndHexDataProvider
* @runInSeparateProcess
* @preserveGlobalState disabled
* @param int $length
* @param string $hex
*/
public function testGenerateUsesOpenSsl($length, $hex)
{
$bytes = hex2bin($hex);
$openSsl = AspectMock::func('Ramsey\Uuid\Generator', 'random_bytes', $bytes);
$generator = new RandomBytesGenerator();
$generator->generate($length);
$openSsl->verifyInvokedOnce([$length]);
}
/**
* @dataProvider lengthAndHexDataProvider
* @runInSeparateProcess
* @preserveGlobalState disabled
* @param int $length
* @param string $hex
*/
public function testGenerateReturnsRandomBytes($length, $hex)
{
$bytes = hex2bin($hex);
AspectMock::func('Ramsey\Uuid\Generator', 'random_bytes', $bytes);
$generator = new RandomBytesGenerator();
$this->assertEquals($bytes, $generator->generate($length));
}
}