testTrimWithCommonPrefixNonPathWindowsDirectorySeparator()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace OpCacheGUITest\Unit\Format;
4
5
use OpCacheGUI\Format\Prefix;
6
use OpCacheGUI\Format\Trimmer;
7
use PHPUnit\Framework\TestCase;
8
9
class PrefixTest extends TestCase
10
{
11
    /**
12
     */
13
    public function testConstructCorrectInstance()
14
    {
15
        $prefix = new Prefix;
16
17
        $this->assertInstanceOf(Trimmer::class, $prefix);
18
    }
19
20
    /**
21
     * @covers OpCacheGUI\Format\Prefix::trim
22
     * @covers OpCacheGUI\Format\Prefix::getPrefixLength
23
     * @covers OpCacheGUI\Format\Prefix::findLongestPrefix
24
     */
25
    public function testTrimWithoutCommonPrefix()
26
    {
27
        $prefix = new Prefix;
28
29
        $data = [
30
            [
31
                'full_path' => '/foo/bar/baz.php',
32
            ],
33
            [
34
                'full_path' => 'bar/baz.php',
35
            ],
36
        ];
37
38
        $this->assertSame($data, $prefix->trim($data));
39
    }
40
41
    /**
42
     * @covers OpCacheGUI\Format\Prefix::trim
43
     * @covers OpCacheGUI\Format\Prefix::getPrefixLength
44
     * @covers OpCacheGUI\Format\Prefix::findLongestPrefix
45
     */
46
    public function testTrimWithoutCommonPrefixEarlyReturn()
47
    {
48
        $prefix = new Prefix;
49
50
        $data = [
51
            [
52
                'full_path' => '/foo/bar/baz.php',
53
            ],
54
            [
55
                'full_path' => 'bar/baz.php',
56
            ],
57
            [
58
                'full_path' => 'bar/qux.php',
59
            ],
60
        ];
61
62
        $this->assertSame($data, $prefix->trim($data));
63
    }
64
65
    /**
66
     * @covers OpCacheGUI\Format\Prefix::trim
67
     * @covers OpCacheGUI\Format\Prefix::getPrefixLength
68
     * @covers OpCacheGUI\Format\Prefix::findLongestPrefix
69
     */
70
    public function testTrimWithCommonPrefixPath()
71
    {
72
        $prefix = new Prefix;
73
74
        $data = [
75
            [
76
                'full_path' => '/foo/yay/more/and/deeper/xbar/baz.php',
77
            ],
78
            [
79
                'full_path' => '/foo/yay/more/and/deeper/ybaz.php',
80
            ],
81
        ];
82
83
        $result = [
84
            [
85
                'full_path' => '/xbar/baz.php',
86
            ],
87
            [
88
                'full_path' => '/ybaz.php',
89
            ],
90
        ];
91
92
        $this->assertSame($result, $prefix->trim($data));
93
    }
94
95
    /**
96
     * @covers OpCacheGUI\Format\Prefix::trim
97
     * @covers OpCacheGUI\Format\Prefix::getPrefixLength
98
     * @covers OpCacheGUI\Format\Prefix::findLongestPrefix
99
     */
100
    public function testTrimWithCommonPrefixNonPath()
101
    {
102
        $prefix = new Prefix;
103
104
        $data = [
105
            [
106
                'full_path' => '/foo/bar/baz.php',
107
            ],
108
            [
109
                'full_path' => '/foo/baz.php',
110
            ],
111
        ];
112
113
        $result = [
114
            [
115
                'full_path' => '/bar/baz.php',
116
            ],
117
            [
118
                'full_path' => '/baz.php',
119
            ],
120
        ];
121
122
        $this->assertSame($result, $prefix->trim($data));
123
    }
124
125
    /**
126
     * @covers OpCacheGUI\Format\Prefix::trim
127
     * @covers OpCacheGUI\Format\Prefix::getPrefixLength
128
     * @covers OpCacheGUI\Format\Prefix::findLongestPrefix
129
     */
130
    public function testTrimWithCommonPrefixPathWindowsDirectorySeparator()
131
    {
132
        $prefix = new Prefix;
133
134
        $data = [
135
            [
136
                'full_path' => '\foo\yay\more\and\deeper\xbar\baz.php',
137
            ],
138
            [
139
                'full_path' => '\foo\yay\more\and\deeper\ybaz.php',
140
            ],
141
        ];
142
143
        $result = [
144
            [
145
                'full_path' => '\xbar\baz.php',
146
            ],
147
            [
148
                'full_path' => '\ybaz.php',
149
            ],
150
        ];
151
152
        $this->assertSame($result, $prefix->trim($data));
153
    }
154
155
    /**
156
     * @covers OpCacheGUI\Format\Prefix::trim
157
     * @covers OpCacheGUI\Format\Prefix::getPrefixLength
158
     * @covers OpCacheGUI\Format\Prefix::findLongestPrefix
159
     */
160
    public function testTrimWithCommonPrefixNonPathWindowsDirectorySeparator()
161
    {
162
        $prefix = new Prefix;
163
164
        $data = [
165
            [
166
                'full_path' => '\foo\bar\baz.php',
167
            ],
168
            [
169
                'full_path' => '\foo\baz.php',
170
            ],
171
        ];
172
173
        $result = [
174
            [
175
                'full_path' => '\bar\baz.php',
176
            ],
177
            [
178
                'full_path' => '\baz.php',
179
            ],
180
        ];
181
182
        $this->assertSame($result, $prefix->trim($data));
183
    }
184
185
    /**
186
     * @covers OpCacheGUI\Format\Prefix::trim
187
     * @covers OpCacheGUI\Format\Prefix::getPrefixLength
188
     * @covers OpCacheGUI\Format\Prefix::findLongestPrefix
189
     */
190
    public function testTrimWithCommonPrefixExactMatch()
191
    {
192
        $prefix = new Prefix;
193
194
        $data = [
195
            [
196
                'full_path' => '/foo/bar/baz.php',
197
            ],
198
            [
199
                'full_path' => '/foo/bar/baz.php',
200
            ],
201
        ];
202
203
        $result = [
204
            [
205
                'full_path' => '',
206
            ],
207
            [
208
                'full_path' => '',
209
            ],
210
        ];
211
212
        $this->assertSame($result, $prefix->trim($data));
213
    }
214
}
215