|
1
|
|
|
<?php |
|
2
|
|
|
namespace exussum12\CoverageChecker; |
|
3
|
|
|
|
|
4
|
|
|
use Exception; |
|
5
|
|
|
use PHPUnit_Framework_AssertionFailedError as AssertionFailedError; |
|
|
|
|
|
|
6
|
|
|
use PHPUnit_Framework_Test as Test; |
|
|
|
|
|
|
7
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
|
|
|
|
|
|
8
|
|
|
use PHPUnit_Framework_TestListener as TestListener; |
|
|
|
|
|
|
9
|
|
|
use PHPUnit_Framework_TestSuite as TestSuite; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Coverage ignored due to not being able to run this |
|
13
|
|
|
* @codeCoverageIgnore |
|
14
|
|
|
* PHPMD suppressed due to having to implement TestListener |
|
15
|
|
|
* @SuppressWarnings(PHPMD) |
|
16
|
|
|
*/ |
|
17
|
|
|
class DiffFilter implements TestListener |
|
18
|
|
|
{ |
|
19
|
|
|
protected $modifiedTests = null; |
|
20
|
|
|
protected $modifiedSuites = null; |
|
21
|
|
|
public function __construct($old, $diff, $fuzziness = 0) |
|
22
|
|
|
{ |
|
23
|
|
|
try { |
|
24
|
|
|
$diff = new DiffFileLoaderOldVersion($diff); |
|
25
|
|
|
$matcher = new FileMatchers\EndsWith(); |
|
26
|
|
|
$coverage = new PhpunitFilter($diff, $matcher, $old); |
|
27
|
|
|
$this->modifiedTests = $coverage->getTestsForRunning($fuzziness); |
|
28
|
|
|
$this->modifiedSuites = array_keys($this->modifiedTests); |
|
29
|
|
|
unset($coverage); |
|
30
|
|
|
} catch (Exception $exception) { |
|
31
|
|
|
//Something has gone wrong, Don't filter |
|
32
|
|
|
echo "Missing required diff / php coverage, Running all tests\n"; |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function addError(Test $test, Exception $exception, $time) |
|
37
|
|
|
{ |
|
38
|
|
|
} |
|
39
|
|
|
public function addFailure(Test $test, AssertionFailedError $exception, $time) |
|
40
|
|
|
{ |
|
41
|
|
|
} |
|
42
|
|
|
public function addRiskyTest(Test $test, Exception $exception, $time) |
|
43
|
|
|
{ |
|
44
|
|
|
} |
|
45
|
|
|
public function startTestSuite(TestSuite $suite) |
|
46
|
|
|
{ |
|
47
|
|
|
if (!is_array($this->modifiedTests)) { |
|
48
|
|
|
return; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$suiteName = $suite->getName(); |
|
52
|
|
|
$runTests = []; |
|
53
|
|
|
if (empty($suiteName)) { |
|
54
|
|
|
return; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$tests = $suite->tests(); |
|
58
|
|
|
|
|
59
|
|
|
foreach ($tests as $test) { |
|
60
|
|
|
$skipTest = |
|
61
|
|
|
$test instanceof TestCase && |
|
62
|
|
|
!$this->hasTestChanged( |
|
63
|
|
|
$test |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
if ($skipTest) { |
|
67
|
|
|
continue; |
|
68
|
|
|
} |
|
69
|
|
|
$runTests[] = $test; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$suite->setTests($runTests); |
|
73
|
|
|
} |
|
74
|
|
|
public function startTest(Test $test) |
|
75
|
|
|
{ |
|
76
|
|
|
} |
|
77
|
|
|
public function endTest(Test $test, $time) |
|
78
|
|
|
{ |
|
79
|
|
|
} |
|
80
|
|
|
public function addIncompleteTest(Test $test, Exception $e, $time) |
|
81
|
|
|
{ |
|
82
|
|
|
} |
|
83
|
|
|
public function addSkippedTest(Test $test, Exception $e, $time) |
|
84
|
|
|
{ |
|
85
|
|
|
} |
|
86
|
|
|
public function endTestSuite(TestSuite $suite) |
|
87
|
|
|
{ |
|
88
|
|
|
} |
|
89
|
|
|
public function onFatalError() |
|
90
|
|
|
{ |
|
91
|
|
|
} |
|
92
|
|
|
public function onCancel() |
|
93
|
|
|
{ |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function startsWith($haystack, $needle) |
|
97
|
|
|
{ |
|
98
|
|
|
$length = strlen($needle); |
|
99
|
|
|
return (substr($haystack, 0, $length) === $needle); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
protected function shouldRunTest($modifiedTest, $currentTest, $class) |
|
103
|
|
|
{ |
|
104
|
|
|
foreach ($modifiedTest as $test) { |
|
105
|
|
|
$testName = $currentTest->getName(); |
|
106
|
|
|
$testMatches = |
|
107
|
|
|
strpos($class, get_class($currentTest)) !== false && |
|
108
|
|
|
( |
|
109
|
|
|
empty($test) || |
|
110
|
|
|
strpos($test, $testName) !== false |
|
111
|
|
|
) |
|
112
|
|
|
; |
|
113
|
|
|
if ($testMatches) { |
|
114
|
|
|
return true; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
return false; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
private function hasTestChanged(TestCase $test) |
|
121
|
|
|
{ |
|
122
|
|
|
foreach ($this->modifiedTests as $class => $modifiedTest) { |
|
123
|
|
|
if ($this->shouldRunTest($modifiedTest, $test, $class)) { |
|
124
|
|
|
return true; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return false; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths