1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the doyo/behat-coverage-extension project. |
5
|
|
|
* |
6
|
|
|
* (c) Anthonius Munthi <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
/* |
15
|
|
|
* This file is part of the doyo/behat-code-coverage project. |
16
|
|
|
* |
17
|
|
|
* (c) Anthonius Munthi <[email protected]> |
18
|
|
|
* |
19
|
|
|
* For the full copyright and license information, please view the LICENSE |
20
|
|
|
* file that was distributed with this source code. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
use Lurker\Event\FilesystemEvent; |
|
|
|
|
24
|
|
|
use Robo\Tasks; |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* This is project's console commands configuration for Robo task runner. |
28
|
|
|
* |
29
|
|
|
* @see http://robo.li/ |
30
|
|
|
*/ |
31
|
|
|
class RoboFile extends Tasks |
32
|
|
|
{ |
33
|
|
|
private $coverage = false; |
34
|
|
|
|
35
|
|
|
private $watch = false; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param array $options |
39
|
|
|
*/ |
40
|
|
|
public function watch($options = ['coverage' => false]) |
41
|
|
|
{ |
42
|
|
|
$this->watch = true; |
43
|
|
|
|
44
|
|
|
$paths = [ |
45
|
|
|
'src', |
46
|
|
|
'tests', |
47
|
|
|
'spec', |
48
|
|
|
'features', |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
$this->taskWatch() |
52
|
|
|
->monitor( |
53
|
|
|
$paths, |
54
|
|
|
function (FilesystemEvent $event) use ($options) { |
55
|
|
|
$resource = (string) $event->getResource(); |
56
|
|
|
if ( |
57
|
|
|
false !== strpos($resource, 'build') |
58
|
|
|
|| false !== strpos($resource, 'var') |
59
|
|
|
) { |
60
|
|
|
return; |
61
|
|
|
} |
62
|
|
|
$this->test($options); |
|
|
|
|
63
|
|
|
}, |
64
|
|
|
FilesystemEvent::ALL |
65
|
|
|
) |
66
|
|
|
->run(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function test() |
70
|
|
|
{ |
71
|
|
|
$this->taskExec('clear')->run(); |
72
|
|
|
|
73
|
|
|
if ($this->coverage) { |
74
|
|
|
$this->taskFilesystemStack() |
75
|
|
|
->mkdir(__DIR__.'/build', 0775) |
76
|
|
|
->mkdir(__DIR__.'/build/cov', 0775) |
77
|
|
|
->run(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** @var \Robo\Result[] $results */ |
81
|
|
|
$results = []; |
82
|
|
|
$results[] = $this->configurePhpSpec()->run(); |
83
|
|
|
$results[] = $this->configurePhpUnit()->run(); |
84
|
|
|
|
85
|
|
|
if (!$this->watch) { |
86
|
|
|
$results[] = $this->configureBehat()->run(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$hasError = false; |
90
|
|
|
foreach ($results as $result) { |
91
|
|
|
if (0 !== $result->getExitCode()) { |
92
|
|
|
$hasError = true; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if ($this->coverage) { |
97
|
|
|
$this->mergeCoverage(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if (!$this->watch) { |
101
|
|
|
if ($hasError) { |
102
|
|
|
throw new \Robo\Exception\TaskException($this, 'Tests failed'); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function coverage() |
108
|
|
|
{ |
109
|
|
|
$this->coverage = true; |
110
|
|
|
$this->test(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function mergeCoverage() |
114
|
|
|
{ |
115
|
|
|
$this |
116
|
|
|
->taskExec('phpdbg -qrr ./vendor/bin/phpcov') |
117
|
|
|
->arg('merge') |
118
|
|
|
->option('clover', 'build/logs/clover.xml') |
119
|
|
|
->option('html', 'build/html') |
120
|
|
|
->option('text') |
121
|
|
|
->option('ansi') |
122
|
|
|
->arg('build/cov') |
123
|
|
|
->run(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return \Robo\Task\Base\Exec|\Robo\Task\Testing\Behat |
|
|
|
|
128
|
|
|
*/ |
129
|
|
|
private function configureBehat() |
130
|
|
|
{ |
131
|
|
|
$task = $this->taskBehat(); |
132
|
|
|
$task->noInteraction() |
133
|
|
|
->format('progress') |
134
|
|
|
->colors(); |
135
|
|
|
|
136
|
|
|
if ($this->coverage) { |
137
|
|
|
$task->option('coverage'); |
138
|
|
|
$command = $task->getCommand(); |
139
|
|
|
$task = $this->taskExec('phpdbg -qrr '.$command); |
140
|
|
|
} else { |
141
|
|
|
$task->option('tags', '~@remote'); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return $task; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return \Robo\Task\Base\Exec|\Robo\Task\Testing\Phpspec |
|
|
|
|
149
|
|
|
*/ |
150
|
|
|
private function configurePhpSpec() |
151
|
|
|
{ |
152
|
|
|
$task = $this->taskPhpspec(); |
153
|
|
|
$task->noCodeGeneration() |
154
|
|
|
->noInteraction() |
155
|
|
|
->format('dot'); |
156
|
|
|
|
157
|
|
|
if ($this->coverage) { |
158
|
|
|
$task->option('coverage'); |
159
|
|
|
$task = $this->taskExec('phpdbg -qrr '.$task->getCommand()); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return $task; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return \Robo\Task\Base\Exec|\Robo\Task\Testing\PHPUnit |
|
|
|
|
167
|
|
|
*/ |
168
|
|
|
private function configurePhpUnit() |
169
|
|
|
{ |
170
|
|
|
$task = $this->taskPhpUnit(); |
171
|
|
|
|
172
|
|
|
if ($this->coverage) { |
173
|
|
|
$task = $this->taskExec('phpdbg -qrr '.$task->getCommand()); |
174
|
|
|
$task->option('coverage-php', 'build/cov/01-phpunit.cov') |
175
|
|
|
->option('coverage-html', 'build/phpunit'); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
return $task; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
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