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