UuidFilterTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 26
c 2
b 0
f 0
dl 0
loc 114
rs 10
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A filterValueDoesNotMatchGivenVersions() 0 11 1
A filterNullAllowedNullIsFalse() 0 4 1
A filterUuidV4() 0 3 1
A filterNullAllowedNullIsTrue() 0 3 1
A filterUuidV1() 0 3 1
A filterUuidV7() 0 3 1
A filterWithInvalidVersionSpecified() 0 5 1
A filterNilUuidNilNotAllowed() 0 6 1
A filterNilUuid() 0 4 1
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(sprintf(UuidFilter::UNSUPPORTED_VERSION_ERROR_FORMAT, 0));
88
        UuidFilter::filter(self::UUID_V7, false, 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, false, [1,7]);
106
    }
107
108
    /**
109
     * @test
110
     * @covers ::filter
111
     */
112
    public function filterNilUuid()
113
    {
114
        $value = UuidFilter::NIL_UUID;
115
        $this->assertSame($value, UuidFilter::filter($value, false, true));
116
    }
117
118
    /**
119
     * @test
120
     * @covers ::filter
121
     */
122
    public function filterNilUuidNilNotAllowed()
123
    {
124
        $value = UuidFilter::NIL_UUID;
125
        $this->expectException(FilterException::class);
126
        $this->expectExceptionMessage(sprintf(UuidFilter::NIL_NOT_ALLOWED_ERROR_FORMAT, $value));
127
        UuidFilter::filter($value, false, false);
128
    }
129
}
130