|
1
|
|
|
<?php |
|
2
|
|
|
namespace exussum12\CoverageChecker\tests; |
|
3
|
|
|
|
|
4
|
|
|
use InvalidArgumentException; |
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use exussum12\CoverageChecker\DiffFileLoader; |
|
7
|
|
|
use exussum12\CoverageChecker\DiffFileState; |
|
8
|
|
|
use exussum12\CoverageChecker\DiffLineHandle\ContextLine; |
|
9
|
|
|
|
|
10
|
|
|
class DiffFileLoaderTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @dataProvider getResults |
|
14
|
|
|
*/ |
|
15
|
|
|
public function testDiffResultsMatch($file, $expected) |
|
16
|
|
|
{ |
|
17
|
|
|
$changed = $this->getChangedLines($file); |
|
18
|
|
|
|
|
19
|
|
|
$this->assertEquals($changed, $expected); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testNonExistantFile() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
25
|
|
|
$this->expectExceptionCode(1); |
|
26
|
|
|
$this->getChangedLines('ufhbubfusdf'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function getResults() |
|
30
|
|
|
{ |
|
31
|
|
|
return [ |
|
32
|
|
|
'newFile' => [ |
|
33
|
|
|
__DIR__ . '/fixtures/newFile.txt', |
|
34
|
|
|
[ |
|
35
|
|
|
'changedFile.php' => [1, 2, 3] |
|
36
|
|
|
] |
|
37
|
|
|
], |
|
38
|
|
|
'lineChange' => [ |
|
39
|
|
|
__DIR__ . '/fixtures/change.txt', |
|
40
|
|
|
[ |
|
41
|
|
|
'changedFile.php' => [3] |
|
42
|
|
|
] |
|
43
|
|
|
], |
|
44
|
|
|
'multipleFiles' => [ |
|
45
|
|
|
__DIR__ . '/fixtures/multiple.txt', |
|
46
|
|
|
[ |
|
47
|
|
|
'changedFile.php' => [3], |
|
48
|
|
|
'newFile.php' => [1, 2, 3] |
|
49
|
|
|
] |
|
50
|
|
|
], |
|
51
|
|
|
'removeFile' => [ |
|
52
|
|
|
__DIR__ . '/fixtures/removeFile.txt', |
|
53
|
|
|
[] |
|
54
|
|
|
], |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testEnsureContextLineIsValid() |
|
59
|
|
|
{ |
|
60
|
|
|
$diff = new DiffFileState(); |
|
61
|
|
|
$contextLine = new ContextLine($diff); |
|
62
|
|
|
$this->assertTrue($contextLine->isValid("anything")); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private function getChangedLines($file) |
|
66
|
|
|
{ |
|
67
|
|
|
$fileLoader = new DiffFileLoader($file); |
|
68
|
|
|
return $fileLoader->getChangedLines(); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|