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