|
1
|
|
|
<?php |
|
2
|
|
|
namespace exussum12\CoverageChecker\tests; |
|
3
|
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
|
5
|
|
|
use Exception; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Ignored due to acceptance test needing to write values |
|
9
|
|
|
* @SuppressWarnings(PHPMD.Superglobals) |
|
10
|
|
|
*/ |
|
11
|
|
|
class PhpmdDiffFilterTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
public function testValid() |
|
15
|
|
|
{ |
|
16
|
|
|
$GLOBALS['argv'] = [ |
|
17
|
|
|
'diffFilter', |
|
18
|
|
|
'--phpmd', |
|
19
|
|
|
'--report=json', |
|
20
|
|
|
__DIR__ . '/fixtures/change.txt', |
|
21
|
|
|
__DIR__ . '/fixtures/phpmd.xml' |
|
22
|
|
|
]; |
|
23
|
|
|
ob_start(); |
|
24
|
|
|
require(__DIR__ . "/../src/Runners/generic.php"); |
|
25
|
|
|
$output = ob_get_clean(); |
|
26
|
|
|
$this->assertContains('100.00', $output); |
|
27
|
|
|
$this->assertContains('Passed', $output); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testNoValidLines() |
|
31
|
|
|
{ |
|
32
|
|
|
$GLOBALS['argv'] = [ |
|
33
|
|
|
'diffFilter', |
|
34
|
|
|
'--phpmd', |
|
35
|
|
|
__DIR__ . '/fixtures/change.txt', |
|
36
|
|
|
__DIR__ . '/fixtures/phpmd-change.xml', |
|
37
|
|
|
]; |
|
38
|
|
|
try { |
|
39
|
|
|
ob_start(); |
|
40
|
|
|
require(__DIR__ . "/../src/Runners/generic.php"); |
|
41
|
|
|
} catch (Exception $e) { |
|
42
|
|
|
$output = ob_get_clean(); |
|
43
|
|
|
$this->assertEquals(2, $e->getCode()); |
|
44
|
|
|
$this->assertContains('0.00%', $output); |
|
45
|
|
|
return; |
|
46
|
|
|
} |
|
47
|
|
|
$this->fail("no exception thrown"); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testNoValidLinesStrict() |
|
51
|
|
|
{ |
|
52
|
|
|
$GLOBALS['argv'] = [ |
|
53
|
|
|
'diffFilter', |
|
54
|
|
|
'--phpmdStrict', |
|
55
|
|
|
__DIR__ . '/fixtures/change.txt', |
|
56
|
|
|
__DIR__ . '/fixtures/phpmd-change.xml', |
|
57
|
|
|
]; |
|
58
|
|
|
try { |
|
59
|
|
|
ob_start(); |
|
60
|
|
|
require(__DIR__ . "/../src/Runners/generic.php"); |
|
61
|
|
|
} catch (Exception $e) { |
|
62
|
|
|
$output = ob_get_clean(); |
|
63
|
|
|
$this->assertEquals(2, $e->getCode()); |
|
64
|
|
|
$this->assertContains('0%', $output); |
|
65
|
|
|
return; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$this->fail("no exception thrown"); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|