1
|
|
|
<?php |
2
|
|
|
namespace exussum12\CoverageChecker\tests; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
use exussum12\CoverageChecker\PhpCsLoader; |
6
|
|
|
use exussum12\CoverageChecker\PhpCsLoaderStrict; |
7
|
|
|
|
8
|
|
|
class LoadPhpcsReportTest extends TestCase |
9
|
|
|
{ |
10
|
|
View Code Duplication |
public function testCanMakeClass() |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
$phpcs = new PhpCsLoader(__DIR__ . '/fixtures/phpcs.json'); |
13
|
|
|
$invalidLines = $phpcs->getLines(); |
14
|
|
|
$expected = [ |
15
|
|
|
'/full/path/to/file/src/XMLReport.php' => [ |
16
|
|
|
11 => ['Opening brace should be on the line after the declaration; found 1 blank line(s)'], |
17
|
|
|
12 => ['Line indented incorrectly; expected at least 8 spaces, found 4'], |
18
|
|
|
], |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
$this->assertEquals($expected, $invalidLines); |
22
|
|
|
$this->assertFalse($phpcs->isValidLine('/full/path/to/file/src/XMLReport.php', 11)); |
23
|
|
|
$this->assertTrue($phpcs->isValidLine('/full/path/to/file/src/XMLReport.php', 10)); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @expectedException \InvalidArgumentException |
28
|
|
|
*/ |
29
|
|
|
public function testRejectsInvalidData() |
30
|
|
|
{ |
31
|
|
|
new PhpCsLoader(__DIR__ . '/fixtures/change.txt'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testCorrectMissingFile() |
35
|
|
|
{ |
36
|
|
|
$phpcs = new PhpCsLoader(__DIR__ . '/fixtures/phpcs.json'); |
37
|
|
|
|
38
|
|
|
$this->assertTrue($phpcs->handleNotFoundFile()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
View Code Duplication |
public function testStrictMode() |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$phpcs = new PhpCsLoaderStrict(__DIR__ . '/fixtures/phpcsstrict.json'); |
44
|
|
|
$invalidLines = $phpcs->getLines(); |
45
|
|
|
$expected = [ |
46
|
|
|
'/full/path/to/file/src/XMLReport.php' => [ |
47
|
|
|
11 => ['Opening brace should be on the line after the declaration; found 1 blank line(s)'], |
48
|
|
|
12 => ['Line indented incorrectly; expected at least 8 spaces, found 4'], |
49
|
|
|
], |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
$this->assertEquals($expected, $invalidLines); |
53
|
|
|
$this->assertFalse($phpcs->isValidLine('/full/path/to/file/src/XMLReport.php', 11)); |
54
|
|
|
$this->assertTrue($phpcs->isValidLine('/full/path/to/file/src/XMLReport.php', 10)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testWholeFileError() |
58
|
|
|
{ |
59
|
|
|
$phpcs = new PhpCsLoaderStrict(__DIR__ . '/fixtures/wholeFileErrorPhpcs.json'); |
60
|
|
|
$phpcs->getLines(); |
61
|
|
|
|
62
|
|
|
$this->assertFalse($phpcs->isValidLine('/tmp/test/test.php', 100)); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.