1
|
|
|
<?php |
2
|
|
|
namespace exussum12\CoverageChecker\tests; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
use Exception; |
6
|
|
|
|
7
|
|
|
class PhpmdDiffFilterTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
View Code Duplication |
public function testValid() |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
$GLOBALS['argv'] = [ |
13
|
|
|
'phpunitDiffFilter', |
14
|
|
|
__DIR__ . '/fixtures/change.txt', |
15
|
|
|
__DIR__ . '/fixtures/phpmd.xml' |
16
|
|
|
]; |
17
|
|
|
ob_start(); |
18
|
|
|
require(__DIR__ . "/../src/runners/phpmdDiffFilter.php"); |
19
|
|
|
$output = ob_get_clean(); |
20
|
|
|
$this->assertContains('100.00%', $output); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
View Code Duplication |
public function testNoValidLines() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$GLOBALS['argv'] = [ |
26
|
|
|
'phpunitDiffFilter', |
27
|
|
|
__DIR__ . '/fixtures/change.txt', |
28
|
|
|
__DIR__ . '/fixtures/phpmd-change.xml', |
29
|
|
|
]; |
30
|
|
|
try { |
31
|
|
|
ob_start(); |
32
|
|
|
require(__DIR__ . "/../src/runners/phpmdDiffFilter.php"); |
33
|
|
|
} catch (Exception $e) { |
34
|
|
|
$output = ob_get_clean(); |
35
|
|
|
$this->assertEquals(2, $e->getCode()); |
36
|
|
|
$this->assertContains('0.00%', $output); |
37
|
|
|
return; |
38
|
|
|
} |
39
|
|
|
$this->fail("no exception thrown"); |
40
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
View Code Duplication |
public function testNoValidLinesStrict() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$GLOBALS['argv'] = [ |
46
|
|
|
'phpunitDiffFilter', |
47
|
|
|
__DIR__ . '/fixtures/change.txt', |
48
|
|
|
__DIR__ . '/fixtures/phpmd-change.xml', |
49
|
|
|
'--strict', |
50
|
|
|
]; |
51
|
|
|
try { |
52
|
|
|
ob_start(); |
53
|
|
|
require(__DIR__ . "/../src/runners/phpmdDiffFilter.php"); |
54
|
|
|
} catch (Exception $e) { |
55
|
|
|
$output = ob_get_clean(); |
56
|
|
|
$this->assertEquals(2, $e->getCode()); |
57
|
|
|
$this->assertContains('0%', $output); |
58
|
|
|
return; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$this->fail("no exception thrown"); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
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.