1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Xmf\Test; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
8
|
|
|
|
9
|
|
|
use Xmf\Uuid; |
10
|
|
|
|
11
|
|
|
class UuidTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Random |
15
|
|
|
*/ |
16
|
|
|
protected $object; |
17
|
|
|
protected $myClass = Uuid::class; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Sets up the fixture, for example, opens a network connection. |
21
|
|
|
* This method is called before a test is executed. |
22
|
|
|
*/ |
23
|
|
|
protected function setUp(): void |
24
|
|
|
{ |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Tears down the fixture, for example, closes a network connection. |
29
|
|
|
* This method is called after a test is executed. |
30
|
|
|
*/ |
31
|
|
|
protected function tearDown(): void |
32
|
|
|
{ |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGenerate() |
36
|
|
|
{ |
37
|
|
|
// match spec for version 4 UUID as per rfc4122 |
38
|
|
|
$uuidMatch = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/'; |
39
|
|
|
|
40
|
|
|
try { |
41
|
|
|
$result = Uuid::generate(); |
42
|
|
|
} catch (\Exception $e) { |
|
|
|
|
43
|
|
|
} |
44
|
|
|
$this->assertMatchesRegularExpression($uuidMatch, $result); |
45
|
|
|
|
46
|
|
|
try { |
47
|
|
|
$anotherResult = Uuid::generate(); |
48
|
|
|
} catch (\Exception $e) { |
|
|
|
|
49
|
|
|
} |
50
|
|
|
$this->assertMatchesRegularExpression($uuidMatch, $anotherResult); |
51
|
|
|
|
52
|
|
|
$this->assertNotEquals($result, $anotherResult); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testPackUnpack() |
56
|
|
|
{ |
57
|
|
|
try { |
58
|
|
|
$uuid = Uuid::generate(); |
59
|
|
|
} catch (\Exception $e) { |
|
|
|
|
60
|
|
|
} |
61
|
|
|
$binUuid = Uuid::packAsBinary($uuid); |
62
|
|
|
$strUuid = Uuid::unpackBinary($binUuid); |
63
|
|
|
$this->assertEquals($uuid, $strUuid); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testInvalidPack() |
67
|
|
|
{ |
68
|
|
|
$this->expectException(\InvalidArgumentException::class); |
69
|
|
|
$binUuid = Uuid::packAsBinary('garbage-data'); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testInvalidUnpack() |
73
|
|
|
{ |
74
|
|
|
$this->expectException(\InvalidArgumentException::class); |
75
|
|
|
$binUuid = Uuid::unpackBinary('123456789012345'); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testInvalidUnpack2() |
79
|
|
|
{ |
80
|
|
|
$this->expectException(\UnexpectedValueException::class); |
81
|
|
|
$binUuid = Uuid::unpackBinary('0000000000000000'); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/* verify natural sort order is the same for readable and binary formats */ |
85
|
|
|
public function testSortOrder() |
86
|
|
|
{ |
87
|
|
|
$auuid = []; |
88
|
|
|
$buuid = []; |
89
|
|
|
for ($i = 1; $i < 10; ++$i) { |
90
|
|
|
try { |
91
|
|
|
$uuid = Uuid::generate(); |
92
|
|
|
} catch (\Exception $e) { |
|
|
|
|
93
|
|
|
} |
94
|
|
|
$auuid[] = $uuid; |
95
|
|
|
$buuid[] = Uuid::packAsBinary($uuid); |
96
|
|
|
} |
97
|
|
|
sort($auuid); |
98
|
|
|
sort($buuid); |
99
|
|
|
foreach ($auuid as $key => $uuid) { |
100
|
|
|
$this->assertEquals($uuid, Uuid::unpackBinary($buuid[$key])); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths