1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Filter; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
use TraderInteractive\Exceptions\FilterException; |
7
|
|
|
use TraderInteractive\Filter\UuidFilter; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @coversDefaultClass \TraderInteractive\Filter\UuidFilter |
12
|
|
|
* @covers ::<private> |
13
|
|
|
*/ |
14
|
|
|
final class UuidFilterTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
* @internal |
19
|
|
|
*/ |
20
|
|
|
const UUID_V1 = '1a42403c-a29d-11ef-b864-0242ac120002'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
* @internal |
25
|
|
|
*/ |
26
|
|
|
const UUID_V4 = 'cc468b36-0b9d-4c93-b8e9-d5e949331ffb'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
* @internal |
31
|
|
|
*/ |
32
|
|
|
const UUID_V7 = '01932b4a-af2b-7093-af59-2fb2044d13d8'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @test |
36
|
|
|
* @covers ::filter |
37
|
|
|
*/ |
38
|
|
|
public function filterUuidV1() |
39
|
|
|
{ |
40
|
|
|
$this->assertSame(self::UUID_V1, UuidFilter::filter(self::UUID_V1)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @test |
45
|
|
|
* @covers ::filter |
46
|
|
|
*/ |
47
|
|
|
public function filterUuidV4() |
48
|
|
|
{ |
49
|
|
|
$this->assertSame(self::UUID_V4, UuidFilter::filter(self::UUID_V4)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @test |
54
|
|
|
* @covers ::filter |
55
|
|
|
*/ |
56
|
|
|
public function filterUuidV7() |
57
|
|
|
{ |
58
|
|
|
$this->assertSame(self::UUID_V7, UuidFilter::filter(self::UUID_V7)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @test |
63
|
|
|
* @covers ::filter |
64
|
|
|
*/ |
65
|
|
|
public function filterNullAllowedNullIsTrue() |
66
|
|
|
{ |
67
|
|
|
$this->assertNull(UuidFilter::filter(null, true)); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @test |
72
|
|
|
* @covers ::filter |
73
|
|
|
*/ |
74
|
|
|
public function filterNullAllowedNullIsFalse() |
75
|
|
|
{ |
76
|
|
|
$this->expectException(FilterException::class); |
77
|
|
|
UuidFilter::filter(null, false); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @test |
82
|
|
|
* @covers ::filter |
83
|
|
|
*/ |
84
|
|
|
public function filterWithInvalidVersionSpecified() |
85
|
|
|
{ |
86
|
|
|
$this->expectException(InvalidArgumentException::class); |
87
|
|
|
$this->expectExceptionMessage('Filter does not support UUID v0'); |
88
|
|
|
UuidFilter::filter(self::UUID_V7, false, [0]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @test |
93
|
|
|
* @covers ::filter |
94
|
|
|
*/ |
95
|
|
|
public function filterValueDoesNotMatchGivenVersions() |
96
|
|
|
{ |
97
|
|
|
$this->expectException(FilterException::class); |
98
|
|
|
$this->expectExceptionMessage( |
99
|
|
|
sprintf( |
100
|
|
|
UuidFilter::FILTER_ERROR_FORMAT, |
101
|
|
|
self::UUID_V4, |
102
|
|
|
implode(', ', [1,7]) |
103
|
|
|
) |
104
|
|
|
); |
105
|
|
|
UuidFilter::filter(self::UUID_V4, false, [1,7]); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.