-
-
Notifications
You must be signed in to change notification settings - Fork 499
/
RandomBytesGeneratorTest.php
56 lines (50 loc) · 1.54 KB
/
RandomBytesGeneratorTest.php
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
<?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();
$this->assertSame($bytes, $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));
}
}