1
|
|
|
<?php |
2
|
|
|
namespace exussum12\CoverageChecker\tests; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
use Exception; |
6
|
|
|
|
7
|
|
|
class PhpunitDiffFilterTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @expectedException Exception |
11
|
|
|
* @expectedExceptionCode 1 |
12
|
|
|
*/ |
13
|
|
|
public function testWrongArgs() |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
$GLOBALS['argv'] = []; |
16
|
|
|
require(__DIR__ . "/../src/runners/phpunitDiffFilter.php"); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
View Code Duplication |
public function testWorkingCorrectly() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$GLOBALS['argv'] = [ |
22
|
|
|
'phpunitDiffFilter', |
23
|
|
|
__DIR__ . '/fixtures/change.txt', |
24
|
|
|
__DIR__ . '/fixtures/coverage.xml' |
25
|
|
|
]; |
26
|
|
|
ob_start(); |
27
|
|
|
require(__DIR__ . "/../src/runners/phpunitDiffFilter.php"); |
28
|
|
|
$output = ob_get_clean(); |
29
|
|
|
$this->assertContains('100.00%', $output); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
public function testFailingBuild() |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$GLOBALS['argv'] = [ |
35
|
|
|
'phpunitDiffFilter', |
36
|
|
|
__DIR__ . '/fixtures/newFile.txt', |
37
|
|
|
__DIR__ . '/fixtures/coverage-change.xml', |
38
|
|
|
70 |
39
|
|
|
]; |
40
|
|
|
try { |
41
|
|
|
ob_start(); |
42
|
|
|
require(__DIR__ . "/../src/runners/phpunitDiffFilter.php"); |
43
|
|
|
} catch (Exception $e) { |
44
|
|
|
$output = ob_get_clean(); |
45
|
|
|
$this->assertEquals(2, $e->getCode()); |
46
|
|
|
$this->assertContains('66.67%', $output); |
47
|
|
|
return; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$this->fail("no exception thrown"); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
View Code Duplication |
public function testPassingLowPercentage() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$GLOBALS['argv'] = [ |
56
|
|
|
'phpunitDiffFilter', |
57
|
|
|
__DIR__ . '/fixtures/newFile.txt', |
58
|
|
|
__DIR__ . '/fixtures/coverage-change.xml', |
59
|
|
|
60 |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
ob_start(); |
63
|
|
|
require(__DIR__ . "/../src/runners/phpunitDiffFilter.php"); |
64
|
|
|
$output = ob_get_clean(); |
65
|
|
|
$this->assertContains('66.67%', $output); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
View Code Duplication |
public function testNoCoveredLines() |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$GLOBALS['argv'] = [ |
71
|
|
|
'phpunitDiffFilter', |
72
|
|
|
__DIR__ . '/fixtures/removeFile.txt', |
73
|
|
|
__DIR__ . '/fixtures/coverage-change.xml', |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
ob_start(); |
77
|
|
|
require(__DIR__ . "/../src/runners/phpunitDiffFilter.php"); |
78
|
|
|
$output = ob_get_clean(); |
79
|
|
|
$this->assertContains('No lines found', $output); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: