1
|
|
|
<?php |
2
|
|
|
namespace exussum12\CoverageChecker\tests; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
use exussum12\CoverageChecker\DiffFileLoader; |
6
|
|
|
use exussum12\CoverageChecker\DiffFileState; |
7
|
|
|
use exussum12\CoverageChecker\DiffLineHandle\ContextLine; |
8
|
|
|
|
9
|
|
|
class DiffFileLoaderTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @dataProvider getResults |
13
|
|
|
*/ |
14
|
|
|
public function testDiffResultsMatch($file, $expected) |
15
|
|
|
{ |
16
|
|
|
$changed = $this->getChangedLines($file); |
17
|
|
|
|
18
|
|
|
$this->assertEquals($changed, $expected); |
19
|
|
|
} |
20
|
|
|
/** |
21
|
|
|
* @expectedException InvalidArgumentException |
22
|
|
|
*/ |
23
|
|
|
public function testNonExistantFile() |
24
|
|
|
{ |
25
|
|
|
$this->getChangedLines('ufhbubfusdf'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getResults() |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
|
|
'newFile' => [ |
32
|
|
|
__DIR__ . '/fixtures/newFile.txt', |
33
|
|
|
[ |
34
|
|
|
'changedFile.php' => [1,2,3] |
35
|
|
|
] |
36
|
|
|
], |
37
|
|
|
'lineChange' => [ |
38
|
|
|
__DIR__ . '/fixtures/change.txt', |
39
|
|
|
[ |
40
|
|
|
'changedFile.php' => [3] |
41
|
|
|
] |
42
|
|
|
], |
43
|
|
|
'multipleFiles' => [ |
44
|
|
|
__DIR__ . '/fixtures/multiple.txt', |
45
|
|
|
[ |
46
|
|
|
'changedFile.php' => [3], |
47
|
|
|
'newFile.php' => [1,2,3] |
48
|
|
|
] |
49
|
|
|
], |
50
|
|
|
'removeFile' => [ |
51
|
|
|
__DIR__ . '/fixtures/removeFile.txt', |
52
|
|
|
[] |
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
|
|
|
|