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 PhpunitDiffFilterTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @expectedException Exception |
15
|
|
|
* @expectedExceptionCode 1 |
16
|
|
|
*/ |
17
|
|
|
public function testWrongArgs() |
18
|
|
|
{ |
19
|
|
|
$GLOBALS['argv'] = []; |
20
|
|
|
require(__DIR__ . "/../src/Runners/generic.php"); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testWorkingCorrectly() |
24
|
|
|
{ |
25
|
|
|
$GLOBALS['argv'] = [ |
26
|
|
|
'diffFilter', |
27
|
|
|
'--phpunit', |
28
|
|
|
__DIR__ . '/fixtures/change.txt', |
29
|
|
|
__DIR__ . '/fixtures/coverage.xml' |
30
|
|
|
]; |
31
|
|
|
ob_start(); |
32
|
|
|
require(__DIR__ . "/../src/Runners/generic.php"); |
33
|
|
|
$output = ob_get_clean(); |
34
|
|
|
$this->assertContains('No lines found', $output); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testFailingBuild() |
38
|
|
|
{ |
39
|
|
|
$GLOBALS['argv'] = [ |
40
|
|
|
'diffFilter', |
41
|
|
|
'--phpunit', |
42
|
|
|
'--report=json', |
43
|
|
|
__DIR__ . '/fixtures/newFile.txt', |
44
|
|
|
__DIR__ . '/fixtures/coverage-change.xml', |
45
|
|
|
70 |
46
|
|
|
]; |
47
|
|
|
try { |
48
|
|
|
ob_start(); |
49
|
|
|
require(__DIR__ . "/../src/Runners/generic.php"); |
50
|
|
|
} catch (Exception $e) { |
51
|
|
|
$output = ob_get_clean(); |
52
|
|
|
$this->assertEquals(2, $e->getCode()); |
53
|
|
|
$this->assertContains('66.67', $output); |
54
|
|
|
$this->assertContains('Failed', $output); |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$this->fail("no exception thrown"); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testPassingLowPercentage() |
62
|
|
|
{ |
63
|
|
|
$GLOBALS['argv'] = [ |
64
|
|
|
'diffFilter', |
65
|
|
|
'--phpunit', |
66
|
|
|
__DIR__ . '/fixtures/newFile.txt', |
67
|
|
|
__DIR__ . '/fixtures/coverage-change.xml', |
68
|
|
|
60 |
69
|
|
|
]; |
70
|
|
|
|
71
|
|
|
ob_start(); |
72
|
|
|
require(__DIR__ . "/../src/Runners/generic.php"); |
73
|
|
|
$output = ob_get_clean(); |
74
|
|
|
$this->assertContains('66.67%', $output); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testNoCoveredLines() |
78
|
|
|
{ |
79
|
|
|
$GLOBALS['argv'] = [ |
80
|
|
|
'diffFilter', |
81
|
|
|
'--phpunit', |
82
|
|
|
__DIR__ . '/fixtures/removeFile.txt', |
83
|
|
|
__DIR__ . '/fixtures/coverage-change.xml', |
84
|
|
|
]; |
85
|
|
|
|
86
|
|
|
ob_start(); |
87
|
|
|
require(__DIR__ . "/../src/Runners/generic.php"); |
88
|
|
|
$output = ob_get_clean(); |
89
|
|
|
$this->assertContains('No lines found', $output); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|