exussum12 /
coverageChecker
| 1 | <?php |
||
| 2 | namespace exussum12\CoverageChecker\tests; |
||
| 3 | |||
| 4 | use PHPUnit\Framework\TestCase; |
||
| 5 | use exussum12\CoverageChecker\CoverageCheck; |
||
| 6 | use exussum12\CoverageChecker\DiffFileLoader; |
||
| 7 | use exussum12\CoverageChecker\FileMatchers; |
||
| 8 | use exussum12\CoverageChecker\Loaders\Clover; |
||
| 9 | |||
| 10 | class CoverageCheckTest extends TestCase |
||
| 11 | { |
||
| 12 | private $errorMessage = ['No Cover']; |
||
| 13 | public function testCoverage() |
||
| 14 | { |
||
| 15 | $diffFileState = $this->createMock(DiffFileLoader::class); |
||
| 16 | $diffFileState->method('getChangedLines') |
||
|
0 ignored issues
–
show
|
|||
| 17 | ->willReturn([ |
||
| 18 | 'testFile1.php' => [1, 2, 3, 4], |
||
| 19 | 'testFile2.php' => [3, 4] |
||
| 20 | |||
| 21 | ]); |
||
| 22 | |||
| 23 | $xmlReport = $this->createMock(Clover::class); |
||
| 24 | $xmlReport->method('parseLines') |
||
| 25 | ->willReturn([ |
||
| 26 | '/full/path/to/testFile1.php', |
||
| 27 | '/full/path/to/testFile2.php', |
||
| 28 | ]); |
||
| 29 | |||
| 30 | $xmlReport->method('getErrorsOnLine') |
||
| 31 | ->will( |
||
| 32 | $this->returnCallback( |
||
| 33 | function () { |
||
| 34 | $file = func_get_arg(0); |
||
| 35 | $line = func_get_arg(1); |
||
| 36 | |||
| 37 | if ($file == '/full/path/to/testFile1.php' && $line == 2) { |
||
| 38 | return $this->errorMessage; |
||
| 39 | } |
||
| 40 | if ($file == '/full/path/to/testFile2.php' && $line == 4) { |
||
| 41 | return $this->errorMessage; |
||
| 42 | } |
||
| 43 | |||
| 44 | return []; |
||
| 45 | } |
||
| 46 | ) |
||
| 47 | ); |
||
| 48 | |||
| 49 | $matcher = new FileMatchers\EndsWith; |
||
| 50 | $coverageCheck = new CoverageCheck($diffFileState, $xmlReport, $matcher); |
||
| 51 | $lines = $coverageCheck->getCoveredLines(); |
||
| 52 | $uncoveredLines = [ |
||
| 53 | 'testFile1.php' => [2 => $this->errorMessage], |
||
| 54 | 'testFile2.php' => [4 => $this->errorMessage], |
||
| 55 | ]; |
||
| 56 | $coveredLines = [ |
||
| 57 | 'testFile1.php' => [1, 3, 4], |
||
| 58 | 'testFile2.php' => [3], |
||
| 59 | ]; |
||
| 60 | |||
| 61 | $expected = [ |
||
| 62 | 'coveredLines' => $coveredLines, |
||
| 63 | 'uncoveredLines' => $uncoveredLines, |
||
| 64 | ]; |
||
| 65 | |||
| 66 | $this->assertEquals($expected, $lines); |
||
| 67 | } |
||
| 68 | |||
| 69 | public function testCoverageFailed() |
||
| 70 | { |
||
| 71 | $diffFileState = $this->createMock(DiffFileLoader::class); |
||
| 72 | $diffFileState->method('getChangedLines') |
||
| 73 | ->willReturn([ |
||
| 74 | 'testFile1.php' => [1, 2, 3, 4], |
||
| 75 | 'testFile2.php' => [3, 4], |
||
| 76 | |||
| 77 | ]); |
||
| 78 | |||
| 79 | $xmlReport = $this->createMock(Clover::class); |
||
| 80 | $xmlReport->method('parseLines') |
||
| 81 | ->willReturn([ |
||
| 82 | '/full/path/to/testFile1.php', |
||
| 83 | |||
| 84 | ]); |
||
| 85 | |||
| 86 | $xmlReport->method('handleNotFoundFile') |
||
| 87 | ->willReturn(null); |
||
| 88 | |||
| 89 | $xmlReport->method('getErrorsOnLine') |
||
| 90 | ->will( |
||
| 91 | $this->returnCallback( |
||
| 92 | function () { |
||
| 93 | $file = func_get_arg(0); |
||
| 94 | $line = func_get_arg(1); |
||
| 95 | |||
| 96 | if ($file == '/full/path/to/testFile1.php' && $line == 2) { |
||
| 97 | return $this->errorMessage; |
||
| 98 | } |
||
| 99 | |||
| 100 | return []; |
||
| 101 | } |
||
| 102 | ) |
||
| 103 | ); |
||
| 104 | |||
| 105 | $matcher = new FileMatchers\EndsWith; |
||
| 106 | $coverageCheck = new CoverageCheck($diffFileState, $xmlReport, $matcher); |
||
| 107 | $lines = $coverageCheck->getCoveredLines(); |
||
| 108 | |||
| 109 | $uncoveredLines = [ |
||
| 110 | 'testFile1.php' => [2 => $this->errorMessage], |
||
| 111 | ]; |
||
| 112 | $coveredLines = [ |
||
| 113 | 'testFile1.php' => [1, 3, 4], |
||
| 114 | ]; |
||
| 115 | |||
| 116 | $expected = [ |
||
| 117 | 'coveredLines' => $coveredLines, |
||
| 118 | 'uncoveredLines' => $uncoveredLines, |
||
| 119 | ]; |
||
| 120 | |||
| 121 | $this->assertEquals($expected, $lines); |
||
| 122 | } |
||
| 123 | |||
| 124 | public function testAddingAllUnknownsCovered() |
||
| 125 | { |
||
| 126 | $diffFileState = $this->createMock(DiffFileLoader::class); |
||
| 127 | $diffFileState->method('getChangedLines') |
||
| 128 | ->willReturn([ |
||
| 129 | 'testFile1.php' => [1, 2, 3, 4], |
||
| 130 | 'testFile2.php' => [3, 4], |
||
| 131 | |||
| 132 | ]); |
||
| 133 | |||
| 134 | $xmlReport = $this->createMock(Clover::class); |
||
| 135 | $xmlReport->method('parseLines') |
||
| 136 | ->willReturn([ |
||
| 137 | '/full/path/to/testFile1.php', |
||
| 138 | ]); |
||
| 139 | |||
| 140 | $xmlReport->method('handleNotFoundFile') |
||
| 141 | ->willReturn(true); |
||
| 142 | |||
| 143 | $xmlReport->method('getErrorsOnLine') |
||
| 144 | ->will( |
||
| 145 | $this->returnCallback( |
||
| 146 | function () { |
||
| 147 | $file = func_get_arg(0); |
||
| 148 | $line = func_get_arg(1); |
||
| 149 | |||
| 150 | if ($file == '/full/path/to/testFile1.php' && $line == 2) { |
||
| 151 | return $this->errorMessage; |
||
| 152 | } |
||
| 153 | |||
| 154 | return []; |
||
| 155 | } |
||
| 156 | ) |
||
| 157 | ); |
||
| 158 | |||
| 159 | $matcher = new FileMatchers\EndsWith; |
||
| 160 | $coverageCheck = new CoverageCheck($diffFileState, $xmlReport, $matcher); |
||
| 161 | $lines = $coverageCheck->getCoveredLines(); |
||
| 162 | |||
| 163 | $uncoveredLines = [ |
||
| 164 | 'testFile1.php' => [2 => $this->errorMessage], |
||
| 165 | ]; |
||
| 166 | $coveredLines = [ |
||
| 167 | 'testFile1.php' => [1, 3, 4], |
||
| 168 | 'testFile2.php' => [3, 4], |
||
| 169 | ]; |
||
| 170 | |||
| 171 | $expected = [ |
||
| 172 | 'coveredLines' => $coveredLines, |
||
| 173 | 'uncoveredLines' => $uncoveredLines, |
||
| 174 | ]; |
||
| 175 | |||
| 176 | $this->assertEquals($expected, $lines); |
||
| 177 | } |
||
| 178 | |||
| 179 | public function testAddingAllUnknownsUnCovered() |
||
| 180 | { |
||
| 181 | $diffFileState = $this->createMock(DiffFileLoader::class); |
||
| 182 | $diffFileState->method('getChangedLines') |
||
| 183 | ->willReturn([ |
||
| 184 | 'testFile1.php' => [1, 2, 3, 4], |
||
| 185 | 'testFile2.php' => [3, 4], |
||
| 186 | |||
| 187 | ]); |
||
| 188 | |||
| 189 | $xmlReport = $this->createMock(Clover::class); |
||
| 190 | $xmlReport->method('parseLines') |
||
| 191 | ->willReturn([ |
||
| 192 | '/full/path/to/testFile1.php', |
||
| 193 | ]); |
||
| 194 | |||
| 195 | $xmlReport->method('handleNotFoundFile') |
||
| 196 | ->willReturn(false); |
||
| 197 | |||
| 198 | $xmlReport->method('getErrorsOnLine') |
||
| 199 | ->will( |
||
| 200 | $this->returnCallback( |
||
| 201 | function () { |
||
| 202 | $file = func_get_arg(0); |
||
| 203 | $line = func_get_arg(1); |
||
| 204 | |||
| 205 | if ($file == '/full/path/to/testFile1.php' && $line == 2) { |
||
| 206 | return $this->errorMessage; |
||
| 207 | } |
||
| 208 | |||
| 209 | return []; |
||
| 210 | } |
||
| 211 | ) |
||
| 212 | ); |
||
| 213 | |||
| 214 | $matcher = new FileMatchers\EndsWith; |
||
| 215 | $coverageCheck = new CoverageCheck($diffFileState, $xmlReport, $matcher); |
||
| 216 | $lines = $coverageCheck->getCoveredLines(); |
||
| 217 | |||
| 218 | $uncoveredLines = [ |
||
| 219 | 'testFile1.php' => [2 => $this->errorMessage], |
||
| 220 | 'testFile2.php' => [ |
||
| 221 | 3 => ['No Cover'], |
||
| 222 | 4 => ['No Cover'], |
||
| 223 | ], |
||
| 224 | ]; |
||
| 225 | $coveredLines = [ |
||
| 226 | 'testFile1.php' => [1, 3, 4], |
||
| 227 | ]; |
||
| 228 | |||
| 229 | $expected = [ |
||
| 230 | 'coveredLines' => $coveredLines, |
||
| 231 | 'uncoveredLines' => $uncoveredLines, |
||
| 232 | ]; |
||
| 233 | |||
| 234 | $this->assertEquals($expected, $lines); |
||
| 235 | } |
||
| 236 | |||
| 237 | public function testCoverageForContextLines() |
||
| 238 | { |
||
| 239 | $diffFileState = $this->createMock(DiffFileLoader::class); |
||
| 240 | $diffFileState->method('getChangedLines') |
||
| 241 | ->willReturn([ |
||
| 242 | 'testFile1.php' => [1, 2, 4], |
||
| 243 | |||
| 244 | ]); |
||
| 245 | |||
| 246 | $xmlReport = $this->createMock(Clover::class); |
||
| 247 | $xmlReport->method('parseLines') |
||
| 248 | ->willReturn([ |
||
| 249 | '/full/path/to/testFile1.php' |
||
| 250 | |||
| 251 | ]); |
||
| 252 | |||
| 253 | $xmlReport->method('handleNotFoundFile') |
||
| 254 | ->willReturn(false); |
||
| 255 | |||
| 256 | $xmlReport->method('getErrorsOnLine') |
||
| 257 | ->will( |
||
| 258 | $this->returnCallback( |
||
| 259 | function () { |
||
| 260 | $file = func_get_arg(0); |
||
| 261 | $line = func_get_arg(1); |
||
| 262 | |||
| 263 | if ($file == '/full/path/to/testFile1.php' && $line == 2) { |
||
| 264 | return null; |
||
| 265 | } |
||
| 266 | |||
| 267 | return []; |
||
| 268 | } |
||
| 269 | ) |
||
| 270 | ); |
||
| 271 | |||
| 272 | $matcher = new FileMatchers\EndsWith; |
||
| 273 | $coverageCheck = new CoverageCheck($diffFileState, $xmlReport, $matcher); |
||
| 274 | $lines = $coverageCheck->getCoveredLines(); |
||
| 275 | |||
| 276 | $coveredLines = [ |
||
| 277 | 'testFile1.php' => [1, 4], |
||
| 278 | ]; |
||
| 279 | |||
| 280 | $expected = [ |
||
| 281 | 'coveredLines' => $coveredLines, |
||
| 282 | 'uncoveredLines' => [], |
||
| 283 | ]; |
||
| 284 | |||
| 285 | $this->assertEquals($expected, $lines); |
||
| 286 | } |
||
| 287 | } |
||
| 288 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.