DiffFileLoaderTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testDiffResultsMatch() 0 5 1
A getChangedLines() 0 4 1
A testNonExistantFile() 0 5 1
A testEnsureContextLineIsValid() 0 5 1
A getResults() 0 25 1
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