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

DiffFileLoaderTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

5 Methods

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