1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ParaTest\Runners\PHPUnit; |
4
|
|
|
|
5
|
|
|
use ParaTest\Coverage\CoverageMerger; |
6
|
|
|
use ParaTest\Logging\LogInterpreter; |
7
|
|
|
use ParaTest\Logging\JUnit\Writer; |
8
|
|
|
|
9
|
|
|
abstract class BaseRunner |
10
|
|
|
{ |
11
|
|
|
const PHPUNIT_FATAL_ERROR = 255; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var Options |
15
|
|
|
*/ |
16
|
|
|
protected $options; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \ParaTest\Logging\LogInterpreter |
20
|
|
|
*/ |
21
|
|
|
protected $interpreter; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ResultPrinter |
25
|
|
|
*/ |
26
|
|
|
protected $printer; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* A collection of pending ExecutableTest objects that have |
30
|
|
|
* yet to run |
31
|
|
|
* |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
protected $pending = array(); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* A collection of ExecutableTest objects that have processes |
38
|
|
|
* currently running |
39
|
|
|
* |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
protected $running = array(); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* A collection of ExecutableTest objects that have already been completed |
46
|
|
|
* and were successful. |
47
|
|
|
* |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
public $succeeded = array(); |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* A tallied exit code that returns the highest exit |
54
|
|
|
* code returned out of the entire collection of tests |
55
|
|
|
* |
56
|
|
|
* @var int |
57
|
|
|
*/ |
58
|
|
|
protected $exitcode = -1; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* CoverageMerger to hold track of the accumulated coverage |
62
|
|
|
* |
63
|
|
|
* @var CoverageMerger |
64
|
|
|
*/ |
65
|
|
|
protected $coverage = null; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Indicates whether the starting messages were printed or not. |
69
|
|
|
* |
70
|
|
|
* @var bool |
71
|
|
|
*/ |
72
|
|
|
protected $starting_messages_printed = false; |
73
|
|
|
|
74
|
|
|
|
75
|
8 |
|
public function __construct($opts = array()) |
76
|
|
|
{ |
77
|
8 |
|
$this->options = new Options($opts); |
78
|
8 |
|
$this->interpreter = new LogInterpreter(); |
79
|
8 |
|
$this->printer = new ResultPrinter($this->interpreter); |
80
|
8 |
|
} |
81
|
|
|
|
82
|
2 |
|
public function run() |
83
|
|
|
{ |
84
|
2 |
|
$this->verifyConfiguration(); |
85
|
2 |
|
$this->initCoverage(); |
86
|
2 |
|
$this->load(); |
87
|
|
|
|
88
|
|
|
// Print the starting messages only if they were not printed yet. |
89
|
2 |
|
if (!$this->starting_messages_printed) { |
90
|
2 |
|
$this->printer->start($this->options); |
91
|
2 |
|
$this->starting_messages_printed = true; |
92
|
2 |
|
} |
93
|
2 |
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Ensures a valid configuration was supplied. If not |
97
|
|
|
* causes ParaTest to print the error message and exit immediately |
98
|
|
|
* with an exit code of 1 |
99
|
|
|
*/ |
100
|
2 |
|
protected function verifyConfiguration() |
101
|
|
|
{ |
102
|
2 |
|
if (isset($this->options->filtered['configuration']) && !file_exists($this->options->filtered['configuration']->getPath())) { |
|
|
|
|
103
|
|
|
$this->printer->println(sprintf('Could not read "%s".', $this->options->filtered['configuration'])); |
|
|
|
|
104
|
|
|
exit(1); |
|
|
|
|
105
|
|
|
} |
106
|
2 |
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Builds the collection of pending ExecutableTest objects |
110
|
|
|
* to run. If functional mode is enabled $this->pending will |
111
|
|
|
* contain a collection of TestMethod objects instead of Suite |
112
|
|
|
* objects |
113
|
|
|
*/ |
114
|
2 |
|
protected function load() |
115
|
|
|
{ |
116
|
2 |
|
$loader = new SuiteLoader($this->options); |
117
|
2 |
|
$loader->load($this->options->path); |
|
|
|
|
118
|
2 |
|
$executables = $this->options->functional || $this->options->only_repeat_failed ? $loader->getTestMethods() : $loader->getSuites(); |
|
|
|
|
119
|
|
|
// Skip successful tests. |
120
|
2 |
|
if ($this->options->only_repeat_failed) { |
|
|
|
|
121
|
|
|
foreach ($this->succeeded as $test) { |
122
|
|
|
foreach ($executables as $key => $executable) { |
123
|
|
|
if ($test->getPath() == $executable->getPath() && $test->getName() == $executable->getName()) { |
124
|
|
|
unset($executables[$key]); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
} |
129
|
2 |
|
$this->pending = array_merge($this->pending, $executables); |
130
|
2 |
|
foreach ($this->pending as $pending) { |
131
|
2 |
|
$this->printer->addTest($pending); |
132
|
2 |
|
} |
133
|
2 |
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Returns the highest exit code encountered |
137
|
|
|
* throughout the course of test execution |
138
|
|
|
* |
139
|
|
|
* @return int |
140
|
|
|
*/ |
141
|
3 |
|
public function getExitCode() |
142
|
2 |
|
{ |
143
|
3 |
|
return $this->exitcode; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Write output to JUnit format if requested |
148
|
|
|
*/ |
149
|
2 |
|
protected function log() |
150
|
|
|
{ |
151
|
2 |
|
if (!isset($this->options->filtered['log-junit'])) { |
|
|
|
|
152
|
1 |
|
return; |
153
|
|
|
} |
154
|
1 |
|
$output = $this->options->filtered['log-junit']; |
|
|
|
|
155
|
1 |
|
$writer = new Writer($this->interpreter, $this->options->path); |
|
|
|
|
156
|
1 |
|
$writer->write($output); |
157
|
1 |
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Write coverage to file if requested |
161
|
|
|
*/ |
162
|
2 |
|
protected function logCoverage() |
163
|
|
|
{ |
164
|
2 |
|
if (!$this->hasCoverage()) { |
165
|
|
|
return; |
166
|
|
|
} |
167
|
|
|
|
168
|
2 |
|
$filteredOptions = $this->options->filtered; |
|
|
|
|
169
|
|
|
|
170
|
2 |
|
$reporter = $this->getCoverage()->getReporter(); |
171
|
|
|
|
172
|
2 |
|
if (isset($filteredOptions['coverage-clover'])) { |
173
|
|
|
$reporter->clover($filteredOptions['coverage-clover']); |
174
|
|
|
} |
175
|
|
|
|
176
|
2 |
|
if (isset($filteredOptions['coverage-html'])) { |
177
|
|
|
$reporter->html($filteredOptions['coverage-html']); |
178
|
|
|
} |
179
|
|
|
|
180
|
2 |
|
$reporter->php($filteredOptions['coverage-php']); |
181
|
2 |
|
} |
182
|
|
|
|
183
|
2 |
|
protected function initCoverage() |
184
|
|
|
{ |
185
|
2 |
|
if (!isset($this->options->filtered['coverage-php'])) { |
|
|
|
|
186
|
|
|
return; |
187
|
|
|
} |
188
|
|
|
|
189
|
2 |
|
$this->coverage = new CoverageMerger(); |
190
|
2 |
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @return bool |
194
|
|
|
*/ |
195
|
2 |
|
protected function hasCoverage() |
196
|
|
|
{ |
197
|
2 |
|
return $this->getCoverage() !== null; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return CoverageMerger |
202
|
|
|
*/ |
203
|
2 |
|
protected function getCoverage() |
204
|
|
|
{ |
205
|
2 |
|
return $this->coverage; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
} |
209
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.