1 | <?php |
||
9 | class Runner extends BaseRunner |
||
10 | { |
||
11 | /** |
||
12 | * A collection of available tokens based on the number |
||
13 | * of processes specified in $options. |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $tokens = []; |
||
18 | |||
19 | 8 | public function __construct(array $opts = []) |
|
24 | |||
25 | /** |
||
26 | * The money maker. Runs all ExecutableTest objects in separate processes. |
||
27 | */ |
||
28 | 2 | public function run() |
|
44 | |||
45 | /** |
||
46 | * Finalizes the run process. This method |
||
47 | * prints all results, rewinds the log interpreter, |
||
48 | * logs any results to JUnit, and cleans up temporary |
||
49 | * files. |
||
50 | */ |
||
51 | 2 | private function complete() |
|
62 | |||
63 | /** |
||
64 | * This method removes ExecutableTest objects from the pending collection |
||
65 | * and adds them to the running collection. It is also in charge of recycling and |
||
66 | * acquiring available test tokens for use. |
||
67 | */ |
||
68 | 2 | private function fillRunQueue() |
|
80 | |||
81 | /** |
||
82 | * Returns whether or not a test has finished being |
||
83 | * executed. If it has, this method also halts a test process - optionally |
||
84 | * throwing an exception if a fatal error has occurred - |
||
85 | * prints feedback, and updates the overall exit code. |
||
86 | * |
||
87 | * @param ExecutableTest $test |
||
88 | * |
||
89 | * @throws \Exception |
||
90 | * |
||
91 | * @return bool |
||
92 | */ |
||
93 | 2 | private function testIsStillRunning(ExecutableTest $test): bool |
|
117 | |||
118 | /** |
||
119 | * If the provided test object has an exit code |
||
120 | * higher than the currently set exit code, that exit |
||
121 | * code will be set as the overall exit code. |
||
122 | * |
||
123 | * @param ExecutableTest $test |
||
124 | */ |
||
125 | 2 | private function setExitCode(ExecutableTest $test) |
|
132 | |||
133 | /** |
||
134 | * Initialize the available test tokens based |
||
135 | * on how many processes ParaTest will be run in. |
||
136 | */ |
||
137 | 8 | protected function initTokens() |
|
138 | { |
||
139 | 8 | $this->tokens = []; |
|
140 | 8 | for ($i = 1; $i <= $this->options->processes; ++$i) { |
|
141 | 8 | $this->tokens[$i] = ['token' => $i, 'unique' => uniqid(sprintf('%s_', $i)), 'available' => true]; |
|
142 | } |
||
143 | 8 | } |
|
144 | |||
145 | /** |
||
146 | * Gets the next token that is available to be acquired |
||
147 | * from a finished process. |
||
148 | * |
||
149 | * @return bool|array |
||
150 | */ |
||
151 | 4 | protected function getNextAvailableToken() |
|
152 | { |
||
153 | 4 | foreach ($this->tokens as $data) { |
|
154 | 4 | if ($data['available']) { |
|
155 | 4 | return $data; |
|
156 | } |
||
157 | } |
||
158 | |||
159 | 1 | return false; |
|
160 | } |
||
161 | |||
162 | /** |
||
163 | * Flag a token as available for use. |
||
164 | * |
||
165 | * @param string $tokenIdentifier |
||
166 | */ |
||
167 | protected function releaseToken($tokenIdentifier) |
||
168 | { |
||
169 | 3 | $filtered = array_filter($this->tokens, function ($val) use ($tokenIdentifier) { |
|
170 | 3 | return $val['token'] === $tokenIdentifier; |
|
171 | 3 | }); |
|
172 | 3 | $keys = array_keys($filtered); |
|
173 | 3 | $this->tokens[$keys[0]]['available'] = true; |
|
174 | 3 | } |
|
175 | |||
176 | /** |
||
177 | * Flag a token as acquired and not available for use. |
||
178 | * |
||
179 | * @param string $tokenIdentifier |
||
180 | */ |
||
181 | protected function acquireToken($tokenIdentifier) |
||
182 | { |
||
183 | 2 | $filtered = array_filter($this->tokens, function ($val) use ($tokenIdentifier) { |
|
184 | 2 | return $val['token'] === $tokenIdentifier; |
|
185 | 2 | }); |
|
186 | 2 | $keys = array_keys($filtered); |
|
187 | 2 | $this->tokens[$keys[0]]['available'] = false; |
|
188 | 2 | } |
|
189 | |||
190 | /** |
||
191 | * @param ExecutableTest $test |
||
192 | */ |
||
193 | 2 | private function addCoverage(ExecutableTest $test) |
|
198 | } |
||
199 |
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.