|
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 tallied exit code that returns the highest exit |
|
46
|
|
|
* code returned out of the entire collection of tests |
|
47
|
|
|
* |
|
48
|
|
|
* @var int |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $exitcode = -1; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* CoverageMerger to hold track of the accumulated coverage |
|
54
|
|
|
* |
|
55
|
|
|
* @var CoverageMerger |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $coverage = null; |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
public function __construct($opts = array()) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->options = new Options($opts); |
|
63
|
8 |
|
$this->interpreter = new LogInterpreter(); |
|
64
|
|
|
$this->printer = new ResultPrinter($this->interpreter); |
|
65
|
8 |
|
} |
|
66
|
8 |
|
|
|
67
|
8 |
|
public function run() |
|
68
|
8 |
|
{ |
|
69
|
|
|
$this->verifyConfiguration(); |
|
70
|
2 |
|
$this->initCoverage(); |
|
71
|
2 |
|
$this->load(); |
|
72
|
2 |
|
$this->printer->start($this->options); |
|
73
|
2 |
|
} |
|
74
|
2 |
|
|
|
75
|
2 |
|
/** |
|
76
|
2 |
|
* Ensures a valid configuration was supplied. If not |
|
77
|
|
|
* causes ParaTest to print the error message and exit immediately |
|
78
|
|
|
* with an exit code of 1 |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function verifyConfiguration() |
|
81
|
|
|
{ |
|
82
|
|
|
if (isset($this->options->filtered['configuration']) && !file_exists($this->options->filtered['configuration']->getPath())) { |
|
|
|
|
|
|
83
|
2 |
|
$this->printer->println(sprintf('Could not read "%s".', $this->options->filtered['configuration'])); |
|
|
|
|
|
|
84
|
|
|
exit(1); |
|
|
|
|
|
|
85
|
2 |
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
2 |
|
* Builds the collection of pending ExecutableTest objects |
|
90
|
|
|
* to run. If functional mode is enabled $this->pending will |
|
91
|
|
|
* contain a collection of TestMethod objects instead of Suite |
|
92
|
|
|
* objects |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function load() |
|
95
|
|
|
{ |
|
96
|
|
|
$loader = new SuiteLoader($this->options); |
|
97
|
2 |
|
$loader->load($this->options->path); |
|
|
|
|
|
|
98
|
|
|
$executables = $this->options->functional ? $loader->getTestMethods() : $loader->getSuites(); |
|
|
|
|
|
|
99
|
2 |
|
$this->pending = array_merge($this->pending, $executables); |
|
100
|
2 |
|
foreach ($this->pending as $pending) { |
|
101
|
2 |
|
$this->printer->addTest($pending); |
|
102
|
2 |
|
} |
|
103
|
2 |
|
} |
|
104
|
2 |
|
|
|
105
|
2 |
|
/** |
|
106
|
2 |
|
* Returns the highest exit code encountered |
|
107
|
|
|
* throughout the course of test execution |
|
108
|
|
|
* |
|
109
|
|
|
* @return int |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getExitCode() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->exitcode; |
|
114
|
1 |
|
} |
|
115
|
|
|
|
|
116
|
1 |
|
/** |
|
117
|
|
|
* Write output to JUnit format if requested |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function log() |
|
120
|
|
|
{ |
|
121
|
|
|
if (!isset($this->options->filtered['log-junit'])) { |
|
|
|
|
|
|
122
|
2 |
|
return; |
|
123
|
|
|
} |
|
124
|
2 |
|
$output = $this->options->filtered['log-junit']; |
|
|
|
|
|
|
125
|
1 |
|
$writer = new Writer($this->interpreter, $this->options->path); |
|
|
|
|
|
|
126
|
|
|
$writer->write($output); |
|
127
|
1 |
|
} |
|
128
|
1 |
|
|
|
129
|
1 |
|
/** |
|
130
|
1 |
|
* Write coverage to file if requested |
|
131
|
|
|
*/ |
|
132
|
|
|
protected function logCoverage() |
|
133
|
|
|
{ |
|
134
|
|
|
if (!$this->hasCoverage()) { |
|
135
|
2 |
|
return; |
|
136
|
|
|
} |
|
137
|
2 |
|
|
|
138
|
|
|
$filteredOptions = $this->options->filtered; |
|
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
$reporter = $this->getCoverage()->getReporter(); |
|
141
|
2 |
|
|
|
142
|
2 |
|
if (isset($filteredOptions['coverage-clover'])) { |
|
143
|
2 |
|
$reporter->clover($filteredOptions['coverage-clover']); |
|
144
|
|
|
} |
|
145
|
2 |
|
|
|
146
|
|
|
if (isset($filteredOptions['coverage-html'])) { |
|
147
|
2 |
|
$reporter->html($filteredOptions['coverage-html']); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
$reporter->php($filteredOptions['coverage-php']); |
|
151
|
|
|
} |
|
152
|
2 |
|
|
|
153
|
2 |
|
protected function initCoverage() |
|
154
|
2 |
|
{ |
|
155
|
|
|
if (!isset($this->options->filtered['coverage-php'])) { |
|
|
|
|
|
|
156
|
2 |
|
return; |
|
157
|
|
|
} |
|
158
|
2 |
|
|
|
159
|
|
|
$this->coverage = new CoverageMerger(); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
2 |
|
/** |
|
163
|
2 |
|
* @return bool |
|
164
|
|
|
*/ |
|
165
|
2 |
|
protected function hasCoverage() |
|
166
|
|
|
{ |
|
167
|
2 |
|
return $this->getCoverage() !== null; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @return CoverageMerger |
|
172
|
|
|
*/ |
|
173
|
2 |
|
protected function getCoverage() |
|
174
|
|
|
{ |
|
175
|
2 |
|
return $this->coverage; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
} |
|
179
|
|
|
|
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@propertyannotation 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.