1 | <?php |
||
4 | class WrapperRunner extends BaseRunner |
||
5 | { |
||
6 | const PHPUNIT_FAILURES = 1; |
||
7 | const PHPUNIT_ERRORS = 2; |
||
8 | |||
9 | /** |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $streams; |
||
13 | |||
14 | /** |
||
15 | * @var Worker[] |
||
16 | */ |
||
17 | protected $workers; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $modified; |
||
23 | |||
24 | |||
25 | public function run() |
||
26 | { |
||
27 | parent::run(); |
||
28 | |||
29 | $this->startWorkers(); |
||
30 | $this->assignAllPendingTests(); |
||
31 | $this->sendStopMessages(); |
||
32 | $this->waitForAllToFinish(); |
||
33 | $this->complete(); |
||
34 | } |
||
35 | |||
36 | protected function load() |
||
37 | { |
||
38 | if ($this->options->functional) { |
||
|
|||
39 | throw new \RuntimeException("The `functional` option is not supported yet in the WrapperRunner. Only full classes can be run due to the current PHPUnit commands causing classloading issues."); |
||
40 | } |
||
41 | parent::load(); |
||
42 | } |
||
43 | |||
44 | private function startWorkers() |
||
45 | { |
||
46 | $wrapper = realpath(__DIR__ . '/../../../../bin/phpunit-wrapper'); |
||
47 | for ($i = 1; $i <= $this->options->processes; $i++) { |
||
48 | $worker = new Worker(); |
||
49 | if ($this->options->noTestTokens) { |
||
50 | $token = null; |
||
51 | $uniqueToken = null; |
||
52 | } else { |
||
53 | $token = $i; |
||
54 | $uniqueToken = uniqid(); |
||
55 | } |
||
56 | $worker->start($wrapper, $token, $uniqueToken); |
||
57 | $this->streams[] = $worker->stdout(); |
||
58 | $this->workers[] = $worker; |
||
59 | } |
||
60 | } |
||
61 | |||
62 | private function assignAllPendingTests() |
||
63 | { |
||
64 | $phpunit = $this->options->phpunit; |
||
65 | $phpunitOptions = $this->options->filtered; |
||
66 | $phpunitOptions['no-globals-backup'] = null; |
||
67 | while (count($this->pending)) { |
||
68 | $this->waitForStreamsToChange($this->streams); |
||
69 | foreach ($this->progressedWorkers() as $worker) { |
||
70 | if ($worker->isFree()) { |
||
71 | $this->flushWorker($worker); |
||
72 | $pending = array_shift($this->pending); |
||
73 | if ($pending) { |
||
74 | $worker->assign($pending, $phpunit, $phpunitOptions); |
||
75 | } |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 | |||
81 | private function sendStopMessages() |
||
82 | { |
||
83 | foreach ($this->workers as $worker) { |
||
84 | $worker->stop(); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | private function waitForAllToFinish() |
||
102 | |||
103 | // put on WorkersPool |
||
104 | private function waitForStreamsToChange($modified) |
||
105 | { |
||
106 | $write = array(); |
||
107 | $except = array(); |
||
108 | $result = stream_select($modified, $write, $except, 1); |
||
109 | if ($result === false) { |
||
110 | throw new \RuntimeException("stream_select() returned an error while waiting for all workers to finish."); |
||
111 | } |
||
112 | $this->modified = $modified; |
||
113 | return $result; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * put on WorkersPool |
||
118 | * @return Worker[] |
||
119 | */ |
||
120 | private function progressedWorkers() |
||
136 | |||
137 | /** |
||
138 | * Returns the output streams of a subset of workers. |
||
139 | * @param array keys are positions in $this->workers |
||
140 | * @return array |
||
141 | */ |
||
142 | private function streamsOf($workers) |
||
150 | |||
151 | private function complete() |
||
163 | |||
164 | |||
165 | private function setExitCode() |
||
175 | |||
176 | private function flushWorker($worker) |
||
184 | |||
185 | /** |
||
186 | private function testIsStillRunning($test) |
||
187 | { |
||
188 | if(!$test->isDoneRunning()) return true; |
||
189 | $this->setExitCode($test); |
||
190 | $test->stop(); |
||
191 | if (static::PHPUNIT_FATAL_ERROR === $test->getExitCode()) |
||
192 | throw new \Exception($test->getStderr(), $test->getExitCode()); |
||
193 | return false; |
||
194 | } |
||
195 | */ |
||
196 | } |
||
197 |
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.