Passed
Branch master (cd2b9b)
by Scott
03:31
created

DiffFileLoaderTest::getChangedLines()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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