@@ -15,13 +15,13 @@ |
||
15 | 15 | */ |
16 | 16 | class AssertionFailedError extends Exception implements SelfDescribing |
17 | 17 | { |
18 | - /** |
|
19 | - * Wrapper for getMessage() which is declared as final. |
|
20 | - * |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - public function toString() |
|
24 | - { |
|
25 | - return $this->getMessage(); |
|
26 | - } |
|
18 | + /** |
|
19 | + * Wrapper for getMessage() which is declared as final. |
|
20 | + * |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + public function toString() |
|
24 | + { |
|
25 | + return $this->getMessage(); |
|
26 | + } |
|
27 | 27 | } |
@@ -100,2420 +100,2420 @@ |
||
100 | 100 | */ |
101 | 101 | abstract class TestCase extends Assert implements Test, SelfDescribing |
102 | 102 | { |
103 | - /** |
|
104 | - * Enable or disable the backup and restoration of the $GLOBALS array. |
|
105 | - * Overwrite this attribute in a child class of TestCase. |
|
106 | - * Setting this attribute in setUp() has no effect! |
|
107 | - * |
|
108 | - * @var bool |
|
109 | - */ |
|
110 | - protected $backupGlobals; |
|
111 | - |
|
112 | - /** |
|
113 | - * @var array |
|
114 | - */ |
|
115 | - protected $backupGlobalsBlacklist = []; |
|
116 | - |
|
117 | - /** |
|
118 | - * Enable or disable the backup and restoration of static attributes. |
|
119 | - * Overwrite this attribute in a child class of TestCase. |
|
120 | - * Setting this attribute in setUp() has no effect! |
|
121 | - * |
|
122 | - * @var bool |
|
123 | - */ |
|
124 | - protected $backupStaticAttributes; |
|
125 | - |
|
126 | - /** |
|
127 | - * @var array |
|
128 | - */ |
|
129 | - protected $backupStaticAttributesBlacklist = []; |
|
130 | - |
|
131 | - /** |
|
132 | - * Whether or not this test is to be run in a separate PHP process. |
|
133 | - * |
|
134 | - * @var bool |
|
135 | - */ |
|
136 | - protected $runTestInSeparateProcess; |
|
137 | - |
|
138 | - /** |
|
139 | - * Whether or not this class is to be run in a separate PHP process. |
|
140 | - * |
|
141 | - * @var bool |
|
142 | - */ |
|
143 | - private $runClassInSeparateProcess; |
|
144 | - |
|
145 | - /** |
|
146 | - * Whether or not this test should preserve the global state when |
|
147 | - * running in a separate PHP process. |
|
148 | - * |
|
149 | - * @var bool |
|
150 | - */ |
|
151 | - protected $preserveGlobalState = true; |
|
152 | - |
|
153 | - /** |
|
154 | - * Whether or not this test is running in a separate PHP process. |
|
155 | - * |
|
156 | - * @var bool |
|
157 | - */ |
|
158 | - private $inIsolation = false; |
|
159 | - |
|
160 | - /** |
|
161 | - * @var array |
|
162 | - */ |
|
163 | - private $data; |
|
164 | - |
|
165 | - /** |
|
166 | - * @var string |
|
167 | - */ |
|
168 | - private $dataName; |
|
169 | - |
|
170 | - /** |
|
171 | - * @var bool |
|
172 | - */ |
|
173 | - private $useErrorHandler; |
|
174 | - |
|
175 | - /** |
|
176 | - * The name of the expected Exception. |
|
177 | - * |
|
178 | - * @var null|string |
|
179 | - */ |
|
180 | - private $expectedException; |
|
181 | - |
|
182 | - /** |
|
183 | - * The message of the expected Exception. |
|
184 | - * |
|
185 | - * @var string |
|
186 | - */ |
|
187 | - private $expectedExceptionMessage; |
|
188 | - |
|
189 | - /** |
|
190 | - * The regex pattern to validate the expected Exception message. |
|
191 | - * |
|
192 | - * @var string |
|
193 | - */ |
|
194 | - private $expectedExceptionMessageRegExp; |
|
195 | - |
|
196 | - /** |
|
197 | - * The code of the expected Exception. |
|
198 | - * |
|
199 | - * @var null|int|string |
|
200 | - */ |
|
201 | - private $expectedExceptionCode; |
|
202 | - |
|
203 | - /** |
|
204 | - * The name of the test case. |
|
205 | - * |
|
206 | - * @var string |
|
207 | - */ |
|
208 | - private $name; |
|
209 | - |
|
210 | - /** |
|
211 | - * @var string[] |
|
212 | - */ |
|
213 | - private $dependencies = []; |
|
214 | - |
|
215 | - /** |
|
216 | - * @var array |
|
217 | - */ |
|
218 | - private $dependencyInput = []; |
|
219 | - |
|
220 | - /** |
|
221 | - * @var array |
|
222 | - */ |
|
223 | - private $iniSettings = []; |
|
224 | - |
|
225 | - /** |
|
226 | - * @var array |
|
227 | - */ |
|
228 | - private $locale = []; |
|
229 | - |
|
230 | - /** |
|
231 | - * @var array |
|
232 | - */ |
|
233 | - private $mockObjects = []; |
|
234 | - |
|
235 | - /** |
|
236 | - * @var array |
|
237 | - */ |
|
238 | - private $mockObjectGenerator; |
|
239 | - |
|
240 | - /** |
|
241 | - * @var int |
|
242 | - */ |
|
243 | - private $status; |
|
244 | - |
|
245 | - /** |
|
246 | - * @var string |
|
247 | - */ |
|
248 | - private $statusMessage = ''; |
|
249 | - |
|
250 | - /** |
|
251 | - * @var int |
|
252 | - */ |
|
253 | - private $numAssertions = 0; |
|
254 | - |
|
255 | - /** |
|
256 | - * @var TestResult |
|
257 | - */ |
|
258 | - private $result; |
|
259 | - |
|
260 | - /** |
|
261 | - * @var mixed |
|
262 | - */ |
|
263 | - private $testResult; |
|
264 | - |
|
265 | - /** |
|
266 | - * @var string |
|
267 | - */ |
|
268 | - private $output = ''; |
|
269 | - |
|
270 | - /** |
|
271 | - * @var string |
|
272 | - */ |
|
273 | - private $outputExpectedRegex; |
|
274 | - |
|
275 | - /** |
|
276 | - * @var string |
|
277 | - */ |
|
278 | - private $outputExpectedString; |
|
279 | - |
|
280 | - /** |
|
281 | - * @var mixed |
|
282 | - */ |
|
283 | - private $outputCallback = false; |
|
284 | - |
|
285 | - /** |
|
286 | - * @var bool |
|
287 | - */ |
|
288 | - private $outputBufferingActive = false; |
|
289 | - |
|
290 | - /** |
|
291 | - * @var int |
|
292 | - */ |
|
293 | - private $outputBufferingLevel; |
|
294 | - |
|
295 | - /** |
|
296 | - * @var SebastianBergmann\GlobalState\Snapshot |
|
297 | - */ |
|
298 | - private $snapshot; |
|
299 | - |
|
300 | - /** |
|
301 | - * @var Prophecy\Prophet |
|
302 | - */ |
|
303 | - private $prophet; |
|
304 | - |
|
305 | - /** |
|
306 | - * @var bool |
|
307 | - */ |
|
308 | - private $beStrictAboutChangesToGlobalState = false; |
|
309 | - |
|
310 | - /** |
|
311 | - * @var bool |
|
312 | - */ |
|
313 | - private $registerMockObjectsFromTestArgumentsRecursively = false; |
|
314 | - |
|
315 | - /** |
|
316 | - * @var string[] |
|
317 | - */ |
|
318 | - private $warnings = []; |
|
319 | - |
|
320 | - /** |
|
321 | - * @var array |
|
322 | - */ |
|
323 | - private $groups = []; |
|
324 | - |
|
325 | - /** |
|
326 | - * @var bool |
|
327 | - */ |
|
328 | - private $doesNotPerformAssertions = false; |
|
329 | - |
|
330 | - /** |
|
331 | - * @var Comparator[] |
|
332 | - */ |
|
333 | - private $customComparators = []; |
|
334 | - |
|
335 | - /** |
|
336 | - * Constructs a test case with the given name. |
|
337 | - * |
|
338 | - * @param string $name |
|
339 | - * @param array $data |
|
340 | - * @param string $dataName |
|
341 | - */ |
|
342 | - public function __construct($name = null, array $data = [], $dataName = '') |
|
343 | - { |
|
344 | - if ($name !== null) { |
|
345 | - $this->setName($name); |
|
346 | - } |
|
347 | - |
|
348 | - $this->data = $data; |
|
349 | - $this->dataName = $dataName; |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Returns a string representation of the test case. |
|
354 | - * |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - public function toString() |
|
358 | - { |
|
359 | - $class = new ReflectionClass($this); |
|
360 | - |
|
361 | - $buffer = \sprintf( |
|
362 | - '%s::%s', |
|
363 | - $class->name, |
|
364 | - $this->getName(false) |
|
365 | - ); |
|
366 | - |
|
367 | - return $buffer . $this->getDataSetAsString(); |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Counts the number of test cases executed by run(TestResult result). |
|
372 | - * |
|
373 | - * @return int |
|
374 | - */ |
|
375 | - public function count() |
|
376 | - { |
|
377 | - return 1; |
|
378 | - } |
|
379 | - |
|
380 | - public function getGroups() |
|
381 | - { |
|
382 | - return $this->groups; |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * @param array $groups |
|
387 | - */ |
|
388 | - public function setGroups(array $groups) |
|
389 | - { |
|
390 | - $this->groups = $groups; |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Returns the annotations for this test. |
|
395 | - * |
|
396 | - * @return array |
|
397 | - */ |
|
398 | - public function getAnnotations() |
|
399 | - { |
|
400 | - return \PHPUnit\Util\Test::parseTestMethodAnnotations( |
|
401 | - \get_class($this), |
|
402 | - $this->name |
|
403 | - ); |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Gets the name of a TestCase. |
|
408 | - * |
|
409 | - * @param bool $withDataSet |
|
410 | - * |
|
411 | - * @return string |
|
412 | - */ |
|
413 | - public function getName($withDataSet = true) |
|
414 | - { |
|
415 | - if ($withDataSet) { |
|
416 | - return $this->name . $this->getDataSetAsString(false); |
|
417 | - } |
|
418 | - |
|
419 | - return $this->name; |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Returns the size of the test. |
|
424 | - * |
|
425 | - * @return int |
|
426 | - */ |
|
427 | - public function getSize() |
|
428 | - { |
|
429 | - return \PHPUnit\Util\Test::getSize( |
|
430 | - \get_class($this), |
|
431 | - $this->getName(false) |
|
432 | - ); |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * @return bool |
|
437 | - */ |
|
438 | - public function hasSize() |
|
439 | - { |
|
440 | - return $this->getSize() !== \PHPUnit\Util\Test::UNKNOWN; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * @return bool |
|
445 | - */ |
|
446 | - public function isSmall() |
|
447 | - { |
|
448 | - return $this->getSize() === \PHPUnit\Util\Test::SMALL; |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * @return bool |
|
453 | - */ |
|
454 | - public function isMedium() |
|
455 | - { |
|
456 | - return $this->getSize() === \PHPUnit\Util\Test::MEDIUM; |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * @return bool |
|
461 | - */ |
|
462 | - public function isLarge() |
|
463 | - { |
|
464 | - return $this->getSize() === \PHPUnit\Util\Test::LARGE; |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * @return string |
|
469 | - */ |
|
470 | - public function getActualOutput() |
|
471 | - { |
|
472 | - if (!$this->outputBufferingActive) { |
|
473 | - return $this->output; |
|
474 | - } |
|
475 | - |
|
476 | - return \ob_get_contents(); |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * @return bool |
|
481 | - */ |
|
482 | - public function hasOutput() |
|
483 | - { |
|
484 | - if (\strlen($this->output) === 0) { |
|
485 | - return false; |
|
486 | - } |
|
487 | - |
|
488 | - if ($this->hasExpectationOnOutput()) { |
|
489 | - return false; |
|
490 | - } |
|
491 | - |
|
492 | - return true; |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * @return bool |
|
497 | - */ |
|
498 | - public function doesNotPerformAssertions() |
|
499 | - { |
|
500 | - return $this->doesNotPerformAssertions; |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * @param string $expectedRegex |
|
505 | - * |
|
506 | - * @throws Exception |
|
507 | - */ |
|
508 | - public function expectOutputRegex($expectedRegex) |
|
509 | - { |
|
510 | - if ($this->outputExpectedString !== null) { |
|
511 | - throw new Exception; |
|
512 | - } |
|
513 | - |
|
514 | - if (\is_string($expectedRegex) || null === $expectedRegex) { |
|
515 | - $this->outputExpectedRegex = $expectedRegex; |
|
516 | - } |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * @param string $expectedString |
|
521 | - */ |
|
522 | - public function expectOutputString($expectedString) |
|
523 | - { |
|
524 | - if ($this->outputExpectedRegex !== null) { |
|
525 | - throw new Exception; |
|
526 | - } |
|
527 | - |
|
528 | - if (\is_string($expectedString) || null === $expectedString) { |
|
529 | - $this->outputExpectedString = $expectedString; |
|
530 | - } |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * @return bool |
|
535 | - */ |
|
536 | - public function hasExpectationOnOutput() |
|
537 | - { |
|
538 | - return \is_string($this->outputExpectedString) || \is_string($this->outputExpectedRegex); |
|
539 | - } |
|
540 | - |
|
541 | - /** |
|
542 | - * @return null|string |
|
543 | - */ |
|
544 | - public function getExpectedException() |
|
545 | - { |
|
546 | - return $this->expectedException; |
|
547 | - } |
|
548 | - |
|
549 | - /** |
|
550 | - * @return null|int|string |
|
551 | - */ |
|
552 | - public function getExpectedExceptionCode() |
|
553 | - { |
|
554 | - return $this->expectedExceptionCode; |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * @return string |
|
559 | - */ |
|
560 | - public function getExpectedExceptionMessage() |
|
561 | - { |
|
562 | - return $this->expectedExceptionMessage; |
|
563 | - } |
|
564 | - |
|
565 | - /** |
|
566 | - * @return string |
|
567 | - */ |
|
568 | - public function getExpectedExceptionMessageRegExp() |
|
569 | - { |
|
570 | - return $this->expectedExceptionMessageRegExp; |
|
571 | - } |
|
572 | - |
|
573 | - /** |
|
574 | - * @param string $exception |
|
575 | - */ |
|
576 | - public function expectException($exception) |
|
577 | - { |
|
578 | - if (!\is_string($exception)) { |
|
579 | - throw InvalidArgumentHelper::factory(1, 'string'); |
|
580 | - } |
|
581 | - |
|
582 | - $this->expectedException = $exception; |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * @param int|string $code |
|
587 | - * |
|
588 | - * @throws Exception |
|
589 | - */ |
|
590 | - public function expectExceptionCode($code) |
|
591 | - { |
|
592 | - if (!\is_int($code) && !\is_string($code)) { |
|
593 | - throw InvalidArgumentHelper::factory(1, 'integer or string'); |
|
594 | - } |
|
595 | - |
|
596 | - $this->expectedExceptionCode = $code; |
|
597 | - } |
|
598 | - |
|
599 | - /** |
|
600 | - * @param string $message |
|
601 | - * |
|
602 | - * @throws Exception |
|
603 | - */ |
|
604 | - public function expectExceptionMessage($message) |
|
605 | - { |
|
606 | - if (!\is_string($message)) { |
|
607 | - throw InvalidArgumentHelper::factory(1, 'string'); |
|
608 | - } |
|
609 | - |
|
610 | - $this->expectedExceptionMessage = $message; |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * @param string $messageRegExp |
|
615 | - * |
|
616 | - * @throws Exception |
|
617 | - */ |
|
618 | - public function expectExceptionMessageRegExp($messageRegExp) |
|
619 | - { |
|
620 | - if (!\is_string($messageRegExp)) { |
|
621 | - throw InvalidArgumentHelper::factory(1, 'string'); |
|
622 | - } |
|
623 | - |
|
624 | - $this->expectedExceptionMessageRegExp = $messageRegExp; |
|
625 | - } |
|
626 | - |
|
627 | - /** |
|
628 | - * Sets up an expectation for an exception to be raised by the code under test. |
|
629 | - * Information for expected exception class, expected exception message, and |
|
630 | - * expected exception code are retrieved from a given Exception object. |
|
631 | - */ |
|
632 | - public function expectExceptionObject(\Exception $exception) |
|
633 | - { |
|
634 | - $this->expectException(\get_class($exception)); |
|
635 | - $this->expectExceptionMessage($exception->getMessage()); |
|
636 | - $this->expectExceptionCode($exception->getCode()); |
|
637 | - } |
|
638 | - |
|
639 | - /** |
|
640 | - * @param bool $flag |
|
641 | - */ |
|
642 | - public function setRegisterMockObjectsFromTestArgumentsRecursively($flag) |
|
643 | - { |
|
644 | - if (!\is_bool($flag)) { |
|
645 | - throw InvalidArgumentHelper::factory(1, 'boolean'); |
|
646 | - } |
|
647 | - |
|
648 | - $this->registerMockObjectsFromTestArgumentsRecursively = $flag; |
|
649 | - } |
|
650 | - |
|
651 | - protected function setExpectedExceptionFromAnnotation() |
|
652 | - { |
|
653 | - try { |
|
654 | - $expectedException = \PHPUnit\Util\Test::getExpectedException( |
|
655 | - \get_class($this), |
|
656 | - $this->name |
|
657 | - ); |
|
658 | - |
|
659 | - if ($expectedException !== false) { |
|
660 | - $this->expectException($expectedException['class']); |
|
661 | - |
|
662 | - if ($expectedException['code'] !== null) { |
|
663 | - $this->expectExceptionCode($expectedException['code']); |
|
664 | - } |
|
665 | - |
|
666 | - if ($expectedException['message'] !== '') { |
|
667 | - $this->expectExceptionMessage($expectedException['message']); |
|
668 | - } elseif ($expectedException['message_regex'] !== '') { |
|
669 | - $this->expectExceptionMessageRegExp($expectedException['message_regex']); |
|
670 | - } |
|
671 | - } |
|
672 | - } catch (ReflectionException $e) { |
|
673 | - } |
|
674 | - } |
|
675 | - |
|
676 | - /** |
|
677 | - * @param bool $useErrorHandler |
|
678 | - */ |
|
679 | - public function setUseErrorHandler($useErrorHandler) |
|
680 | - { |
|
681 | - $this->useErrorHandler = $useErrorHandler; |
|
682 | - } |
|
683 | - |
|
684 | - protected function setUseErrorHandlerFromAnnotation() |
|
685 | - { |
|
686 | - try { |
|
687 | - $useErrorHandler = \PHPUnit\Util\Test::getErrorHandlerSettings( |
|
688 | - \get_class($this), |
|
689 | - $this->name |
|
690 | - ); |
|
691 | - |
|
692 | - if ($useErrorHandler !== null) { |
|
693 | - $this->setUseErrorHandler($useErrorHandler); |
|
694 | - } |
|
695 | - } catch (ReflectionException $e) { |
|
696 | - } |
|
697 | - } |
|
698 | - |
|
699 | - protected function checkRequirements() |
|
700 | - { |
|
701 | - if (!$this->name || !\method_exists($this, $this->name)) { |
|
702 | - return; |
|
703 | - } |
|
704 | - |
|
705 | - $missingRequirements = \PHPUnit\Util\Test::getMissingRequirements( |
|
706 | - \get_class($this), |
|
707 | - $this->name |
|
708 | - ); |
|
709 | - |
|
710 | - if (!empty($missingRequirements)) { |
|
711 | - $this->markTestSkipped(\implode(PHP_EOL, $missingRequirements)); |
|
712 | - } |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * Returns the status of this test. |
|
717 | - * |
|
718 | - * @return int |
|
719 | - */ |
|
720 | - public function getStatus() |
|
721 | - { |
|
722 | - return $this->status; |
|
723 | - } |
|
724 | - |
|
725 | - public function markAsRisky() |
|
726 | - { |
|
727 | - $this->status = BaseTestRunner::STATUS_RISKY; |
|
728 | - } |
|
729 | - |
|
730 | - /** |
|
731 | - * Returns the status message of this test. |
|
732 | - * |
|
733 | - * @return string |
|
734 | - */ |
|
735 | - public function getStatusMessage() |
|
736 | - { |
|
737 | - return $this->statusMessage; |
|
738 | - } |
|
739 | - |
|
740 | - /** |
|
741 | - * Returns whether or not this test has failed. |
|
742 | - * |
|
743 | - * @return bool |
|
744 | - */ |
|
745 | - public function hasFailed() |
|
746 | - { |
|
747 | - $status = $this->getStatus(); |
|
748 | - |
|
749 | - return $status == BaseTestRunner::STATUS_FAILURE || |
|
750 | - $status == BaseTestRunner::STATUS_ERROR; |
|
751 | - } |
|
752 | - |
|
753 | - /** |
|
754 | - * Runs the test case and collects the results in a TestResult object. |
|
755 | - * If no TestResult object is passed a new one will be created. |
|
756 | - * |
|
757 | - * @param TestResult $result |
|
758 | - * |
|
759 | - * @return TestResult|null |
|
760 | - * |
|
761 | - * @throws Exception |
|
762 | - */ |
|
763 | - public function run(TestResult $result = null) |
|
764 | - { |
|
765 | - if ($result === null) { |
|
766 | - $result = $this->createResult(); |
|
767 | - } |
|
768 | - |
|
769 | - if (!$this instanceof WarningTestCase) { |
|
770 | - $this->setTestResultObject($result); |
|
771 | - $this->setUseErrorHandlerFromAnnotation(); |
|
772 | - } |
|
773 | - |
|
774 | - if ($this->useErrorHandler !== null) { |
|
775 | - $oldErrorHandlerSetting = $result->getConvertErrorsToExceptions(); |
|
776 | - $result->convertErrorsToExceptions($this->useErrorHandler); |
|
777 | - } |
|
778 | - |
|
779 | - if (!$this instanceof WarningTestCase && |
|
780 | - !$this instanceof SkippedTestCase && |
|
781 | - !$this->handleDependencies()) { |
|
782 | - return; |
|
783 | - } |
|
784 | - |
|
785 | - $runEntireClass = $this->runClassInSeparateProcess && !$this->runTestInSeparateProcess; |
|
786 | - |
|
787 | - if (($this->runTestInSeparateProcess === true || $this->runClassInSeparateProcess === true) && |
|
788 | - $this->inIsolation !== true && |
|
789 | - !$this instanceof PhptTestCase) { |
|
790 | - $class = new ReflectionClass($this); |
|
791 | - |
|
792 | - if ($runEntireClass) { |
|
793 | - $template = new Text_Template( |
|
794 | - __DIR__ . '/../Util/PHP/Template/TestCaseClass.tpl' |
|
795 | - ); |
|
796 | - } else { |
|
797 | - $template = new Text_Template( |
|
798 | - __DIR__ . '/../Util/PHP/Template/TestCaseMethod.tpl' |
|
799 | - ); |
|
800 | - } |
|
801 | - |
|
802 | - if ($this->preserveGlobalState) { |
|
803 | - $constants = GlobalState::getConstantsAsString(); |
|
804 | - $globals = GlobalState::getGlobalsAsString(); |
|
805 | - $includedFiles = GlobalState::getIncludedFilesAsString(); |
|
806 | - $iniSettings = GlobalState::getIniSettingsAsString(); |
|
807 | - } else { |
|
808 | - $constants = ''; |
|
809 | - if (!empty($GLOBALS['__PHPUNIT_BOOTSTRAP'])) { |
|
810 | - $globals = '$GLOBALS[\'__PHPUNIT_BOOTSTRAP\'] = ' . \var_export($GLOBALS['__PHPUNIT_BOOTSTRAP'], true) . ";\n"; |
|
811 | - } else { |
|
812 | - $globals = ''; |
|
813 | - } |
|
814 | - $includedFiles = ''; |
|
815 | - $iniSettings = ''; |
|
816 | - } |
|
817 | - |
|
818 | - $coverage = $result->getCollectCodeCoverageInformation() ? 'true' : 'false'; |
|
819 | - $isStrictAboutTestsThatDoNotTestAnything = $result->isStrictAboutTestsThatDoNotTestAnything() ? 'true' : 'false'; |
|
820 | - $isStrictAboutOutputDuringTests = $result->isStrictAboutOutputDuringTests() ? 'true' : 'false'; |
|
821 | - $enforcesTimeLimit = $result->enforcesTimeLimit() ? 'true' : 'false'; |
|
822 | - $isStrictAboutTodoAnnotatedTests = $result->isStrictAboutTodoAnnotatedTests() ? 'true' : 'false'; |
|
823 | - $isStrictAboutResourceUsageDuringSmallTests = $result->isStrictAboutResourceUsageDuringSmallTests() ? 'true' : 'false'; |
|
824 | - |
|
825 | - if (\defined('PHPUNIT_COMPOSER_INSTALL')) { |
|
826 | - $composerAutoload = \var_export(PHPUNIT_COMPOSER_INSTALL, true); |
|
827 | - } else { |
|
828 | - $composerAutoload = '\'\''; |
|
829 | - } |
|
830 | - |
|
831 | - if (\defined('__PHPUNIT_PHAR__')) { |
|
832 | - $phar = \var_export(__PHPUNIT_PHAR__, true); |
|
833 | - } else { |
|
834 | - $phar = '\'\''; |
|
835 | - } |
|
836 | - |
|
837 | - if ($result->getCodeCoverage()) { |
|
838 | - $codeCoverageFilter = $result->getCodeCoverage()->filter(); |
|
839 | - } else { |
|
840 | - $codeCoverageFilter = null; |
|
841 | - } |
|
842 | - |
|
843 | - $data = \var_export(\serialize($this->data), true); |
|
844 | - $dataName = \var_export($this->dataName, true); |
|
845 | - $dependencyInput = \var_export(\serialize($this->dependencyInput), true); |
|
846 | - $includePath = \var_export(\get_include_path(), true); |
|
847 | - $codeCoverageFilter = \var_export(\serialize($codeCoverageFilter), true); |
|
848 | - // must do these fixes because TestCaseMethod.tpl has unserialize('{data}') in it, and we can't break BC |
|
849 | - // the lines above used to use addcslashes() rather than var_export(), which breaks null byte escape sequences |
|
850 | - $data = "'." . $data . ".'"; |
|
851 | - $dataName = "'.(" . $dataName . ").'"; |
|
852 | - $dependencyInput = "'." . $dependencyInput . ".'"; |
|
853 | - $includePath = "'." . $includePath . ".'"; |
|
854 | - $codeCoverageFilter = "'." . $codeCoverageFilter . ".'"; |
|
855 | - |
|
856 | - $configurationFilePath = $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] ?? ''; |
|
857 | - |
|
858 | - $var = [ |
|
859 | - 'composerAutoload' => $composerAutoload, |
|
860 | - 'phar' => $phar, |
|
861 | - 'filename' => $class->getFileName(), |
|
862 | - 'className' => $class->getName(), |
|
863 | - 'collectCodeCoverageInformation' => $coverage, |
|
864 | - 'data' => $data, |
|
865 | - 'dataName' => $dataName, |
|
866 | - 'dependencyInput' => $dependencyInput, |
|
867 | - 'constants' => $constants, |
|
868 | - 'globals' => $globals, |
|
869 | - 'include_path' => $includePath, |
|
870 | - 'included_files' => $includedFiles, |
|
871 | - 'iniSettings' => $iniSettings, |
|
872 | - 'isStrictAboutTestsThatDoNotTestAnything' => $isStrictAboutTestsThatDoNotTestAnything, |
|
873 | - 'isStrictAboutOutputDuringTests' => $isStrictAboutOutputDuringTests, |
|
874 | - 'enforcesTimeLimit' => $enforcesTimeLimit, |
|
875 | - 'isStrictAboutTodoAnnotatedTests' => $isStrictAboutTodoAnnotatedTests, |
|
876 | - 'isStrictAboutResourceUsageDuringSmallTests' => $isStrictAboutResourceUsageDuringSmallTests, |
|
877 | - 'codeCoverageFilter' => $codeCoverageFilter, |
|
878 | - 'configurationFilePath' => $configurationFilePath |
|
879 | - ]; |
|
880 | - |
|
881 | - if (!$runEntireClass) { |
|
882 | - $var['methodName'] = $this->name; |
|
883 | - } |
|
884 | - |
|
885 | - $template->setVar( |
|
886 | - $var |
|
887 | - ); |
|
888 | - |
|
889 | - $this->prepareTemplate($template); |
|
890 | - |
|
891 | - $php = AbstractPhpProcess::factory(); |
|
892 | - $php->runTestJob($template->render(), $this, $result); |
|
893 | - } else { |
|
894 | - $result->run($this); |
|
895 | - } |
|
896 | - |
|
897 | - if (isset($oldErrorHandlerSetting)) { |
|
898 | - $result->convertErrorsToExceptions($oldErrorHandlerSetting); |
|
899 | - } |
|
900 | - |
|
901 | - $this->result = null; |
|
902 | - |
|
903 | - return $result; |
|
904 | - } |
|
905 | - |
|
906 | - /** |
|
907 | - * Runs the bare test sequence. |
|
908 | - */ |
|
909 | - public function runBare() |
|
910 | - { |
|
911 | - $this->numAssertions = 0; |
|
912 | - |
|
913 | - $this->snapshotGlobalState(); |
|
914 | - $this->startOutputBuffering(); |
|
915 | - \clearstatcache(); |
|
916 | - $currentWorkingDirectory = \getcwd(); |
|
917 | - |
|
918 | - $hookMethods = \PHPUnit\Util\Test::getHookMethods(\get_class($this)); |
|
919 | - |
|
920 | - try { |
|
921 | - $hasMetRequirements = false; |
|
922 | - $this->checkRequirements(); |
|
923 | - $hasMetRequirements = true; |
|
924 | - |
|
925 | - if ($this->inIsolation) { |
|
926 | - foreach ($hookMethods['beforeClass'] as $method) { |
|
927 | - $this->$method(); |
|
928 | - } |
|
929 | - } |
|
930 | - |
|
931 | - $this->setExpectedExceptionFromAnnotation(); |
|
932 | - $this->setDoesNotPerformAssertionsFromAnnotation(); |
|
933 | - |
|
934 | - foreach ($hookMethods['before'] as $method) { |
|
935 | - $this->$method(); |
|
936 | - } |
|
937 | - |
|
938 | - $this->assertPreConditions(); |
|
939 | - $this->testResult = $this->runTest(); |
|
940 | - $this->verifyMockObjects(); |
|
941 | - $this->assertPostConditions(); |
|
942 | - |
|
943 | - if (!empty($this->warnings)) { |
|
944 | - throw new Warning( |
|
945 | - \implode( |
|
946 | - "\n", |
|
947 | - \array_unique($this->warnings) |
|
948 | - ) |
|
949 | - ); |
|
950 | - } |
|
951 | - |
|
952 | - $this->status = BaseTestRunner::STATUS_PASSED; |
|
953 | - } catch (IncompleteTest $e) { |
|
954 | - $this->status = BaseTestRunner::STATUS_INCOMPLETE; |
|
955 | - $this->statusMessage = $e->getMessage(); |
|
956 | - } catch (SkippedTest $e) { |
|
957 | - $this->status = BaseTestRunner::STATUS_SKIPPED; |
|
958 | - $this->statusMessage = $e->getMessage(); |
|
959 | - } catch (Warning $e) { |
|
960 | - $this->status = BaseTestRunner::STATUS_WARNING; |
|
961 | - $this->statusMessage = $e->getMessage(); |
|
962 | - } catch (AssertionFailedError $e) { |
|
963 | - $this->status = BaseTestRunner::STATUS_FAILURE; |
|
964 | - $this->statusMessage = $e->getMessage(); |
|
965 | - } catch (PredictionException $e) { |
|
966 | - $this->status = BaseTestRunner::STATUS_FAILURE; |
|
967 | - $this->statusMessage = $e->getMessage(); |
|
968 | - } catch (Throwable $_e) { |
|
969 | - $e = $_e; |
|
970 | - } |
|
971 | - |
|
972 | - if (isset($_e)) { |
|
973 | - $this->status = BaseTestRunner::STATUS_ERROR; |
|
974 | - $this->statusMessage = $_e->getMessage(); |
|
975 | - } |
|
976 | - |
|
977 | - // Clean up the mock objects. |
|
978 | - $this->mockObjects = []; |
|
979 | - $this->prophet = null; |
|
980 | - |
|
981 | - // Tear down the fixture. An exception raised in tearDown() will be |
|
982 | - // caught and passed on when no exception was raised before. |
|
983 | - try { |
|
984 | - if ($hasMetRequirements) { |
|
985 | - foreach ($hookMethods['after'] as $method) { |
|
986 | - $this->$method(); |
|
987 | - } |
|
988 | - |
|
989 | - if ($this->inIsolation) { |
|
990 | - foreach ($hookMethods['afterClass'] as $method) { |
|
991 | - $this->$method(); |
|
992 | - } |
|
993 | - } |
|
994 | - } |
|
995 | - } catch (Throwable $_e) { |
|
996 | - if (!isset($e)) { |
|
997 | - $e = $_e; |
|
998 | - } |
|
999 | - } |
|
1000 | - |
|
1001 | - try { |
|
1002 | - $this->stopOutputBuffering(); |
|
1003 | - } catch (RiskyTestError $_e) { |
|
1004 | - if (!isset($e)) { |
|
1005 | - $e = $_e; |
|
1006 | - } |
|
1007 | - } |
|
1008 | - |
|
1009 | - \clearstatcache(); |
|
1010 | - |
|
1011 | - if ($currentWorkingDirectory != \getcwd()) { |
|
1012 | - \chdir($currentWorkingDirectory); |
|
1013 | - } |
|
1014 | - |
|
1015 | - $this->restoreGlobalState(); |
|
1016 | - $this->unregisterCustomComparators(); |
|
1017 | - $this->cleanupIniSettings(); |
|
1018 | - $this->cleanupLocaleSettings(); |
|
1019 | - |
|
1020 | - // Perform assertion on output. |
|
1021 | - if (!isset($e)) { |
|
1022 | - try { |
|
1023 | - if ($this->outputExpectedRegex !== null) { |
|
1024 | - $this->assertRegExp($this->outputExpectedRegex, $this->output); |
|
1025 | - } elseif ($this->outputExpectedString !== null) { |
|
1026 | - $this->assertEquals($this->outputExpectedString, $this->output); |
|
1027 | - } |
|
1028 | - } catch (Throwable $_e) { |
|
1029 | - $e = $_e; |
|
1030 | - } |
|
1031 | - } |
|
1032 | - |
|
1033 | - // Workaround for missing "finally". |
|
1034 | - if (isset($e)) { |
|
1035 | - if ($e instanceof PredictionException) { |
|
1036 | - $e = new AssertionFailedError($e->getMessage()); |
|
1037 | - } |
|
1038 | - |
|
1039 | - $this->onNotSuccessfulTest($e); |
|
1040 | - } |
|
1041 | - } |
|
1042 | - |
|
1043 | - /** |
|
1044 | - * Override to run the test and assert its state. |
|
1045 | - * |
|
1046 | - * @return mixed |
|
1047 | - * |
|
1048 | - * @throws Exception|Exception |
|
1049 | - * @throws Exception |
|
1050 | - */ |
|
1051 | - protected function runTest() |
|
1052 | - { |
|
1053 | - if ($this->name === null) { |
|
1054 | - throw new Exception( |
|
1055 | - 'PHPUnit\Framework\TestCase::$name must not be null.' |
|
1056 | - ); |
|
1057 | - } |
|
1058 | - |
|
1059 | - try { |
|
1060 | - $class = new ReflectionClass($this); |
|
1061 | - $method = $class->getMethod($this->name); |
|
1062 | - } catch (ReflectionException $e) { |
|
1063 | - $this->fail($e->getMessage()); |
|
1064 | - } |
|
1065 | - |
|
1066 | - $testArguments = \array_merge($this->data, $this->dependencyInput); |
|
1067 | - |
|
1068 | - $this->registerMockObjectsFromTestArguments($testArguments); |
|
1069 | - |
|
1070 | - try { |
|
1071 | - $testResult = $method->invokeArgs($this, $testArguments); |
|
1072 | - } catch (Throwable $t) { |
|
1073 | - $exception = $t; |
|
1074 | - } |
|
1075 | - |
|
1076 | - if (isset($exception)) { |
|
1077 | - if ($this->checkExceptionExpectations($exception)) { |
|
1078 | - if ($this->expectedException !== null) { |
|
1079 | - $this->assertThat( |
|
1080 | - $exception, |
|
1081 | - new ExceptionConstraint( |
|
1082 | - $this->expectedException |
|
1083 | - ) |
|
1084 | - ); |
|
1085 | - } |
|
1086 | - |
|
1087 | - if ($this->expectedExceptionMessage !== null) { |
|
1088 | - $this->assertThat( |
|
1089 | - $exception, |
|
1090 | - new ExceptionMessage( |
|
1091 | - $this->expectedExceptionMessage |
|
1092 | - ) |
|
1093 | - ); |
|
1094 | - } |
|
1095 | - |
|
1096 | - if ($this->expectedExceptionMessageRegExp !== null) { |
|
1097 | - $this->assertThat( |
|
1098 | - $exception, |
|
1099 | - new ExceptionMessageRegularExpression( |
|
1100 | - $this->expectedExceptionMessageRegExp |
|
1101 | - ) |
|
1102 | - ); |
|
1103 | - } |
|
1104 | - |
|
1105 | - if ($this->expectedExceptionCode !== null) { |
|
1106 | - $this->assertThat( |
|
1107 | - $exception, |
|
1108 | - new ExceptionCode( |
|
1109 | - $this->expectedExceptionCode |
|
1110 | - ) |
|
1111 | - ); |
|
1112 | - } |
|
1113 | - |
|
1114 | - return; |
|
1115 | - } |
|
1116 | - |
|
1117 | - throw $exception; |
|
1118 | - } |
|
1119 | - |
|
1120 | - if ($this->expectedException !== null) { |
|
1121 | - $this->assertThat( |
|
1122 | - null, |
|
1123 | - new ExceptionConstraint( |
|
1124 | - $this->expectedException |
|
1125 | - ) |
|
1126 | - ); |
|
1127 | - } elseif ($this->expectedExceptionMessage !== null) { |
|
1128 | - $this->numAssertions++; |
|
1129 | - |
|
1130 | - throw new AssertionFailedError( |
|
1131 | - \sprintf( |
|
1132 | - 'Failed asserting that exception with message "%s" is thrown', |
|
1133 | - $this->expectedExceptionMessage |
|
1134 | - ) |
|
1135 | - ); |
|
1136 | - } elseif ($this->expectedExceptionMessageRegExp !== null) { |
|
1137 | - $this->numAssertions++; |
|
1138 | - |
|
1139 | - throw new AssertionFailedError( |
|
1140 | - \sprintf( |
|
1141 | - 'Failed asserting that exception with message matching "%s" is thrown', |
|
1142 | - $this->expectedExceptionMessageRegExp |
|
1143 | - ) |
|
1144 | - ); |
|
1145 | - } elseif ($this->expectedExceptionCode !== null) { |
|
1146 | - $this->numAssertions++; |
|
1147 | - |
|
1148 | - throw new AssertionFailedError( |
|
1149 | - \sprintf( |
|
1150 | - 'Failed asserting that exception with code "%s" is thrown', |
|
1151 | - $this->expectedExceptionCode |
|
1152 | - ) |
|
1153 | - ); |
|
1154 | - } |
|
1155 | - |
|
1156 | - return $testResult; |
|
1157 | - } |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * Verifies the mock object expectations. |
|
1161 | - */ |
|
1162 | - protected function verifyMockObjects() |
|
1163 | - { |
|
1164 | - foreach ($this->mockObjects as $mockObject) { |
|
1165 | - if ($mockObject->__phpunit_hasMatchers()) { |
|
1166 | - $this->numAssertions++; |
|
1167 | - } |
|
1168 | - |
|
1169 | - $mockObject->__phpunit_verify( |
|
1170 | - $this->shouldInvocationMockerBeReset($mockObject) |
|
1171 | - ); |
|
1172 | - } |
|
1173 | - |
|
1174 | - if ($this->prophet !== null) { |
|
1175 | - try { |
|
1176 | - $this->prophet->checkPredictions(); |
|
1177 | - } catch (Throwable $t) { |
|
1178 | - /* Intentionally left empty */ |
|
1179 | - } |
|
1180 | - |
|
1181 | - foreach ($this->prophet->getProphecies() as $objectProphecy) { |
|
1182 | - foreach ($objectProphecy->getMethodProphecies() as $methodProphecies) { |
|
1183 | - foreach ($methodProphecies as $methodProphecy) { |
|
1184 | - $this->numAssertions += \count($methodProphecy->getCheckedPredictions()); |
|
1185 | - } |
|
1186 | - } |
|
1187 | - } |
|
1188 | - |
|
1189 | - if (isset($t)) { |
|
1190 | - throw $t; |
|
1191 | - } |
|
1192 | - } |
|
1193 | - } |
|
1194 | - |
|
1195 | - /** |
|
1196 | - * Sets the name of a TestCase. |
|
1197 | - * |
|
1198 | - * @param string |
|
1199 | - */ |
|
1200 | - public function setName($name) |
|
1201 | - { |
|
1202 | - $this->name = $name; |
|
1203 | - } |
|
1204 | - |
|
1205 | - /** |
|
1206 | - * Sets the dependencies of a TestCase. |
|
1207 | - * |
|
1208 | - * @param string[] $dependencies |
|
1209 | - */ |
|
1210 | - public function setDependencies(array $dependencies) |
|
1211 | - { |
|
1212 | - $this->dependencies = $dependencies; |
|
1213 | - } |
|
1214 | - |
|
1215 | - /** |
|
1216 | - * Returns true if the tests has dependencies |
|
1217 | - * |
|
1218 | - * @return bool |
|
1219 | - */ |
|
1220 | - public function hasDependencies() |
|
1221 | - { |
|
1222 | - return \count($this->dependencies) > 0; |
|
1223 | - } |
|
1224 | - |
|
1225 | - /** |
|
1226 | - * Sets |
|
1227 | - * |
|
1228 | - * @param array $dependencyInput |
|
1229 | - */ |
|
1230 | - public function setDependencyInput(array $dependencyInput) |
|
1231 | - { |
|
1232 | - $this->dependencyInput = $dependencyInput; |
|
1233 | - } |
|
1234 | - |
|
1235 | - /** |
|
1236 | - * @param bool $beStrictAboutChangesToGlobalState |
|
1237 | - */ |
|
1238 | - public function setBeStrictAboutChangesToGlobalState($beStrictAboutChangesToGlobalState) |
|
1239 | - { |
|
1240 | - $this->beStrictAboutChangesToGlobalState = $beStrictAboutChangesToGlobalState; |
|
1241 | - } |
|
1242 | - |
|
1243 | - /** |
|
1244 | - * Calling this method in setUp() has no effect! |
|
1245 | - * |
|
1246 | - * @param bool $backupGlobals |
|
1247 | - */ |
|
1248 | - public function setBackupGlobals($backupGlobals) |
|
1249 | - { |
|
1250 | - if (null === $this->backupGlobals && \is_bool($backupGlobals)) { |
|
1251 | - $this->backupGlobals = $backupGlobals; |
|
1252 | - } |
|
1253 | - } |
|
1254 | - |
|
1255 | - /** |
|
1256 | - * Calling this method in setUp() has no effect! |
|
1257 | - * |
|
1258 | - * @param bool $backupStaticAttributes |
|
1259 | - */ |
|
1260 | - public function setBackupStaticAttributes($backupStaticAttributes) |
|
1261 | - { |
|
1262 | - if (null === $this->backupStaticAttributes && |
|
1263 | - \is_bool($backupStaticAttributes)) { |
|
1264 | - $this->backupStaticAttributes = $backupStaticAttributes; |
|
1265 | - } |
|
1266 | - } |
|
1267 | - |
|
1268 | - /** |
|
1269 | - * @param bool $runTestInSeparateProcess |
|
1270 | - * |
|
1271 | - * @throws Exception |
|
1272 | - */ |
|
1273 | - public function setRunTestInSeparateProcess($runTestInSeparateProcess) |
|
1274 | - { |
|
1275 | - if (\is_bool($runTestInSeparateProcess)) { |
|
1276 | - if ($this->runTestInSeparateProcess === null) { |
|
1277 | - $this->runTestInSeparateProcess = $runTestInSeparateProcess; |
|
1278 | - } |
|
1279 | - } else { |
|
1280 | - throw InvalidArgumentHelper::factory(1, 'boolean'); |
|
1281 | - } |
|
1282 | - } |
|
1283 | - |
|
1284 | - /** |
|
1285 | - * @param bool $runClassInSeparateProcess |
|
1286 | - * |
|
1287 | - * @throws Exception |
|
1288 | - */ |
|
1289 | - public function setRunClassInSeparateProcess($runClassInSeparateProcess) |
|
1290 | - { |
|
1291 | - if (\is_bool($runClassInSeparateProcess)) { |
|
1292 | - if ($this->runClassInSeparateProcess === null) { |
|
1293 | - $this->runClassInSeparateProcess = $runClassInSeparateProcess; |
|
1294 | - } |
|
1295 | - } else { |
|
1296 | - throw InvalidArgumentHelper::factory(1, 'boolean'); |
|
1297 | - } |
|
1298 | - } |
|
1299 | - |
|
1300 | - /** |
|
1301 | - * @param bool $preserveGlobalState |
|
1302 | - * |
|
1303 | - * @throws Exception |
|
1304 | - */ |
|
1305 | - public function setPreserveGlobalState($preserveGlobalState) |
|
1306 | - { |
|
1307 | - if (\is_bool($preserveGlobalState)) { |
|
1308 | - $this->preserveGlobalState = $preserveGlobalState; |
|
1309 | - } else { |
|
1310 | - throw InvalidArgumentHelper::factory(1, 'boolean'); |
|
1311 | - } |
|
1312 | - } |
|
1313 | - |
|
1314 | - /** |
|
1315 | - * @param bool $inIsolation |
|
1316 | - * |
|
1317 | - * @throws Exception |
|
1318 | - */ |
|
1319 | - public function setInIsolation($inIsolation) |
|
1320 | - { |
|
1321 | - if (\is_bool($inIsolation)) { |
|
1322 | - $this->inIsolation = $inIsolation; |
|
1323 | - } else { |
|
1324 | - throw InvalidArgumentHelper::factory(1, 'boolean'); |
|
1325 | - } |
|
1326 | - } |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * @return bool |
|
1330 | - */ |
|
1331 | - public function isInIsolation() |
|
1332 | - { |
|
1333 | - return $this->inIsolation; |
|
1334 | - } |
|
1335 | - |
|
1336 | - /** |
|
1337 | - * @return mixed |
|
1338 | - */ |
|
1339 | - public function getResult() |
|
1340 | - { |
|
1341 | - return $this->testResult; |
|
1342 | - } |
|
1343 | - |
|
1344 | - /** |
|
1345 | - * @param mixed $result |
|
1346 | - */ |
|
1347 | - public function setResult($result) |
|
1348 | - { |
|
1349 | - $this->testResult = $result; |
|
1350 | - } |
|
1351 | - |
|
1352 | - /** |
|
1353 | - * @param callable $callback |
|
1354 | - * |
|
1355 | - * @throws Exception |
|
1356 | - */ |
|
1357 | - public function setOutputCallback($callback) |
|
1358 | - { |
|
1359 | - if (!\is_callable($callback)) { |
|
1360 | - throw InvalidArgumentHelper::factory(1, 'callback'); |
|
1361 | - } |
|
1362 | - |
|
1363 | - $this->outputCallback = $callback; |
|
1364 | - } |
|
1365 | - |
|
1366 | - /** |
|
1367 | - * @return TestResult |
|
1368 | - */ |
|
1369 | - public function getTestResultObject() |
|
1370 | - { |
|
1371 | - return $this->result; |
|
1372 | - } |
|
1373 | - |
|
1374 | - /** |
|
1375 | - * @param TestResult $result |
|
1376 | - */ |
|
1377 | - public function setTestResultObject(TestResult $result) |
|
1378 | - { |
|
1379 | - $this->result = $result; |
|
1380 | - } |
|
1381 | - |
|
1382 | - /** |
|
1383 | - * @param PHPUnit_Framework_MockObject_MockObject $mockObject |
|
1384 | - */ |
|
1385 | - public function registerMockObject(PHPUnit_Framework_MockObject_MockObject $mockObject) |
|
1386 | - { |
|
1387 | - $this->mockObjects[] = $mockObject; |
|
1388 | - } |
|
1389 | - |
|
1390 | - /** |
|
1391 | - * This method is a wrapper for the ini_set() function that automatically |
|
1392 | - * resets the modified php.ini setting to its original value after the |
|
1393 | - * test is run. |
|
1394 | - * |
|
1395 | - * @param string $varName |
|
1396 | - * @param string $newValue |
|
1397 | - * |
|
1398 | - * @throws Exception |
|
1399 | - */ |
|
1400 | - protected function iniSet($varName, $newValue) |
|
1401 | - { |
|
1402 | - if (!\is_string($varName)) { |
|
1403 | - throw InvalidArgumentHelper::factory(1, 'string'); |
|
1404 | - } |
|
1405 | - |
|
1406 | - $currentValue = \ini_set($varName, $newValue); |
|
1407 | - |
|
1408 | - if ($currentValue !== false) { |
|
1409 | - $this->iniSettings[$varName] = $currentValue; |
|
1410 | - } else { |
|
1411 | - throw new Exception( |
|
1412 | - \sprintf( |
|
1413 | - 'INI setting "%s" could not be set to "%s".', |
|
1414 | - $varName, |
|
1415 | - $newValue |
|
1416 | - ) |
|
1417 | - ); |
|
1418 | - } |
|
1419 | - } |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * This method is a wrapper for the setlocale() function that automatically |
|
1423 | - * resets the locale to its original value after the test is run. |
|
1424 | - * |
|
1425 | - * @param int $category |
|
1426 | - * @param string $locale |
|
1427 | - * |
|
1428 | - * @throws Exception |
|
1429 | - */ |
|
1430 | - protected function setLocale() |
|
1431 | - { |
|
1432 | - $args = \func_get_args(); |
|
1433 | - |
|
1434 | - if (\count($args) < 2) { |
|
1435 | - throw new Exception; |
|
1436 | - } |
|
1437 | - |
|
1438 | - list($category, $locale) = $args; |
|
1439 | - |
|
1440 | - $categories = [ |
|
1441 | - LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME |
|
1442 | - ]; |
|
1443 | - |
|
1444 | - if (\defined('LC_MESSAGES')) { |
|
1445 | - $categories[] = LC_MESSAGES; |
|
1446 | - } |
|
1447 | - |
|
1448 | - if (!\in_array($category, $categories)) { |
|
1449 | - throw new Exception; |
|
1450 | - } |
|
1451 | - |
|
1452 | - if (!\is_array($locale) && !\is_string($locale)) { |
|
1453 | - throw new Exception; |
|
1454 | - } |
|
1455 | - |
|
1456 | - $this->locale[$category] = \setlocale($category, 0); |
|
1457 | - |
|
1458 | - $result = \call_user_func_array('setlocale', $args); |
|
1459 | - |
|
1460 | - if ($result === false) { |
|
1461 | - throw new Exception( |
|
1462 | - 'The locale functionality is not implemented on your platform, ' . |
|
1463 | - 'the specified locale does not exist or the category name is ' . |
|
1464 | - 'invalid.' |
|
1465 | - ); |
|
1466 | - } |
|
1467 | - } |
|
1468 | - |
|
1469 | - /** |
|
1470 | - * Returns a builder object to create mock objects using a fluent interface. |
|
1471 | - * |
|
1472 | - * @param string|string[] $className |
|
1473 | - * |
|
1474 | - * @return PHPUnit_Framework_MockObject_MockBuilder |
|
1475 | - */ |
|
1476 | - public function getMockBuilder($className) |
|
1477 | - { |
|
1478 | - return new PHPUnit_Framework_MockObject_MockBuilder($this, $className); |
|
1479 | - } |
|
1480 | - |
|
1481 | - /** |
|
1482 | - * Returns a test double for the specified class. |
|
1483 | - * |
|
1484 | - * @param string $originalClassName |
|
1485 | - * |
|
1486 | - * @return PHPUnit_Framework_MockObject_MockObject |
|
1487 | - * |
|
1488 | - * @throws Exception |
|
1489 | - */ |
|
1490 | - protected function createMock($originalClassName) |
|
1491 | - { |
|
1492 | - return $this->getMockBuilder($originalClassName) |
|
1493 | - ->disableOriginalConstructor() |
|
1494 | - ->disableOriginalClone() |
|
1495 | - ->disableArgumentCloning() |
|
1496 | - ->disallowMockingUnknownTypes() |
|
1497 | - ->getMock(); |
|
1498 | - } |
|
1499 | - |
|
1500 | - /** |
|
1501 | - * Returns a configured test double for the specified class. |
|
1502 | - * |
|
1503 | - * @param string $originalClassName |
|
1504 | - * @param array $configuration |
|
1505 | - * |
|
1506 | - * @return PHPUnit_Framework_MockObject_MockObject |
|
1507 | - * |
|
1508 | - * @throws Exception |
|
1509 | - */ |
|
1510 | - protected function createConfiguredMock($originalClassName, array $configuration) |
|
1511 | - { |
|
1512 | - $o = $this->createMock($originalClassName); |
|
1513 | - |
|
1514 | - foreach ($configuration as $method => $return) { |
|
1515 | - $o->method($method)->willReturn($return); |
|
1516 | - } |
|
1517 | - |
|
1518 | - return $o; |
|
1519 | - } |
|
1520 | - |
|
1521 | - /** |
|
1522 | - * Returns a partial test double for the specified class. |
|
1523 | - * |
|
1524 | - * @param string $originalClassName |
|
1525 | - * @param string[] $methods |
|
1526 | - * |
|
1527 | - * @return PHPUnit_Framework_MockObject_MockObject |
|
1528 | - * |
|
1529 | - * @throws Exception |
|
1530 | - */ |
|
1531 | - protected function createPartialMock($originalClassName, array $methods) |
|
1532 | - { |
|
1533 | - return $this->getMockBuilder($originalClassName) |
|
1534 | - ->disableOriginalConstructor() |
|
1535 | - ->disableOriginalClone() |
|
1536 | - ->disableArgumentCloning() |
|
1537 | - ->disallowMockingUnknownTypes() |
|
1538 | - ->setMethods(empty($methods) ? null : $methods) |
|
1539 | - ->getMock(); |
|
1540 | - } |
|
1541 | - |
|
1542 | - /** |
|
1543 | - * Returns a test proxy for the specified class. |
|
1544 | - * |
|
1545 | - * @param string $originalClassName |
|
1546 | - * @param array $constructorArguments |
|
1547 | - * |
|
1548 | - * @return PHPUnit_Framework_MockObject_MockObject |
|
1549 | - * |
|
1550 | - * @throws Exception |
|
1551 | - */ |
|
1552 | - protected function createTestProxy($originalClassName, array $constructorArguments = []) |
|
1553 | - { |
|
1554 | - return $this->getMockBuilder($originalClassName) |
|
1555 | - ->setConstructorArgs($constructorArguments) |
|
1556 | - ->enableProxyingToOriginalMethods() |
|
1557 | - ->getMock(); |
|
1558 | - } |
|
1559 | - |
|
1560 | - /** |
|
1561 | - * Mocks the specified class and returns the name of the mocked class. |
|
1562 | - * |
|
1563 | - * @param string $originalClassName |
|
1564 | - * @param array $methods |
|
1565 | - * @param array $arguments |
|
1566 | - * @param string $mockClassName |
|
1567 | - * @param bool $callOriginalConstructor |
|
1568 | - * @param bool $callOriginalClone |
|
1569 | - * @param bool $callAutoload |
|
1570 | - * @param bool $cloneArguments |
|
1571 | - * |
|
1572 | - * @return string |
|
1573 | - * |
|
1574 | - * @throws Exception |
|
1575 | - */ |
|
1576 | - protected function getMockClass($originalClassName, $methods = [], array $arguments = [], $mockClassName = '', $callOriginalConstructor = false, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false) |
|
1577 | - { |
|
1578 | - $mock = $this->getMockObjectGenerator()->getMock( |
|
1579 | - $originalClassName, |
|
1580 | - $methods, |
|
1581 | - $arguments, |
|
1582 | - $mockClassName, |
|
1583 | - $callOriginalConstructor, |
|
1584 | - $callOriginalClone, |
|
1585 | - $callAutoload, |
|
1586 | - $cloneArguments |
|
1587 | - ); |
|
1588 | - |
|
1589 | - return \get_class($mock); |
|
1590 | - } |
|
1591 | - |
|
1592 | - /** |
|
1593 | - * Returns a mock object for the specified abstract class with all abstract |
|
1594 | - * methods of the class mocked. Concrete methods are not mocked by default. |
|
1595 | - * To mock concrete methods, use the 7th parameter ($mockedMethods). |
|
1596 | - * |
|
1597 | - * @param string $originalClassName |
|
1598 | - * @param array $arguments |
|
1599 | - * @param string $mockClassName |
|
1600 | - * @param bool $callOriginalConstructor |
|
1601 | - * @param bool $callOriginalClone |
|
1602 | - * @param bool $callAutoload |
|
1603 | - * @param array $mockedMethods |
|
1604 | - * @param bool $cloneArguments |
|
1605 | - * |
|
1606 | - * @return PHPUnit_Framework_MockObject_MockObject |
|
1607 | - * |
|
1608 | - * @throws Exception |
|
1609 | - */ |
|
1610 | - protected function getMockForAbstractClass($originalClassName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = false) |
|
1611 | - { |
|
1612 | - $mockObject = $this->getMockObjectGenerator()->getMockForAbstractClass( |
|
1613 | - $originalClassName, |
|
1614 | - $arguments, |
|
1615 | - $mockClassName, |
|
1616 | - $callOriginalConstructor, |
|
1617 | - $callOriginalClone, |
|
1618 | - $callAutoload, |
|
1619 | - $mockedMethods, |
|
1620 | - $cloneArguments |
|
1621 | - ); |
|
1622 | - |
|
1623 | - $this->registerMockObject($mockObject); |
|
1624 | - |
|
1625 | - return $mockObject; |
|
1626 | - } |
|
1627 | - |
|
1628 | - /** |
|
1629 | - * Returns a mock object based on the given WSDL file. |
|
1630 | - * |
|
1631 | - * @param string $wsdlFile |
|
1632 | - * @param string $originalClassName |
|
1633 | - * @param string $mockClassName |
|
1634 | - * @param array $methods |
|
1635 | - * @param bool $callOriginalConstructor |
|
1636 | - * @param array $options An array of options passed to SOAPClient::_construct |
|
1637 | - * |
|
1638 | - * @return PHPUnit_Framework_MockObject_MockObject |
|
1639 | - */ |
|
1640 | - protected function getMockFromWsdl($wsdlFile, $originalClassName = '', $mockClassName = '', array $methods = [], $callOriginalConstructor = true, array $options = []) |
|
1641 | - { |
|
1642 | - if ($originalClassName === '') { |
|
1643 | - $originalClassName = \pathinfo(\basename(\parse_url($wsdlFile)['path']), PATHINFO_FILENAME); |
|
1644 | - } |
|
1645 | - |
|
1646 | - if (!\class_exists($originalClassName)) { |
|
1647 | - eval( |
|
1648 | - $this->getMockObjectGenerator()->generateClassFromWsdl( |
|
1649 | - $wsdlFile, |
|
1650 | - $originalClassName, |
|
1651 | - $methods, |
|
1652 | - $options |
|
1653 | - ) |
|
1654 | - ); |
|
1655 | - } |
|
1656 | - |
|
1657 | - $mockObject = $this->getMockObjectGenerator()->getMock( |
|
1658 | - $originalClassName, |
|
1659 | - $methods, |
|
1660 | - ['', $options], |
|
1661 | - $mockClassName, |
|
1662 | - $callOriginalConstructor, |
|
1663 | - false, |
|
1664 | - false |
|
1665 | - ); |
|
1666 | - |
|
1667 | - $this->registerMockObject($mockObject); |
|
1668 | - |
|
1669 | - return $mockObject; |
|
1670 | - } |
|
1671 | - |
|
1672 | - /** |
|
1673 | - * Returns a mock object for the specified trait with all abstract methods |
|
1674 | - * of the trait mocked. Concrete methods to mock can be specified with the |
|
1675 | - * `$mockedMethods` parameter. |
|
1676 | - * |
|
1677 | - * @param string $traitName |
|
1678 | - * @param array $arguments |
|
1679 | - * @param string $mockClassName |
|
1680 | - * @param bool $callOriginalConstructor |
|
1681 | - * @param bool $callOriginalClone |
|
1682 | - * @param bool $callAutoload |
|
1683 | - * @param array $mockedMethods |
|
1684 | - * @param bool $cloneArguments |
|
1685 | - * |
|
1686 | - * @return PHPUnit_Framework_MockObject_MockObject |
|
1687 | - * |
|
1688 | - * @throws Exception |
|
1689 | - */ |
|
1690 | - protected function getMockForTrait($traitName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = false) |
|
1691 | - { |
|
1692 | - $mockObject = $this->getMockObjectGenerator()->getMockForTrait( |
|
1693 | - $traitName, |
|
1694 | - $arguments, |
|
1695 | - $mockClassName, |
|
1696 | - $callOriginalConstructor, |
|
1697 | - $callOriginalClone, |
|
1698 | - $callAutoload, |
|
1699 | - $mockedMethods, |
|
1700 | - $cloneArguments |
|
1701 | - ); |
|
1702 | - |
|
1703 | - $this->registerMockObject($mockObject); |
|
1704 | - |
|
1705 | - return $mockObject; |
|
1706 | - } |
|
1707 | - |
|
1708 | - /** |
|
1709 | - * Returns an object for the specified trait. |
|
1710 | - * |
|
1711 | - * @param string $traitName |
|
1712 | - * @param array $arguments |
|
1713 | - * @param string $traitClassName |
|
1714 | - * @param bool $callOriginalConstructor |
|
1715 | - * @param bool $callOriginalClone |
|
1716 | - * @param bool $callAutoload |
|
1717 | - * |
|
1718 | - * @return object |
|
1719 | - * |
|
1720 | - * @throws Exception |
|
1721 | - */ |
|
1722 | - protected function getObjectForTrait($traitName, array $arguments = [], $traitClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true) |
|
1723 | - { |
|
1724 | - return $this->getMockObjectGenerator()->getObjectForTrait( |
|
1725 | - $traitName, |
|
1726 | - $arguments, |
|
1727 | - $traitClassName, |
|
1728 | - $callOriginalConstructor, |
|
1729 | - $callOriginalClone, |
|
1730 | - $callAutoload |
|
1731 | - ); |
|
1732 | - } |
|
1733 | - |
|
1734 | - /** |
|
1735 | - * @param string|null $classOrInterface |
|
1736 | - * |
|
1737 | - * @return \Prophecy\Prophecy\ObjectProphecy |
|
1738 | - * |
|
1739 | - * @throws \LogicException |
|
1740 | - */ |
|
1741 | - protected function prophesize($classOrInterface = null) |
|
1742 | - { |
|
1743 | - return $this->getProphet()->prophesize($classOrInterface); |
|
1744 | - } |
|
1745 | - |
|
1746 | - /** |
|
1747 | - * Adds a value to the assertion counter. |
|
1748 | - * |
|
1749 | - * @param int $count |
|
1750 | - */ |
|
1751 | - public function addToAssertionCount($count) |
|
1752 | - { |
|
1753 | - $this->numAssertions += $count; |
|
1754 | - } |
|
1755 | - |
|
1756 | - /** |
|
1757 | - * Returns the number of assertions performed by this test. |
|
1758 | - * |
|
1759 | - * @return int |
|
1760 | - */ |
|
1761 | - public function getNumAssertions() |
|
1762 | - { |
|
1763 | - return $this->numAssertions; |
|
1764 | - } |
|
1765 | - |
|
1766 | - /** |
|
1767 | - * Returns a matcher that matches when the method is executed |
|
1768 | - * zero or more times. |
|
1769 | - * |
|
1770 | - * @return PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount |
|
1771 | - */ |
|
1772 | - public static function any() |
|
1773 | - { |
|
1774 | - return new PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount; |
|
1775 | - } |
|
1776 | - |
|
1777 | - /** |
|
1778 | - * Returns a matcher that matches when the method is never executed. |
|
1779 | - * |
|
1780 | - * @return PHPUnit_Framework_MockObject_Matcher_InvokedCount |
|
1781 | - */ |
|
1782 | - public static function never() |
|
1783 | - { |
|
1784 | - return new PHPUnit_Framework_MockObject_Matcher_InvokedCount(0); |
|
1785 | - } |
|
1786 | - |
|
1787 | - /** |
|
1788 | - * Returns a matcher that matches when the method is executed |
|
1789 | - * at least N times. |
|
1790 | - * |
|
1791 | - * @param int $requiredInvocations |
|
1792 | - * |
|
1793 | - * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastCount |
|
1794 | - */ |
|
1795 | - public static function atLeast($requiredInvocations) |
|
1796 | - { |
|
1797 | - return new PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastCount( |
|
1798 | - $requiredInvocations |
|
1799 | - ); |
|
1800 | - } |
|
1801 | - |
|
1802 | - /** |
|
1803 | - * Returns a matcher that matches when the method is executed at least once. |
|
1804 | - * |
|
1805 | - * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce |
|
1806 | - */ |
|
1807 | - public static function atLeastOnce() |
|
1808 | - { |
|
1809 | - return new PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce; |
|
1810 | - } |
|
1811 | - |
|
1812 | - /** |
|
1813 | - * Returns a matcher that matches when the method is executed exactly once. |
|
1814 | - * |
|
1815 | - * @return PHPUnit_Framework_MockObject_Matcher_InvokedCount |
|
1816 | - */ |
|
1817 | - public static function once() |
|
1818 | - { |
|
1819 | - return new PHPUnit_Framework_MockObject_Matcher_InvokedCount(1); |
|
1820 | - } |
|
1821 | - |
|
1822 | - /** |
|
1823 | - * Returns a matcher that matches when the method is executed |
|
1824 | - * exactly $count times. |
|
1825 | - * |
|
1826 | - * @param int $count |
|
1827 | - * |
|
1828 | - * @return PHPUnit_Framework_MockObject_Matcher_InvokedCount |
|
1829 | - */ |
|
1830 | - public static function exactly($count) |
|
1831 | - { |
|
1832 | - return new PHPUnit_Framework_MockObject_Matcher_InvokedCount($count); |
|
1833 | - } |
|
1834 | - |
|
1835 | - /** |
|
1836 | - * Returns a matcher that matches when the method is executed |
|
1837 | - * at most N times. |
|
1838 | - * |
|
1839 | - * @param int $allowedInvocations |
|
1840 | - * |
|
1841 | - * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtMostCount |
|
1842 | - */ |
|
1843 | - public static function atMost($allowedInvocations) |
|
1844 | - { |
|
1845 | - return new PHPUnit_Framework_MockObject_Matcher_InvokedAtMostCount( |
|
1846 | - $allowedInvocations |
|
1847 | - ); |
|
1848 | - } |
|
1849 | - |
|
1850 | - /** |
|
1851 | - * Returns a matcher that matches when the method is executed |
|
1852 | - * at the given index. |
|
1853 | - * |
|
1854 | - * @param int $index |
|
1855 | - * |
|
1856 | - * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex |
|
1857 | - */ |
|
1858 | - public static function at($index) |
|
1859 | - { |
|
1860 | - return new PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex($index); |
|
1861 | - } |
|
1862 | - |
|
1863 | - /** |
|
1864 | - * @param mixed $value |
|
1865 | - * |
|
1866 | - * @return PHPUnit_Framework_MockObject_Stub_Return |
|
1867 | - */ |
|
1868 | - public static function returnValue($value) |
|
1869 | - { |
|
1870 | - return new PHPUnit_Framework_MockObject_Stub_Return($value); |
|
1871 | - } |
|
1872 | - |
|
1873 | - /** |
|
1874 | - * @param array $valueMap |
|
1875 | - * |
|
1876 | - * @return PHPUnit_Framework_MockObject_Stub_ReturnValueMap |
|
1877 | - */ |
|
1878 | - public static function returnValueMap(array $valueMap) |
|
1879 | - { |
|
1880 | - return new PHPUnit_Framework_MockObject_Stub_ReturnValueMap($valueMap); |
|
1881 | - } |
|
1882 | - |
|
1883 | - /** |
|
1884 | - * @param int $argumentIndex |
|
1885 | - * |
|
1886 | - * @return PHPUnit_Framework_MockObject_Stub_ReturnArgument |
|
1887 | - */ |
|
1888 | - public static function returnArgument($argumentIndex) |
|
1889 | - { |
|
1890 | - return new PHPUnit_Framework_MockObject_Stub_ReturnArgument( |
|
1891 | - $argumentIndex |
|
1892 | - ); |
|
1893 | - } |
|
1894 | - |
|
1895 | - /** |
|
1896 | - * @param mixed $callback |
|
1897 | - * |
|
1898 | - * @return PHPUnit_Framework_MockObject_Stub_ReturnCallback |
|
1899 | - */ |
|
1900 | - public static function returnCallback($callback) |
|
1901 | - { |
|
1902 | - return new PHPUnit_Framework_MockObject_Stub_ReturnCallback($callback); |
|
1903 | - } |
|
1904 | - |
|
1905 | - /** |
|
1906 | - * Returns the current object. |
|
1907 | - * |
|
1908 | - * This method is useful when mocking a fluent interface. |
|
1909 | - * |
|
1910 | - * @return PHPUnit_Framework_MockObject_Stub_ReturnSelf |
|
1911 | - */ |
|
1912 | - public static function returnSelf() |
|
1913 | - { |
|
1914 | - return new PHPUnit_Framework_MockObject_Stub_ReturnSelf(); |
|
1915 | - } |
|
1916 | - |
|
1917 | - /** |
|
1918 | - * @param Throwable $exception |
|
1919 | - * |
|
1920 | - * @return PHPUnit_Framework_MockObject_Stub_Exception |
|
1921 | - */ |
|
1922 | - public static function throwException(Throwable $exception) |
|
1923 | - { |
|
1924 | - return new PHPUnit_Framework_MockObject_Stub_Exception($exception); |
|
1925 | - } |
|
1926 | - |
|
1927 | - /** |
|
1928 | - * @param mixed $value , ... |
|
1929 | - * |
|
1930 | - * @return PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls |
|
1931 | - */ |
|
1932 | - public static function onConsecutiveCalls() |
|
1933 | - { |
|
1934 | - $args = \func_get_args(); |
|
1935 | - |
|
1936 | - return new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls($args); |
|
1937 | - } |
|
1938 | - |
|
1939 | - /** |
|
1940 | - * @return bool |
|
1941 | - */ |
|
1942 | - public function usesDataProvider() |
|
1943 | - { |
|
1944 | - return !empty($this->data); |
|
1945 | - } |
|
1946 | - |
|
1947 | - /** |
|
1948 | - * @return string |
|
1949 | - */ |
|
1950 | - public function dataDescription() |
|
1951 | - { |
|
1952 | - return \is_string($this->dataName) ? $this->dataName : ''; |
|
1953 | - } |
|
1954 | - |
|
1955 | - public function registerComparator(Comparator $comparator) |
|
1956 | - { |
|
1957 | - ComparatorFactory::getInstance()->register($comparator); |
|
1958 | - |
|
1959 | - $this->customComparators[] = $comparator; |
|
1960 | - } |
|
1961 | - |
|
1962 | - /** |
|
1963 | - * Gets the data set description of a TestCase. |
|
1964 | - * |
|
1965 | - * @param bool $includeData |
|
1966 | - * |
|
1967 | - * @return string |
|
1968 | - */ |
|
1969 | - public function getDataSetAsString($includeData = true) |
|
1970 | - { |
|
1971 | - $buffer = ''; |
|
1972 | - |
|
1973 | - if (!empty($this->data)) { |
|
1974 | - if (\is_int($this->dataName)) { |
|
1975 | - $buffer .= \sprintf(' with data set #%d', $this->dataName); |
|
1976 | - } else { |
|
1977 | - $buffer .= \sprintf(' with data set "%s"', $this->dataName); |
|
1978 | - } |
|
1979 | - |
|
1980 | - $exporter = new Exporter; |
|
1981 | - |
|
1982 | - if ($includeData) { |
|
1983 | - $buffer .= \sprintf(' (%s)', $exporter->shortenedRecursiveExport($this->data)); |
|
1984 | - } |
|
1985 | - } |
|
1986 | - |
|
1987 | - return $buffer; |
|
1988 | - } |
|
1989 | - |
|
1990 | - /** |
|
1991 | - * Gets the data set of a TestCase. |
|
1992 | - * |
|
1993 | - * @return array |
|
1994 | - */ |
|
1995 | - protected function getProvidedData() |
|
1996 | - { |
|
1997 | - return $this->data; |
|
1998 | - } |
|
1999 | - |
|
2000 | - /** |
|
2001 | - * Creates a default TestResult object. |
|
2002 | - * |
|
2003 | - * @return TestResult |
|
2004 | - */ |
|
2005 | - protected function createResult() |
|
2006 | - { |
|
2007 | - return new TestResult; |
|
2008 | - } |
|
2009 | - |
|
2010 | - protected function handleDependencies() |
|
2011 | - { |
|
2012 | - if (!empty($this->dependencies) && !$this->inIsolation) { |
|
2013 | - $className = \get_class($this); |
|
2014 | - $passed = $this->result->passed(); |
|
2015 | - $passedKeys = \array_keys($passed); |
|
2016 | - $numKeys = \count($passedKeys); |
|
2017 | - |
|
2018 | - for ($i = 0; $i < $numKeys; $i++) { |
|
2019 | - $pos = \strpos($passedKeys[$i], ' with data set'); |
|
2020 | - |
|
2021 | - if ($pos !== false) { |
|
2022 | - $passedKeys[$i] = \substr($passedKeys[$i], 0, $pos); |
|
2023 | - } |
|
2024 | - } |
|
2025 | - |
|
2026 | - $passedKeys = \array_flip(\array_unique($passedKeys)); |
|
2027 | - |
|
2028 | - foreach ($this->dependencies as $dependency) { |
|
2029 | - $clone = false; |
|
2030 | - |
|
2031 | - if (\strpos($dependency, 'clone ') === 0) { |
|
2032 | - $clone = true; |
|
2033 | - $dependency = \substr($dependency, \strlen('clone ')); |
|
2034 | - } elseif (\strpos($dependency, '!clone ') === 0) { |
|
2035 | - $clone = false; |
|
2036 | - $dependency = \substr($dependency, \strlen('!clone ')); |
|
2037 | - } |
|
2038 | - |
|
2039 | - if (\strpos($dependency, '::') === false) { |
|
2040 | - $dependency = $className . '::' . $dependency; |
|
2041 | - } |
|
2042 | - |
|
2043 | - if (!isset($passedKeys[$dependency])) { |
|
2044 | - $this->result->startTest($this); |
|
2045 | - $this->result->addError( |
|
2046 | - $this, |
|
2047 | - new SkippedTestError( |
|
2048 | - \sprintf( |
|
2049 | - 'This test depends on "%s" to pass.', |
|
2050 | - $dependency |
|
2051 | - ) |
|
2052 | - ), |
|
2053 | - 0 |
|
2054 | - ); |
|
2055 | - $this->result->endTest($this, 0); |
|
2056 | - |
|
2057 | - return false; |
|
2058 | - } |
|
2059 | - |
|
2060 | - if (isset($passed[$dependency])) { |
|
2061 | - if ($passed[$dependency]['size'] != \PHPUnit\Util\Test::UNKNOWN && |
|
2062 | - $this->getSize() != \PHPUnit\Util\Test::UNKNOWN && |
|
2063 | - $passed[$dependency]['size'] > $this->getSize()) { |
|
2064 | - $this->result->addError( |
|
2065 | - $this, |
|
2066 | - new SkippedTestError( |
|
2067 | - 'This test depends on a test that is larger than itself.' |
|
2068 | - ), |
|
2069 | - 0 |
|
2070 | - ); |
|
2071 | - |
|
2072 | - return false; |
|
2073 | - } |
|
2074 | - |
|
2075 | - if ($clone) { |
|
2076 | - $deepCopy = new DeepCopy; |
|
2077 | - $deepCopy->skipUncloneable(false); |
|
2078 | - |
|
2079 | - $this->dependencyInput[$dependency] = $deepCopy->copy($passed[$dependency]['result']); |
|
2080 | - } else { |
|
2081 | - $this->dependencyInput[$dependency] = $passed[$dependency]['result']; |
|
2082 | - } |
|
2083 | - } else { |
|
2084 | - $this->dependencyInput[$dependency] = null; |
|
2085 | - } |
|
2086 | - } |
|
2087 | - } |
|
2088 | - |
|
2089 | - return true; |
|
2090 | - } |
|
2091 | - |
|
2092 | - /** |
|
2093 | - * This method is called before the first test of this test class is run. |
|
2094 | - */ |
|
2095 | - public static function setUpBeforeClass() |
|
2096 | - { |
|
2097 | - } |
|
2098 | - |
|
2099 | - /** |
|
2100 | - * Sets up the fixture, for example, open a network connection. |
|
2101 | - * This method is called before a test is executed. |
|
2102 | - */ |
|
2103 | - protected function setUp() |
|
2104 | - { |
|
2105 | - } |
|
2106 | - |
|
2107 | - /** |
|
2108 | - * Performs assertions shared by all tests of a test case. |
|
2109 | - * |
|
2110 | - * This method is called before the execution of a test starts |
|
2111 | - * and after setUp() is called. |
|
2112 | - */ |
|
2113 | - protected function assertPreConditions() |
|
2114 | - { |
|
2115 | - } |
|
2116 | - |
|
2117 | - /** |
|
2118 | - * Performs assertions shared by all tests of a test case. |
|
2119 | - * |
|
2120 | - * This method is called after the execution of a test ends |
|
2121 | - * and before tearDown() is called. |
|
2122 | - */ |
|
2123 | - protected function assertPostConditions() |
|
2124 | - { |
|
2125 | - } |
|
2126 | - |
|
2127 | - /** |
|
2128 | - * Tears down the fixture, for example, close a network connection. |
|
2129 | - * This method is called after a test is executed. |
|
2130 | - */ |
|
2131 | - protected function tearDown() |
|
2132 | - { |
|
2133 | - } |
|
2134 | - |
|
2135 | - /** |
|
2136 | - * This method is called after the last test of this test class is run. |
|
2137 | - */ |
|
2138 | - public static function tearDownAfterClass() |
|
2139 | - { |
|
2140 | - } |
|
2141 | - |
|
2142 | - /** |
|
2143 | - * This method is called when a test method did not execute successfully. |
|
2144 | - * |
|
2145 | - * @param Throwable $t |
|
2146 | - * |
|
2147 | - * @throws Throwable |
|
2148 | - */ |
|
2149 | - protected function onNotSuccessfulTest(Throwable $t) |
|
2150 | - { |
|
2151 | - throw $t; |
|
2152 | - } |
|
2153 | - |
|
2154 | - /** |
|
2155 | - * Performs custom preparations on the process isolation template. |
|
2156 | - * |
|
2157 | - * @param Text_Template $template |
|
2158 | - */ |
|
2159 | - protected function prepareTemplate(Text_Template $template) |
|
2160 | - { |
|
2161 | - } |
|
2162 | - |
|
2163 | - /** |
|
2164 | - * Get the mock object generator, creating it if it doesn't exist. |
|
2165 | - * |
|
2166 | - * @return PHPUnit_Framework_MockObject_Generator |
|
2167 | - */ |
|
2168 | - private function getMockObjectGenerator() |
|
2169 | - { |
|
2170 | - if (null === $this->mockObjectGenerator) { |
|
2171 | - $this->mockObjectGenerator = new PHPUnit_Framework_MockObject_Generator; |
|
2172 | - } |
|
2173 | - |
|
2174 | - return $this->mockObjectGenerator; |
|
2175 | - } |
|
2176 | - |
|
2177 | - private function startOutputBuffering() |
|
2178 | - { |
|
2179 | - \ob_start(); |
|
2180 | - |
|
2181 | - $this->outputBufferingActive = true; |
|
2182 | - $this->outputBufferingLevel = \ob_get_level(); |
|
2183 | - } |
|
2184 | - |
|
2185 | - private function stopOutputBuffering() |
|
2186 | - { |
|
2187 | - if (\ob_get_level() != $this->outputBufferingLevel) { |
|
2188 | - while (\ob_get_level() >= $this->outputBufferingLevel) { |
|
2189 | - \ob_end_clean(); |
|
2190 | - } |
|
2191 | - |
|
2192 | - throw new RiskyTestError( |
|
2193 | - 'Test code or tested code did not (only) close its own output buffers' |
|
2194 | - ); |
|
2195 | - } |
|
2196 | - |
|
2197 | - $output = \ob_get_contents(); |
|
2198 | - |
|
2199 | - if ($this->outputCallback === false) { |
|
2200 | - $this->output = $output; |
|
2201 | - } else { |
|
2202 | - $this->output = \call_user_func_array( |
|
2203 | - $this->outputCallback, |
|
2204 | - [$output] |
|
2205 | - ); |
|
2206 | - } |
|
2207 | - |
|
2208 | - \ob_end_clean(); |
|
2209 | - |
|
2210 | - $this->outputBufferingActive = false; |
|
2211 | - $this->outputBufferingLevel = \ob_get_level(); |
|
2212 | - } |
|
2213 | - |
|
2214 | - private function snapshotGlobalState() |
|
2215 | - { |
|
2216 | - if ($this->runTestInSeparateProcess || |
|
2217 | - $this->inIsolation || |
|
2218 | - (!$this->backupGlobals === true && !$this->backupStaticAttributes)) { |
|
2219 | - return; |
|
2220 | - } |
|
2221 | - |
|
2222 | - $this->snapshot = $this->createGlobalStateSnapshot($this->backupGlobals === true); |
|
2223 | - } |
|
2224 | - |
|
2225 | - private function restoreGlobalState() |
|
2226 | - { |
|
2227 | - if (!$this->snapshot instanceof Snapshot) { |
|
2228 | - return; |
|
2229 | - } |
|
2230 | - |
|
2231 | - if ($this->beStrictAboutChangesToGlobalState) { |
|
2232 | - try { |
|
2233 | - $this->compareGlobalStateSnapshots( |
|
2234 | - $this->snapshot, |
|
2235 | - $this->createGlobalStateSnapshot($this->backupGlobals === true) |
|
2236 | - ); |
|
2237 | - } catch (RiskyTestError $rte) { |
|
2238 | - // Intentionally left empty |
|
2239 | - } |
|
2240 | - } |
|
2241 | - |
|
2242 | - $restorer = new Restorer; |
|
2243 | - |
|
2244 | - if ($this->backupGlobals === true) { |
|
2245 | - $restorer->restoreGlobalVariables($this->snapshot); |
|
2246 | - } |
|
2247 | - |
|
2248 | - if ($this->backupStaticAttributes) { |
|
2249 | - $restorer->restoreStaticAttributes($this->snapshot); |
|
2250 | - } |
|
2251 | - |
|
2252 | - $this->snapshot = null; |
|
2253 | - |
|
2254 | - if (isset($rte)) { |
|
2255 | - throw $rte; |
|
2256 | - } |
|
2257 | - } |
|
2258 | - |
|
2259 | - /** |
|
2260 | - * @param bool $backupGlobals |
|
2261 | - * |
|
2262 | - * @return Snapshot |
|
2263 | - */ |
|
2264 | - private function createGlobalStateSnapshot($backupGlobals) |
|
2265 | - { |
|
2266 | - $blacklist = new Blacklist; |
|
2267 | - |
|
2268 | - foreach ($this->backupGlobalsBlacklist as $globalVariable) { |
|
2269 | - $blacklist->addGlobalVariable($globalVariable); |
|
2270 | - } |
|
2271 | - |
|
2272 | - if (!\defined('PHPUNIT_TESTSUITE')) { |
|
2273 | - $blacklist->addClassNamePrefix('PHPUnit'); |
|
2274 | - $blacklist->addClassNamePrefix('File_Iterator'); |
|
2275 | - $blacklist->addClassNamePrefix('SebastianBergmann\CodeCoverage'); |
|
2276 | - $blacklist->addClassNamePrefix('PHP_Invoker'); |
|
2277 | - $blacklist->addClassNamePrefix('PHP_Timer'); |
|
2278 | - $blacklist->addClassNamePrefix('PHP_Token'); |
|
2279 | - $blacklist->addClassNamePrefix('Symfony'); |
|
2280 | - $blacklist->addClassNamePrefix('Text_Template'); |
|
2281 | - $blacklist->addClassNamePrefix('Doctrine\Instantiator'); |
|
2282 | - $blacklist->addClassNamePrefix('Prophecy'); |
|
2283 | - |
|
2284 | - foreach ($this->backupStaticAttributesBlacklist as $class => $attributes) { |
|
2285 | - foreach ($attributes as $attribute) { |
|
2286 | - $blacklist->addStaticAttribute($class, $attribute); |
|
2287 | - } |
|
2288 | - } |
|
2289 | - } |
|
2290 | - |
|
2291 | - return new Snapshot( |
|
2292 | - $blacklist, |
|
2293 | - $backupGlobals, |
|
2294 | - (bool) $this->backupStaticAttributes, |
|
2295 | - false, |
|
2296 | - false, |
|
2297 | - false, |
|
2298 | - false, |
|
2299 | - false, |
|
2300 | - false, |
|
2301 | - false |
|
2302 | - ); |
|
2303 | - } |
|
2304 | - |
|
2305 | - /** |
|
2306 | - * @param Snapshot $before |
|
2307 | - * @param Snapshot $after |
|
2308 | - * |
|
2309 | - * @throws RiskyTestError |
|
2310 | - */ |
|
2311 | - private function compareGlobalStateSnapshots(Snapshot $before, Snapshot $after) |
|
2312 | - { |
|
2313 | - $backupGlobals = $this->backupGlobals === null || $this->backupGlobals === true; |
|
2314 | - |
|
2315 | - if ($backupGlobals) { |
|
2316 | - $this->compareGlobalStateSnapshotPart( |
|
2317 | - $before->globalVariables(), |
|
2318 | - $after->globalVariables(), |
|
2319 | - "--- Global variables before the test\n+++ Global variables after the test\n" |
|
2320 | - ); |
|
2321 | - |
|
2322 | - $this->compareGlobalStateSnapshotPart( |
|
2323 | - $before->superGlobalVariables(), |
|
2324 | - $after->superGlobalVariables(), |
|
2325 | - "--- Super-global variables before the test\n+++ Super-global variables after the test\n" |
|
2326 | - ); |
|
2327 | - } |
|
2328 | - |
|
2329 | - if ($this->backupStaticAttributes) { |
|
2330 | - $this->compareGlobalStateSnapshotPart( |
|
2331 | - $before->staticAttributes(), |
|
2332 | - $after->staticAttributes(), |
|
2333 | - "--- Static attributes before the test\n+++ Static attributes after the test\n" |
|
2334 | - ); |
|
2335 | - } |
|
2336 | - } |
|
2337 | - |
|
2338 | - /** |
|
2339 | - * @param array $before |
|
2340 | - * @param array $after |
|
2341 | - * @param string $header |
|
2342 | - * |
|
2343 | - * @throws RiskyTestError |
|
2344 | - */ |
|
2345 | - private function compareGlobalStateSnapshotPart(array $before, array $after, $header) |
|
2346 | - { |
|
2347 | - if ($before != $after) { |
|
2348 | - $differ = new Differ($header); |
|
2349 | - $exporter = new Exporter; |
|
2350 | - |
|
2351 | - $diff = $differ->diff( |
|
2352 | - $exporter->export($before), |
|
2353 | - $exporter->export($after) |
|
2354 | - ); |
|
2355 | - |
|
2356 | - throw new RiskyTestError( |
|
2357 | - $diff |
|
2358 | - ); |
|
2359 | - } |
|
2360 | - } |
|
2361 | - |
|
2362 | - /** |
|
2363 | - * @return Prophecy\Prophet |
|
2364 | - */ |
|
2365 | - private function getProphet() |
|
2366 | - { |
|
2367 | - if ($this->prophet === null) { |
|
2368 | - $this->prophet = new Prophet; |
|
2369 | - } |
|
2370 | - |
|
2371 | - return $this->prophet; |
|
2372 | - } |
|
2373 | - |
|
2374 | - /** |
|
2375 | - * @param PHPUnit_Framework_MockObject_MockObject $mock |
|
2376 | - * |
|
2377 | - * @return bool |
|
2378 | - */ |
|
2379 | - private function shouldInvocationMockerBeReset(PHPUnit_Framework_MockObject_MockObject $mock) |
|
2380 | - { |
|
2381 | - $enumerator = new Enumerator; |
|
2382 | - |
|
2383 | - foreach ($enumerator->enumerate($this->dependencyInput) as $object) { |
|
2384 | - if ($mock === $object) { |
|
2385 | - return false; |
|
2386 | - } |
|
2387 | - } |
|
2388 | - |
|
2389 | - if (!\is_array($this->testResult) && !\is_object($this->testResult)) { |
|
2390 | - return true; |
|
2391 | - } |
|
2392 | - |
|
2393 | - foreach ($enumerator->enumerate($this->testResult) as $object) { |
|
2394 | - if ($mock === $object) { |
|
2395 | - return false; |
|
2396 | - } |
|
2397 | - } |
|
2398 | - |
|
2399 | - return true; |
|
2400 | - } |
|
2401 | - |
|
2402 | - /** |
|
2403 | - * @param array $testArguments |
|
2404 | - * @param array $visited |
|
2405 | - */ |
|
2406 | - private function registerMockObjectsFromTestArguments(array $testArguments, array &$visited = []) |
|
2407 | - { |
|
2408 | - if ($this->registerMockObjectsFromTestArgumentsRecursively) { |
|
2409 | - $enumerator = new Enumerator; |
|
2410 | - |
|
2411 | - foreach ($enumerator->enumerate($testArguments) as $object) { |
|
2412 | - if ($object instanceof PHPUnit_Framework_MockObject_MockObject) { |
|
2413 | - $this->registerMockObject($object); |
|
2414 | - } |
|
2415 | - } |
|
2416 | - } else { |
|
2417 | - foreach ($testArguments as $testArgument) { |
|
2418 | - if ($testArgument instanceof PHPUnit_Framework_MockObject_MockObject) { |
|
2419 | - if ($this->isCloneable($testArgument)) { |
|
2420 | - $testArgument = clone $testArgument; |
|
2421 | - } |
|
2422 | - |
|
2423 | - $this->registerMockObject($testArgument); |
|
2424 | - } elseif (\is_array($testArgument) && !\in_array($testArgument, $visited, true)) { |
|
2425 | - $visited[] = $testArgument; |
|
2426 | - |
|
2427 | - $this->registerMockObjectsFromTestArguments( |
|
2428 | - $testArgument, |
|
2429 | - $visited |
|
2430 | - ); |
|
2431 | - } |
|
2432 | - } |
|
2433 | - } |
|
2434 | - } |
|
2435 | - |
|
2436 | - private function setDoesNotPerformAssertionsFromAnnotation() |
|
2437 | - { |
|
2438 | - $annotations = $this->getAnnotations(); |
|
2439 | - |
|
2440 | - if (isset($annotations['method']['doesNotPerformAssertions'])) { |
|
2441 | - $this->doesNotPerformAssertions = true; |
|
2442 | - } |
|
2443 | - } |
|
2444 | - |
|
2445 | - /** |
|
2446 | - * @param PHPUnit_Framework_MockObject_MockObject $testArgument |
|
2447 | - * |
|
2448 | - * @return bool |
|
2449 | - */ |
|
2450 | - private function isCloneable(PHPUnit_Framework_MockObject_MockObject $testArgument) |
|
2451 | - { |
|
2452 | - $reflector = new ReflectionObject($testArgument); |
|
2453 | - |
|
2454 | - if (!$reflector->isCloneable()) { |
|
2455 | - return false; |
|
2456 | - } |
|
2457 | - |
|
2458 | - if ($reflector->hasMethod('__clone') && |
|
2459 | - $reflector->getMethod('__clone')->isPublic()) { |
|
2460 | - return true; |
|
2461 | - } |
|
2462 | - |
|
2463 | - return false; |
|
2464 | - } |
|
2465 | - |
|
2466 | - private function unregisterCustomComparators() |
|
2467 | - { |
|
2468 | - $factory = ComparatorFactory::getInstance(); |
|
2469 | - |
|
2470 | - foreach ($this->customComparators as $comparator) { |
|
2471 | - $factory->unregister($comparator); |
|
2472 | - } |
|
2473 | - |
|
2474 | - $this->customComparators = []; |
|
2475 | - } |
|
2476 | - |
|
2477 | - private function cleanupIniSettings() |
|
2478 | - { |
|
2479 | - foreach ($this->iniSettings as $varName => $oldValue) { |
|
2480 | - \ini_set($varName, $oldValue); |
|
2481 | - } |
|
2482 | - |
|
2483 | - $this->iniSettings = []; |
|
2484 | - } |
|
2485 | - |
|
2486 | - private function cleanupLocaleSettings() |
|
2487 | - { |
|
2488 | - foreach ($this->locale as $category => $locale) { |
|
2489 | - \setlocale($category, $locale); |
|
2490 | - } |
|
2491 | - |
|
2492 | - $this->locale = []; |
|
2493 | - } |
|
2494 | - |
|
2495 | - private function checkExceptionExpectations(Throwable $throwable): bool |
|
2496 | - { |
|
2497 | - $result = false; |
|
2498 | - |
|
2499 | - if ($this->expectedException !== null || $this->expectedExceptionCode !== null || $this->expectedExceptionMessage !== null || $this->expectedExceptionMessageRegExp !== null) { |
|
2500 | - $result = true; |
|
2501 | - } |
|
2502 | - |
|
2503 | - if ($throwable instanceof Exception) { |
|
2504 | - $result = false; |
|
2505 | - } |
|
2506 | - |
|
2507 | - if (\is_string($this->expectedException)) { |
|
2508 | - $reflector = new ReflectionClass($this->expectedException); |
|
2509 | - |
|
2510 | - if ($this->expectedException === 'PHPUnit\Framework\Exception' || |
|
2511 | - $this->expectedException === '\PHPUnit\Framework\Exception' || |
|
2512 | - $reflector->isSubclassOf('PHPUnit\Framework\Exception')) { |
|
2513 | - $result = true; |
|
2514 | - } |
|
2515 | - } |
|
2516 | - |
|
2517 | - return $result; |
|
2518 | - } |
|
103 | + /** |
|
104 | + * Enable or disable the backup and restoration of the $GLOBALS array. |
|
105 | + * Overwrite this attribute in a child class of TestCase. |
|
106 | + * Setting this attribute in setUp() has no effect! |
|
107 | + * |
|
108 | + * @var bool |
|
109 | + */ |
|
110 | + protected $backupGlobals; |
|
111 | + |
|
112 | + /** |
|
113 | + * @var array |
|
114 | + */ |
|
115 | + protected $backupGlobalsBlacklist = []; |
|
116 | + |
|
117 | + /** |
|
118 | + * Enable or disable the backup and restoration of static attributes. |
|
119 | + * Overwrite this attribute in a child class of TestCase. |
|
120 | + * Setting this attribute in setUp() has no effect! |
|
121 | + * |
|
122 | + * @var bool |
|
123 | + */ |
|
124 | + protected $backupStaticAttributes; |
|
125 | + |
|
126 | + /** |
|
127 | + * @var array |
|
128 | + */ |
|
129 | + protected $backupStaticAttributesBlacklist = []; |
|
130 | + |
|
131 | + /** |
|
132 | + * Whether or not this test is to be run in a separate PHP process. |
|
133 | + * |
|
134 | + * @var bool |
|
135 | + */ |
|
136 | + protected $runTestInSeparateProcess; |
|
137 | + |
|
138 | + /** |
|
139 | + * Whether or not this class is to be run in a separate PHP process. |
|
140 | + * |
|
141 | + * @var bool |
|
142 | + */ |
|
143 | + private $runClassInSeparateProcess; |
|
144 | + |
|
145 | + /** |
|
146 | + * Whether or not this test should preserve the global state when |
|
147 | + * running in a separate PHP process. |
|
148 | + * |
|
149 | + * @var bool |
|
150 | + */ |
|
151 | + protected $preserveGlobalState = true; |
|
152 | + |
|
153 | + /** |
|
154 | + * Whether or not this test is running in a separate PHP process. |
|
155 | + * |
|
156 | + * @var bool |
|
157 | + */ |
|
158 | + private $inIsolation = false; |
|
159 | + |
|
160 | + /** |
|
161 | + * @var array |
|
162 | + */ |
|
163 | + private $data; |
|
164 | + |
|
165 | + /** |
|
166 | + * @var string |
|
167 | + */ |
|
168 | + private $dataName; |
|
169 | + |
|
170 | + /** |
|
171 | + * @var bool |
|
172 | + */ |
|
173 | + private $useErrorHandler; |
|
174 | + |
|
175 | + /** |
|
176 | + * The name of the expected Exception. |
|
177 | + * |
|
178 | + * @var null|string |
|
179 | + */ |
|
180 | + private $expectedException; |
|
181 | + |
|
182 | + /** |
|
183 | + * The message of the expected Exception. |
|
184 | + * |
|
185 | + * @var string |
|
186 | + */ |
|
187 | + private $expectedExceptionMessage; |
|
188 | + |
|
189 | + /** |
|
190 | + * The regex pattern to validate the expected Exception message. |
|
191 | + * |
|
192 | + * @var string |
|
193 | + */ |
|
194 | + private $expectedExceptionMessageRegExp; |
|
195 | + |
|
196 | + /** |
|
197 | + * The code of the expected Exception. |
|
198 | + * |
|
199 | + * @var null|int|string |
|
200 | + */ |
|
201 | + private $expectedExceptionCode; |
|
202 | + |
|
203 | + /** |
|
204 | + * The name of the test case. |
|
205 | + * |
|
206 | + * @var string |
|
207 | + */ |
|
208 | + private $name; |
|
209 | + |
|
210 | + /** |
|
211 | + * @var string[] |
|
212 | + */ |
|
213 | + private $dependencies = []; |
|
214 | + |
|
215 | + /** |
|
216 | + * @var array |
|
217 | + */ |
|
218 | + private $dependencyInput = []; |
|
219 | + |
|
220 | + /** |
|
221 | + * @var array |
|
222 | + */ |
|
223 | + private $iniSettings = []; |
|
224 | + |
|
225 | + /** |
|
226 | + * @var array |
|
227 | + */ |
|
228 | + private $locale = []; |
|
229 | + |
|
230 | + /** |
|
231 | + * @var array |
|
232 | + */ |
|
233 | + private $mockObjects = []; |
|
234 | + |
|
235 | + /** |
|
236 | + * @var array |
|
237 | + */ |
|
238 | + private $mockObjectGenerator; |
|
239 | + |
|
240 | + /** |
|
241 | + * @var int |
|
242 | + */ |
|
243 | + private $status; |
|
244 | + |
|
245 | + /** |
|
246 | + * @var string |
|
247 | + */ |
|
248 | + private $statusMessage = ''; |
|
249 | + |
|
250 | + /** |
|
251 | + * @var int |
|
252 | + */ |
|
253 | + private $numAssertions = 0; |
|
254 | + |
|
255 | + /** |
|
256 | + * @var TestResult |
|
257 | + */ |
|
258 | + private $result; |
|
259 | + |
|
260 | + /** |
|
261 | + * @var mixed |
|
262 | + */ |
|
263 | + private $testResult; |
|
264 | + |
|
265 | + /** |
|
266 | + * @var string |
|
267 | + */ |
|
268 | + private $output = ''; |
|
269 | + |
|
270 | + /** |
|
271 | + * @var string |
|
272 | + */ |
|
273 | + private $outputExpectedRegex; |
|
274 | + |
|
275 | + /** |
|
276 | + * @var string |
|
277 | + */ |
|
278 | + private $outputExpectedString; |
|
279 | + |
|
280 | + /** |
|
281 | + * @var mixed |
|
282 | + */ |
|
283 | + private $outputCallback = false; |
|
284 | + |
|
285 | + /** |
|
286 | + * @var bool |
|
287 | + */ |
|
288 | + private $outputBufferingActive = false; |
|
289 | + |
|
290 | + /** |
|
291 | + * @var int |
|
292 | + */ |
|
293 | + private $outputBufferingLevel; |
|
294 | + |
|
295 | + /** |
|
296 | + * @var SebastianBergmann\GlobalState\Snapshot |
|
297 | + */ |
|
298 | + private $snapshot; |
|
299 | + |
|
300 | + /** |
|
301 | + * @var Prophecy\Prophet |
|
302 | + */ |
|
303 | + private $prophet; |
|
304 | + |
|
305 | + /** |
|
306 | + * @var bool |
|
307 | + */ |
|
308 | + private $beStrictAboutChangesToGlobalState = false; |
|
309 | + |
|
310 | + /** |
|
311 | + * @var bool |
|
312 | + */ |
|
313 | + private $registerMockObjectsFromTestArgumentsRecursively = false; |
|
314 | + |
|
315 | + /** |
|
316 | + * @var string[] |
|
317 | + */ |
|
318 | + private $warnings = []; |
|
319 | + |
|
320 | + /** |
|
321 | + * @var array |
|
322 | + */ |
|
323 | + private $groups = []; |
|
324 | + |
|
325 | + /** |
|
326 | + * @var bool |
|
327 | + */ |
|
328 | + private $doesNotPerformAssertions = false; |
|
329 | + |
|
330 | + /** |
|
331 | + * @var Comparator[] |
|
332 | + */ |
|
333 | + private $customComparators = []; |
|
334 | + |
|
335 | + /** |
|
336 | + * Constructs a test case with the given name. |
|
337 | + * |
|
338 | + * @param string $name |
|
339 | + * @param array $data |
|
340 | + * @param string $dataName |
|
341 | + */ |
|
342 | + public function __construct($name = null, array $data = [], $dataName = '') |
|
343 | + { |
|
344 | + if ($name !== null) { |
|
345 | + $this->setName($name); |
|
346 | + } |
|
347 | + |
|
348 | + $this->data = $data; |
|
349 | + $this->dataName = $dataName; |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Returns a string representation of the test case. |
|
354 | + * |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + public function toString() |
|
358 | + { |
|
359 | + $class = new ReflectionClass($this); |
|
360 | + |
|
361 | + $buffer = \sprintf( |
|
362 | + '%s::%s', |
|
363 | + $class->name, |
|
364 | + $this->getName(false) |
|
365 | + ); |
|
366 | + |
|
367 | + return $buffer . $this->getDataSetAsString(); |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Counts the number of test cases executed by run(TestResult result). |
|
372 | + * |
|
373 | + * @return int |
|
374 | + */ |
|
375 | + public function count() |
|
376 | + { |
|
377 | + return 1; |
|
378 | + } |
|
379 | + |
|
380 | + public function getGroups() |
|
381 | + { |
|
382 | + return $this->groups; |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * @param array $groups |
|
387 | + */ |
|
388 | + public function setGroups(array $groups) |
|
389 | + { |
|
390 | + $this->groups = $groups; |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Returns the annotations for this test. |
|
395 | + * |
|
396 | + * @return array |
|
397 | + */ |
|
398 | + public function getAnnotations() |
|
399 | + { |
|
400 | + return \PHPUnit\Util\Test::parseTestMethodAnnotations( |
|
401 | + \get_class($this), |
|
402 | + $this->name |
|
403 | + ); |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Gets the name of a TestCase. |
|
408 | + * |
|
409 | + * @param bool $withDataSet |
|
410 | + * |
|
411 | + * @return string |
|
412 | + */ |
|
413 | + public function getName($withDataSet = true) |
|
414 | + { |
|
415 | + if ($withDataSet) { |
|
416 | + return $this->name . $this->getDataSetAsString(false); |
|
417 | + } |
|
418 | + |
|
419 | + return $this->name; |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Returns the size of the test. |
|
424 | + * |
|
425 | + * @return int |
|
426 | + */ |
|
427 | + public function getSize() |
|
428 | + { |
|
429 | + return \PHPUnit\Util\Test::getSize( |
|
430 | + \get_class($this), |
|
431 | + $this->getName(false) |
|
432 | + ); |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * @return bool |
|
437 | + */ |
|
438 | + public function hasSize() |
|
439 | + { |
|
440 | + return $this->getSize() !== \PHPUnit\Util\Test::UNKNOWN; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * @return bool |
|
445 | + */ |
|
446 | + public function isSmall() |
|
447 | + { |
|
448 | + return $this->getSize() === \PHPUnit\Util\Test::SMALL; |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * @return bool |
|
453 | + */ |
|
454 | + public function isMedium() |
|
455 | + { |
|
456 | + return $this->getSize() === \PHPUnit\Util\Test::MEDIUM; |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * @return bool |
|
461 | + */ |
|
462 | + public function isLarge() |
|
463 | + { |
|
464 | + return $this->getSize() === \PHPUnit\Util\Test::LARGE; |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * @return string |
|
469 | + */ |
|
470 | + public function getActualOutput() |
|
471 | + { |
|
472 | + if (!$this->outputBufferingActive) { |
|
473 | + return $this->output; |
|
474 | + } |
|
475 | + |
|
476 | + return \ob_get_contents(); |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * @return bool |
|
481 | + */ |
|
482 | + public function hasOutput() |
|
483 | + { |
|
484 | + if (\strlen($this->output) === 0) { |
|
485 | + return false; |
|
486 | + } |
|
487 | + |
|
488 | + if ($this->hasExpectationOnOutput()) { |
|
489 | + return false; |
|
490 | + } |
|
491 | + |
|
492 | + return true; |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * @return bool |
|
497 | + */ |
|
498 | + public function doesNotPerformAssertions() |
|
499 | + { |
|
500 | + return $this->doesNotPerformAssertions; |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * @param string $expectedRegex |
|
505 | + * |
|
506 | + * @throws Exception |
|
507 | + */ |
|
508 | + public function expectOutputRegex($expectedRegex) |
|
509 | + { |
|
510 | + if ($this->outputExpectedString !== null) { |
|
511 | + throw new Exception; |
|
512 | + } |
|
513 | + |
|
514 | + if (\is_string($expectedRegex) || null === $expectedRegex) { |
|
515 | + $this->outputExpectedRegex = $expectedRegex; |
|
516 | + } |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * @param string $expectedString |
|
521 | + */ |
|
522 | + public function expectOutputString($expectedString) |
|
523 | + { |
|
524 | + if ($this->outputExpectedRegex !== null) { |
|
525 | + throw new Exception; |
|
526 | + } |
|
527 | + |
|
528 | + if (\is_string($expectedString) || null === $expectedString) { |
|
529 | + $this->outputExpectedString = $expectedString; |
|
530 | + } |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * @return bool |
|
535 | + */ |
|
536 | + public function hasExpectationOnOutput() |
|
537 | + { |
|
538 | + return \is_string($this->outputExpectedString) || \is_string($this->outputExpectedRegex); |
|
539 | + } |
|
540 | + |
|
541 | + /** |
|
542 | + * @return null|string |
|
543 | + */ |
|
544 | + public function getExpectedException() |
|
545 | + { |
|
546 | + return $this->expectedException; |
|
547 | + } |
|
548 | + |
|
549 | + /** |
|
550 | + * @return null|int|string |
|
551 | + */ |
|
552 | + public function getExpectedExceptionCode() |
|
553 | + { |
|
554 | + return $this->expectedExceptionCode; |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * @return string |
|
559 | + */ |
|
560 | + public function getExpectedExceptionMessage() |
|
561 | + { |
|
562 | + return $this->expectedExceptionMessage; |
|
563 | + } |
|
564 | + |
|
565 | + /** |
|
566 | + * @return string |
|
567 | + */ |
|
568 | + public function getExpectedExceptionMessageRegExp() |
|
569 | + { |
|
570 | + return $this->expectedExceptionMessageRegExp; |
|
571 | + } |
|
572 | + |
|
573 | + /** |
|
574 | + * @param string $exception |
|
575 | + */ |
|
576 | + public function expectException($exception) |
|
577 | + { |
|
578 | + if (!\is_string($exception)) { |
|
579 | + throw InvalidArgumentHelper::factory(1, 'string'); |
|
580 | + } |
|
581 | + |
|
582 | + $this->expectedException = $exception; |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * @param int|string $code |
|
587 | + * |
|
588 | + * @throws Exception |
|
589 | + */ |
|
590 | + public function expectExceptionCode($code) |
|
591 | + { |
|
592 | + if (!\is_int($code) && !\is_string($code)) { |
|
593 | + throw InvalidArgumentHelper::factory(1, 'integer or string'); |
|
594 | + } |
|
595 | + |
|
596 | + $this->expectedExceptionCode = $code; |
|
597 | + } |
|
598 | + |
|
599 | + /** |
|
600 | + * @param string $message |
|
601 | + * |
|
602 | + * @throws Exception |
|
603 | + */ |
|
604 | + public function expectExceptionMessage($message) |
|
605 | + { |
|
606 | + if (!\is_string($message)) { |
|
607 | + throw InvalidArgumentHelper::factory(1, 'string'); |
|
608 | + } |
|
609 | + |
|
610 | + $this->expectedExceptionMessage = $message; |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * @param string $messageRegExp |
|
615 | + * |
|
616 | + * @throws Exception |
|
617 | + */ |
|
618 | + public function expectExceptionMessageRegExp($messageRegExp) |
|
619 | + { |
|
620 | + if (!\is_string($messageRegExp)) { |
|
621 | + throw InvalidArgumentHelper::factory(1, 'string'); |
|
622 | + } |
|
623 | + |
|
624 | + $this->expectedExceptionMessageRegExp = $messageRegExp; |
|
625 | + } |
|
626 | + |
|
627 | + /** |
|
628 | + * Sets up an expectation for an exception to be raised by the code under test. |
|
629 | + * Information for expected exception class, expected exception message, and |
|
630 | + * expected exception code are retrieved from a given Exception object. |
|
631 | + */ |
|
632 | + public function expectExceptionObject(\Exception $exception) |
|
633 | + { |
|
634 | + $this->expectException(\get_class($exception)); |
|
635 | + $this->expectExceptionMessage($exception->getMessage()); |
|
636 | + $this->expectExceptionCode($exception->getCode()); |
|
637 | + } |
|
638 | + |
|
639 | + /** |
|
640 | + * @param bool $flag |
|
641 | + */ |
|
642 | + public function setRegisterMockObjectsFromTestArgumentsRecursively($flag) |
|
643 | + { |
|
644 | + if (!\is_bool($flag)) { |
|
645 | + throw InvalidArgumentHelper::factory(1, 'boolean'); |
|
646 | + } |
|
647 | + |
|
648 | + $this->registerMockObjectsFromTestArgumentsRecursively = $flag; |
|
649 | + } |
|
650 | + |
|
651 | + protected function setExpectedExceptionFromAnnotation() |
|
652 | + { |
|
653 | + try { |
|
654 | + $expectedException = \PHPUnit\Util\Test::getExpectedException( |
|
655 | + \get_class($this), |
|
656 | + $this->name |
|
657 | + ); |
|
658 | + |
|
659 | + if ($expectedException !== false) { |
|
660 | + $this->expectException($expectedException['class']); |
|
661 | + |
|
662 | + if ($expectedException['code'] !== null) { |
|
663 | + $this->expectExceptionCode($expectedException['code']); |
|
664 | + } |
|
665 | + |
|
666 | + if ($expectedException['message'] !== '') { |
|
667 | + $this->expectExceptionMessage($expectedException['message']); |
|
668 | + } elseif ($expectedException['message_regex'] !== '') { |
|
669 | + $this->expectExceptionMessageRegExp($expectedException['message_regex']); |
|
670 | + } |
|
671 | + } |
|
672 | + } catch (ReflectionException $e) { |
|
673 | + } |
|
674 | + } |
|
675 | + |
|
676 | + /** |
|
677 | + * @param bool $useErrorHandler |
|
678 | + */ |
|
679 | + public function setUseErrorHandler($useErrorHandler) |
|
680 | + { |
|
681 | + $this->useErrorHandler = $useErrorHandler; |
|
682 | + } |
|
683 | + |
|
684 | + protected function setUseErrorHandlerFromAnnotation() |
|
685 | + { |
|
686 | + try { |
|
687 | + $useErrorHandler = \PHPUnit\Util\Test::getErrorHandlerSettings( |
|
688 | + \get_class($this), |
|
689 | + $this->name |
|
690 | + ); |
|
691 | + |
|
692 | + if ($useErrorHandler !== null) { |
|
693 | + $this->setUseErrorHandler($useErrorHandler); |
|
694 | + } |
|
695 | + } catch (ReflectionException $e) { |
|
696 | + } |
|
697 | + } |
|
698 | + |
|
699 | + protected function checkRequirements() |
|
700 | + { |
|
701 | + if (!$this->name || !\method_exists($this, $this->name)) { |
|
702 | + return; |
|
703 | + } |
|
704 | + |
|
705 | + $missingRequirements = \PHPUnit\Util\Test::getMissingRequirements( |
|
706 | + \get_class($this), |
|
707 | + $this->name |
|
708 | + ); |
|
709 | + |
|
710 | + if (!empty($missingRequirements)) { |
|
711 | + $this->markTestSkipped(\implode(PHP_EOL, $missingRequirements)); |
|
712 | + } |
|
713 | + } |
|
714 | + |
|
715 | + /** |
|
716 | + * Returns the status of this test. |
|
717 | + * |
|
718 | + * @return int |
|
719 | + */ |
|
720 | + public function getStatus() |
|
721 | + { |
|
722 | + return $this->status; |
|
723 | + } |
|
724 | + |
|
725 | + public function markAsRisky() |
|
726 | + { |
|
727 | + $this->status = BaseTestRunner::STATUS_RISKY; |
|
728 | + } |
|
729 | + |
|
730 | + /** |
|
731 | + * Returns the status message of this test. |
|
732 | + * |
|
733 | + * @return string |
|
734 | + */ |
|
735 | + public function getStatusMessage() |
|
736 | + { |
|
737 | + return $this->statusMessage; |
|
738 | + } |
|
739 | + |
|
740 | + /** |
|
741 | + * Returns whether or not this test has failed. |
|
742 | + * |
|
743 | + * @return bool |
|
744 | + */ |
|
745 | + public function hasFailed() |
|
746 | + { |
|
747 | + $status = $this->getStatus(); |
|
748 | + |
|
749 | + return $status == BaseTestRunner::STATUS_FAILURE || |
|
750 | + $status == BaseTestRunner::STATUS_ERROR; |
|
751 | + } |
|
752 | + |
|
753 | + /** |
|
754 | + * Runs the test case and collects the results in a TestResult object. |
|
755 | + * If no TestResult object is passed a new one will be created. |
|
756 | + * |
|
757 | + * @param TestResult $result |
|
758 | + * |
|
759 | + * @return TestResult|null |
|
760 | + * |
|
761 | + * @throws Exception |
|
762 | + */ |
|
763 | + public function run(TestResult $result = null) |
|
764 | + { |
|
765 | + if ($result === null) { |
|
766 | + $result = $this->createResult(); |
|
767 | + } |
|
768 | + |
|
769 | + if (!$this instanceof WarningTestCase) { |
|
770 | + $this->setTestResultObject($result); |
|
771 | + $this->setUseErrorHandlerFromAnnotation(); |
|
772 | + } |
|
773 | + |
|
774 | + if ($this->useErrorHandler !== null) { |
|
775 | + $oldErrorHandlerSetting = $result->getConvertErrorsToExceptions(); |
|
776 | + $result->convertErrorsToExceptions($this->useErrorHandler); |
|
777 | + } |
|
778 | + |
|
779 | + if (!$this instanceof WarningTestCase && |
|
780 | + !$this instanceof SkippedTestCase && |
|
781 | + !$this->handleDependencies()) { |
|
782 | + return; |
|
783 | + } |
|
784 | + |
|
785 | + $runEntireClass = $this->runClassInSeparateProcess && !$this->runTestInSeparateProcess; |
|
786 | + |
|
787 | + if (($this->runTestInSeparateProcess === true || $this->runClassInSeparateProcess === true) && |
|
788 | + $this->inIsolation !== true && |
|
789 | + !$this instanceof PhptTestCase) { |
|
790 | + $class = new ReflectionClass($this); |
|
791 | + |
|
792 | + if ($runEntireClass) { |
|
793 | + $template = new Text_Template( |
|
794 | + __DIR__ . '/../Util/PHP/Template/TestCaseClass.tpl' |
|
795 | + ); |
|
796 | + } else { |
|
797 | + $template = new Text_Template( |
|
798 | + __DIR__ . '/../Util/PHP/Template/TestCaseMethod.tpl' |
|
799 | + ); |
|
800 | + } |
|
801 | + |
|
802 | + if ($this->preserveGlobalState) { |
|
803 | + $constants = GlobalState::getConstantsAsString(); |
|
804 | + $globals = GlobalState::getGlobalsAsString(); |
|
805 | + $includedFiles = GlobalState::getIncludedFilesAsString(); |
|
806 | + $iniSettings = GlobalState::getIniSettingsAsString(); |
|
807 | + } else { |
|
808 | + $constants = ''; |
|
809 | + if (!empty($GLOBALS['__PHPUNIT_BOOTSTRAP'])) { |
|
810 | + $globals = '$GLOBALS[\'__PHPUNIT_BOOTSTRAP\'] = ' . \var_export($GLOBALS['__PHPUNIT_BOOTSTRAP'], true) . ";\n"; |
|
811 | + } else { |
|
812 | + $globals = ''; |
|
813 | + } |
|
814 | + $includedFiles = ''; |
|
815 | + $iniSettings = ''; |
|
816 | + } |
|
817 | + |
|
818 | + $coverage = $result->getCollectCodeCoverageInformation() ? 'true' : 'false'; |
|
819 | + $isStrictAboutTestsThatDoNotTestAnything = $result->isStrictAboutTestsThatDoNotTestAnything() ? 'true' : 'false'; |
|
820 | + $isStrictAboutOutputDuringTests = $result->isStrictAboutOutputDuringTests() ? 'true' : 'false'; |
|
821 | + $enforcesTimeLimit = $result->enforcesTimeLimit() ? 'true' : 'false'; |
|
822 | + $isStrictAboutTodoAnnotatedTests = $result->isStrictAboutTodoAnnotatedTests() ? 'true' : 'false'; |
|
823 | + $isStrictAboutResourceUsageDuringSmallTests = $result->isStrictAboutResourceUsageDuringSmallTests() ? 'true' : 'false'; |
|
824 | + |
|
825 | + if (\defined('PHPUNIT_COMPOSER_INSTALL')) { |
|
826 | + $composerAutoload = \var_export(PHPUNIT_COMPOSER_INSTALL, true); |
|
827 | + } else { |
|
828 | + $composerAutoload = '\'\''; |
|
829 | + } |
|
830 | + |
|
831 | + if (\defined('__PHPUNIT_PHAR__')) { |
|
832 | + $phar = \var_export(__PHPUNIT_PHAR__, true); |
|
833 | + } else { |
|
834 | + $phar = '\'\''; |
|
835 | + } |
|
836 | + |
|
837 | + if ($result->getCodeCoverage()) { |
|
838 | + $codeCoverageFilter = $result->getCodeCoverage()->filter(); |
|
839 | + } else { |
|
840 | + $codeCoverageFilter = null; |
|
841 | + } |
|
842 | + |
|
843 | + $data = \var_export(\serialize($this->data), true); |
|
844 | + $dataName = \var_export($this->dataName, true); |
|
845 | + $dependencyInput = \var_export(\serialize($this->dependencyInput), true); |
|
846 | + $includePath = \var_export(\get_include_path(), true); |
|
847 | + $codeCoverageFilter = \var_export(\serialize($codeCoverageFilter), true); |
|
848 | + // must do these fixes because TestCaseMethod.tpl has unserialize('{data}') in it, and we can't break BC |
|
849 | + // the lines above used to use addcslashes() rather than var_export(), which breaks null byte escape sequences |
|
850 | + $data = "'." . $data . ".'"; |
|
851 | + $dataName = "'.(" . $dataName . ").'"; |
|
852 | + $dependencyInput = "'." . $dependencyInput . ".'"; |
|
853 | + $includePath = "'." . $includePath . ".'"; |
|
854 | + $codeCoverageFilter = "'." . $codeCoverageFilter . ".'"; |
|
855 | + |
|
856 | + $configurationFilePath = $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] ?? ''; |
|
857 | + |
|
858 | + $var = [ |
|
859 | + 'composerAutoload' => $composerAutoload, |
|
860 | + 'phar' => $phar, |
|
861 | + 'filename' => $class->getFileName(), |
|
862 | + 'className' => $class->getName(), |
|
863 | + 'collectCodeCoverageInformation' => $coverage, |
|
864 | + 'data' => $data, |
|
865 | + 'dataName' => $dataName, |
|
866 | + 'dependencyInput' => $dependencyInput, |
|
867 | + 'constants' => $constants, |
|
868 | + 'globals' => $globals, |
|
869 | + 'include_path' => $includePath, |
|
870 | + 'included_files' => $includedFiles, |
|
871 | + 'iniSettings' => $iniSettings, |
|
872 | + 'isStrictAboutTestsThatDoNotTestAnything' => $isStrictAboutTestsThatDoNotTestAnything, |
|
873 | + 'isStrictAboutOutputDuringTests' => $isStrictAboutOutputDuringTests, |
|
874 | + 'enforcesTimeLimit' => $enforcesTimeLimit, |
|
875 | + 'isStrictAboutTodoAnnotatedTests' => $isStrictAboutTodoAnnotatedTests, |
|
876 | + 'isStrictAboutResourceUsageDuringSmallTests' => $isStrictAboutResourceUsageDuringSmallTests, |
|
877 | + 'codeCoverageFilter' => $codeCoverageFilter, |
|
878 | + 'configurationFilePath' => $configurationFilePath |
|
879 | + ]; |
|
880 | + |
|
881 | + if (!$runEntireClass) { |
|
882 | + $var['methodName'] = $this->name; |
|
883 | + } |
|
884 | + |
|
885 | + $template->setVar( |
|
886 | + $var |
|
887 | + ); |
|
888 | + |
|
889 | + $this->prepareTemplate($template); |
|
890 | + |
|
891 | + $php = AbstractPhpProcess::factory(); |
|
892 | + $php->runTestJob($template->render(), $this, $result); |
|
893 | + } else { |
|
894 | + $result->run($this); |
|
895 | + } |
|
896 | + |
|
897 | + if (isset($oldErrorHandlerSetting)) { |
|
898 | + $result->convertErrorsToExceptions($oldErrorHandlerSetting); |
|
899 | + } |
|
900 | + |
|
901 | + $this->result = null; |
|
902 | + |
|
903 | + return $result; |
|
904 | + } |
|
905 | + |
|
906 | + /** |
|
907 | + * Runs the bare test sequence. |
|
908 | + */ |
|
909 | + public function runBare() |
|
910 | + { |
|
911 | + $this->numAssertions = 0; |
|
912 | + |
|
913 | + $this->snapshotGlobalState(); |
|
914 | + $this->startOutputBuffering(); |
|
915 | + \clearstatcache(); |
|
916 | + $currentWorkingDirectory = \getcwd(); |
|
917 | + |
|
918 | + $hookMethods = \PHPUnit\Util\Test::getHookMethods(\get_class($this)); |
|
919 | + |
|
920 | + try { |
|
921 | + $hasMetRequirements = false; |
|
922 | + $this->checkRequirements(); |
|
923 | + $hasMetRequirements = true; |
|
924 | + |
|
925 | + if ($this->inIsolation) { |
|
926 | + foreach ($hookMethods['beforeClass'] as $method) { |
|
927 | + $this->$method(); |
|
928 | + } |
|
929 | + } |
|
930 | + |
|
931 | + $this->setExpectedExceptionFromAnnotation(); |
|
932 | + $this->setDoesNotPerformAssertionsFromAnnotation(); |
|
933 | + |
|
934 | + foreach ($hookMethods['before'] as $method) { |
|
935 | + $this->$method(); |
|
936 | + } |
|
937 | + |
|
938 | + $this->assertPreConditions(); |
|
939 | + $this->testResult = $this->runTest(); |
|
940 | + $this->verifyMockObjects(); |
|
941 | + $this->assertPostConditions(); |
|
942 | + |
|
943 | + if (!empty($this->warnings)) { |
|
944 | + throw new Warning( |
|
945 | + \implode( |
|
946 | + "\n", |
|
947 | + \array_unique($this->warnings) |
|
948 | + ) |
|
949 | + ); |
|
950 | + } |
|
951 | + |
|
952 | + $this->status = BaseTestRunner::STATUS_PASSED; |
|
953 | + } catch (IncompleteTest $e) { |
|
954 | + $this->status = BaseTestRunner::STATUS_INCOMPLETE; |
|
955 | + $this->statusMessage = $e->getMessage(); |
|
956 | + } catch (SkippedTest $e) { |
|
957 | + $this->status = BaseTestRunner::STATUS_SKIPPED; |
|
958 | + $this->statusMessage = $e->getMessage(); |
|
959 | + } catch (Warning $e) { |
|
960 | + $this->status = BaseTestRunner::STATUS_WARNING; |
|
961 | + $this->statusMessage = $e->getMessage(); |
|
962 | + } catch (AssertionFailedError $e) { |
|
963 | + $this->status = BaseTestRunner::STATUS_FAILURE; |
|
964 | + $this->statusMessage = $e->getMessage(); |
|
965 | + } catch (PredictionException $e) { |
|
966 | + $this->status = BaseTestRunner::STATUS_FAILURE; |
|
967 | + $this->statusMessage = $e->getMessage(); |
|
968 | + } catch (Throwable $_e) { |
|
969 | + $e = $_e; |
|
970 | + } |
|
971 | + |
|
972 | + if (isset($_e)) { |
|
973 | + $this->status = BaseTestRunner::STATUS_ERROR; |
|
974 | + $this->statusMessage = $_e->getMessage(); |
|
975 | + } |
|
976 | + |
|
977 | + // Clean up the mock objects. |
|
978 | + $this->mockObjects = []; |
|
979 | + $this->prophet = null; |
|
980 | + |
|
981 | + // Tear down the fixture. An exception raised in tearDown() will be |
|
982 | + // caught and passed on when no exception was raised before. |
|
983 | + try { |
|
984 | + if ($hasMetRequirements) { |
|
985 | + foreach ($hookMethods['after'] as $method) { |
|
986 | + $this->$method(); |
|
987 | + } |
|
988 | + |
|
989 | + if ($this->inIsolation) { |
|
990 | + foreach ($hookMethods['afterClass'] as $method) { |
|
991 | + $this->$method(); |
|
992 | + } |
|
993 | + } |
|
994 | + } |
|
995 | + } catch (Throwable $_e) { |
|
996 | + if (!isset($e)) { |
|
997 | + $e = $_e; |
|
998 | + } |
|
999 | + } |
|
1000 | + |
|
1001 | + try { |
|
1002 | + $this->stopOutputBuffering(); |
|
1003 | + } catch (RiskyTestError $_e) { |
|
1004 | + if (!isset($e)) { |
|
1005 | + $e = $_e; |
|
1006 | + } |
|
1007 | + } |
|
1008 | + |
|
1009 | + \clearstatcache(); |
|
1010 | + |
|
1011 | + if ($currentWorkingDirectory != \getcwd()) { |
|
1012 | + \chdir($currentWorkingDirectory); |
|
1013 | + } |
|
1014 | + |
|
1015 | + $this->restoreGlobalState(); |
|
1016 | + $this->unregisterCustomComparators(); |
|
1017 | + $this->cleanupIniSettings(); |
|
1018 | + $this->cleanupLocaleSettings(); |
|
1019 | + |
|
1020 | + // Perform assertion on output. |
|
1021 | + if (!isset($e)) { |
|
1022 | + try { |
|
1023 | + if ($this->outputExpectedRegex !== null) { |
|
1024 | + $this->assertRegExp($this->outputExpectedRegex, $this->output); |
|
1025 | + } elseif ($this->outputExpectedString !== null) { |
|
1026 | + $this->assertEquals($this->outputExpectedString, $this->output); |
|
1027 | + } |
|
1028 | + } catch (Throwable $_e) { |
|
1029 | + $e = $_e; |
|
1030 | + } |
|
1031 | + } |
|
1032 | + |
|
1033 | + // Workaround for missing "finally". |
|
1034 | + if (isset($e)) { |
|
1035 | + if ($e instanceof PredictionException) { |
|
1036 | + $e = new AssertionFailedError($e->getMessage()); |
|
1037 | + } |
|
1038 | + |
|
1039 | + $this->onNotSuccessfulTest($e); |
|
1040 | + } |
|
1041 | + } |
|
1042 | + |
|
1043 | + /** |
|
1044 | + * Override to run the test and assert its state. |
|
1045 | + * |
|
1046 | + * @return mixed |
|
1047 | + * |
|
1048 | + * @throws Exception|Exception |
|
1049 | + * @throws Exception |
|
1050 | + */ |
|
1051 | + protected function runTest() |
|
1052 | + { |
|
1053 | + if ($this->name === null) { |
|
1054 | + throw new Exception( |
|
1055 | + 'PHPUnit\Framework\TestCase::$name must not be null.' |
|
1056 | + ); |
|
1057 | + } |
|
1058 | + |
|
1059 | + try { |
|
1060 | + $class = new ReflectionClass($this); |
|
1061 | + $method = $class->getMethod($this->name); |
|
1062 | + } catch (ReflectionException $e) { |
|
1063 | + $this->fail($e->getMessage()); |
|
1064 | + } |
|
1065 | + |
|
1066 | + $testArguments = \array_merge($this->data, $this->dependencyInput); |
|
1067 | + |
|
1068 | + $this->registerMockObjectsFromTestArguments($testArguments); |
|
1069 | + |
|
1070 | + try { |
|
1071 | + $testResult = $method->invokeArgs($this, $testArguments); |
|
1072 | + } catch (Throwable $t) { |
|
1073 | + $exception = $t; |
|
1074 | + } |
|
1075 | + |
|
1076 | + if (isset($exception)) { |
|
1077 | + if ($this->checkExceptionExpectations($exception)) { |
|
1078 | + if ($this->expectedException !== null) { |
|
1079 | + $this->assertThat( |
|
1080 | + $exception, |
|
1081 | + new ExceptionConstraint( |
|
1082 | + $this->expectedException |
|
1083 | + ) |
|
1084 | + ); |
|
1085 | + } |
|
1086 | + |
|
1087 | + if ($this->expectedExceptionMessage !== null) { |
|
1088 | + $this->assertThat( |
|
1089 | + $exception, |
|
1090 | + new ExceptionMessage( |
|
1091 | + $this->expectedExceptionMessage |
|
1092 | + ) |
|
1093 | + ); |
|
1094 | + } |
|
1095 | + |
|
1096 | + if ($this->expectedExceptionMessageRegExp !== null) { |
|
1097 | + $this->assertThat( |
|
1098 | + $exception, |
|
1099 | + new ExceptionMessageRegularExpression( |
|
1100 | + $this->expectedExceptionMessageRegExp |
|
1101 | + ) |
|
1102 | + ); |
|
1103 | + } |
|
1104 | + |
|
1105 | + if ($this->expectedExceptionCode !== null) { |
|
1106 | + $this->assertThat( |
|
1107 | + $exception, |
|
1108 | + new ExceptionCode( |
|
1109 | + $this->expectedExceptionCode |
|
1110 | + ) |
|
1111 | + ); |
|
1112 | + } |
|
1113 | + |
|
1114 | + return; |
|
1115 | + } |
|
1116 | + |
|
1117 | + throw $exception; |
|
1118 | + } |
|
1119 | + |
|
1120 | + if ($this->expectedException !== null) { |
|
1121 | + $this->assertThat( |
|
1122 | + null, |
|
1123 | + new ExceptionConstraint( |
|
1124 | + $this->expectedException |
|
1125 | + ) |
|
1126 | + ); |
|
1127 | + } elseif ($this->expectedExceptionMessage !== null) { |
|
1128 | + $this->numAssertions++; |
|
1129 | + |
|
1130 | + throw new AssertionFailedError( |
|
1131 | + \sprintf( |
|
1132 | + 'Failed asserting that exception with message "%s" is thrown', |
|
1133 | + $this->expectedExceptionMessage |
|
1134 | + ) |
|
1135 | + ); |
|
1136 | + } elseif ($this->expectedExceptionMessageRegExp !== null) { |
|
1137 | + $this->numAssertions++; |
|
1138 | + |
|
1139 | + throw new AssertionFailedError( |
|
1140 | + \sprintf( |
|
1141 | + 'Failed asserting that exception with message matching "%s" is thrown', |
|
1142 | + $this->expectedExceptionMessageRegExp |
|
1143 | + ) |
|
1144 | + ); |
|
1145 | + } elseif ($this->expectedExceptionCode !== null) { |
|
1146 | + $this->numAssertions++; |
|
1147 | + |
|
1148 | + throw new AssertionFailedError( |
|
1149 | + \sprintf( |
|
1150 | + 'Failed asserting that exception with code "%s" is thrown', |
|
1151 | + $this->expectedExceptionCode |
|
1152 | + ) |
|
1153 | + ); |
|
1154 | + } |
|
1155 | + |
|
1156 | + return $testResult; |
|
1157 | + } |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * Verifies the mock object expectations. |
|
1161 | + */ |
|
1162 | + protected function verifyMockObjects() |
|
1163 | + { |
|
1164 | + foreach ($this->mockObjects as $mockObject) { |
|
1165 | + if ($mockObject->__phpunit_hasMatchers()) { |
|
1166 | + $this->numAssertions++; |
|
1167 | + } |
|
1168 | + |
|
1169 | + $mockObject->__phpunit_verify( |
|
1170 | + $this->shouldInvocationMockerBeReset($mockObject) |
|
1171 | + ); |
|
1172 | + } |
|
1173 | + |
|
1174 | + if ($this->prophet !== null) { |
|
1175 | + try { |
|
1176 | + $this->prophet->checkPredictions(); |
|
1177 | + } catch (Throwable $t) { |
|
1178 | + /* Intentionally left empty */ |
|
1179 | + } |
|
1180 | + |
|
1181 | + foreach ($this->prophet->getProphecies() as $objectProphecy) { |
|
1182 | + foreach ($objectProphecy->getMethodProphecies() as $methodProphecies) { |
|
1183 | + foreach ($methodProphecies as $methodProphecy) { |
|
1184 | + $this->numAssertions += \count($methodProphecy->getCheckedPredictions()); |
|
1185 | + } |
|
1186 | + } |
|
1187 | + } |
|
1188 | + |
|
1189 | + if (isset($t)) { |
|
1190 | + throw $t; |
|
1191 | + } |
|
1192 | + } |
|
1193 | + } |
|
1194 | + |
|
1195 | + /** |
|
1196 | + * Sets the name of a TestCase. |
|
1197 | + * |
|
1198 | + * @param string |
|
1199 | + */ |
|
1200 | + public function setName($name) |
|
1201 | + { |
|
1202 | + $this->name = $name; |
|
1203 | + } |
|
1204 | + |
|
1205 | + /** |
|
1206 | + * Sets the dependencies of a TestCase. |
|
1207 | + * |
|
1208 | + * @param string[] $dependencies |
|
1209 | + */ |
|
1210 | + public function setDependencies(array $dependencies) |
|
1211 | + { |
|
1212 | + $this->dependencies = $dependencies; |
|
1213 | + } |
|
1214 | + |
|
1215 | + /** |
|
1216 | + * Returns true if the tests has dependencies |
|
1217 | + * |
|
1218 | + * @return bool |
|
1219 | + */ |
|
1220 | + public function hasDependencies() |
|
1221 | + { |
|
1222 | + return \count($this->dependencies) > 0; |
|
1223 | + } |
|
1224 | + |
|
1225 | + /** |
|
1226 | + * Sets |
|
1227 | + * |
|
1228 | + * @param array $dependencyInput |
|
1229 | + */ |
|
1230 | + public function setDependencyInput(array $dependencyInput) |
|
1231 | + { |
|
1232 | + $this->dependencyInput = $dependencyInput; |
|
1233 | + } |
|
1234 | + |
|
1235 | + /** |
|
1236 | + * @param bool $beStrictAboutChangesToGlobalState |
|
1237 | + */ |
|
1238 | + public function setBeStrictAboutChangesToGlobalState($beStrictAboutChangesToGlobalState) |
|
1239 | + { |
|
1240 | + $this->beStrictAboutChangesToGlobalState = $beStrictAboutChangesToGlobalState; |
|
1241 | + } |
|
1242 | + |
|
1243 | + /** |
|
1244 | + * Calling this method in setUp() has no effect! |
|
1245 | + * |
|
1246 | + * @param bool $backupGlobals |
|
1247 | + */ |
|
1248 | + public function setBackupGlobals($backupGlobals) |
|
1249 | + { |
|
1250 | + if (null === $this->backupGlobals && \is_bool($backupGlobals)) { |
|
1251 | + $this->backupGlobals = $backupGlobals; |
|
1252 | + } |
|
1253 | + } |
|
1254 | + |
|
1255 | + /** |
|
1256 | + * Calling this method in setUp() has no effect! |
|
1257 | + * |
|
1258 | + * @param bool $backupStaticAttributes |
|
1259 | + */ |
|
1260 | + public function setBackupStaticAttributes($backupStaticAttributes) |
|
1261 | + { |
|
1262 | + if (null === $this->backupStaticAttributes && |
|
1263 | + \is_bool($backupStaticAttributes)) { |
|
1264 | + $this->backupStaticAttributes = $backupStaticAttributes; |
|
1265 | + } |
|
1266 | + } |
|
1267 | + |
|
1268 | + /** |
|
1269 | + * @param bool $runTestInSeparateProcess |
|
1270 | + * |
|
1271 | + * @throws Exception |
|
1272 | + */ |
|
1273 | + public function setRunTestInSeparateProcess($runTestInSeparateProcess) |
|
1274 | + { |
|
1275 | + if (\is_bool($runTestInSeparateProcess)) { |
|
1276 | + if ($this->runTestInSeparateProcess === null) { |
|
1277 | + $this->runTestInSeparateProcess = $runTestInSeparateProcess; |
|
1278 | + } |
|
1279 | + } else { |
|
1280 | + throw InvalidArgumentHelper::factory(1, 'boolean'); |
|
1281 | + } |
|
1282 | + } |
|
1283 | + |
|
1284 | + /** |
|
1285 | + * @param bool $runClassInSeparateProcess |
|
1286 | + * |
|
1287 | + * @throws Exception |
|
1288 | + */ |
|
1289 | + public function setRunClassInSeparateProcess($runClassInSeparateProcess) |
|
1290 | + { |
|
1291 | + if (\is_bool($runClassInSeparateProcess)) { |
|
1292 | + if ($this->runClassInSeparateProcess === null) { |
|
1293 | + $this->runClassInSeparateProcess = $runClassInSeparateProcess; |
|
1294 | + } |
|
1295 | + } else { |
|
1296 | + throw InvalidArgumentHelper::factory(1, 'boolean'); |
|
1297 | + } |
|
1298 | + } |
|
1299 | + |
|
1300 | + /** |
|
1301 | + * @param bool $preserveGlobalState |
|
1302 | + * |
|
1303 | + * @throws Exception |
|
1304 | + */ |
|
1305 | + public function setPreserveGlobalState($preserveGlobalState) |
|
1306 | + { |
|
1307 | + if (\is_bool($preserveGlobalState)) { |
|
1308 | + $this->preserveGlobalState = $preserveGlobalState; |
|
1309 | + } else { |
|
1310 | + throw InvalidArgumentHelper::factory(1, 'boolean'); |
|
1311 | + } |
|
1312 | + } |
|
1313 | + |
|
1314 | + /** |
|
1315 | + * @param bool $inIsolation |
|
1316 | + * |
|
1317 | + * @throws Exception |
|
1318 | + */ |
|
1319 | + public function setInIsolation($inIsolation) |
|
1320 | + { |
|
1321 | + if (\is_bool($inIsolation)) { |
|
1322 | + $this->inIsolation = $inIsolation; |
|
1323 | + } else { |
|
1324 | + throw InvalidArgumentHelper::factory(1, 'boolean'); |
|
1325 | + } |
|
1326 | + } |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * @return bool |
|
1330 | + */ |
|
1331 | + public function isInIsolation() |
|
1332 | + { |
|
1333 | + return $this->inIsolation; |
|
1334 | + } |
|
1335 | + |
|
1336 | + /** |
|
1337 | + * @return mixed |
|
1338 | + */ |
|
1339 | + public function getResult() |
|
1340 | + { |
|
1341 | + return $this->testResult; |
|
1342 | + } |
|
1343 | + |
|
1344 | + /** |
|
1345 | + * @param mixed $result |
|
1346 | + */ |
|
1347 | + public function setResult($result) |
|
1348 | + { |
|
1349 | + $this->testResult = $result; |
|
1350 | + } |
|
1351 | + |
|
1352 | + /** |
|
1353 | + * @param callable $callback |
|
1354 | + * |
|
1355 | + * @throws Exception |
|
1356 | + */ |
|
1357 | + public function setOutputCallback($callback) |
|
1358 | + { |
|
1359 | + if (!\is_callable($callback)) { |
|
1360 | + throw InvalidArgumentHelper::factory(1, 'callback'); |
|
1361 | + } |
|
1362 | + |
|
1363 | + $this->outputCallback = $callback; |
|
1364 | + } |
|
1365 | + |
|
1366 | + /** |
|
1367 | + * @return TestResult |
|
1368 | + */ |
|
1369 | + public function getTestResultObject() |
|
1370 | + { |
|
1371 | + return $this->result; |
|
1372 | + } |
|
1373 | + |
|
1374 | + /** |
|
1375 | + * @param TestResult $result |
|
1376 | + */ |
|
1377 | + public function setTestResultObject(TestResult $result) |
|
1378 | + { |
|
1379 | + $this->result = $result; |
|
1380 | + } |
|
1381 | + |
|
1382 | + /** |
|
1383 | + * @param PHPUnit_Framework_MockObject_MockObject $mockObject |
|
1384 | + */ |
|
1385 | + public function registerMockObject(PHPUnit_Framework_MockObject_MockObject $mockObject) |
|
1386 | + { |
|
1387 | + $this->mockObjects[] = $mockObject; |
|
1388 | + } |
|
1389 | + |
|
1390 | + /** |
|
1391 | + * This method is a wrapper for the ini_set() function that automatically |
|
1392 | + * resets the modified php.ini setting to its original value after the |
|
1393 | + * test is run. |
|
1394 | + * |
|
1395 | + * @param string $varName |
|
1396 | + * @param string $newValue |
|
1397 | + * |
|
1398 | + * @throws Exception |
|
1399 | + */ |
|
1400 | + protected function iniSet($varName, $newValue) |
|
1401 | + { |
|
1402 | + if (!\is_string($varName)) { |
|
1403 | + throw InvalidArgumentHelper::factory(1, 'string'); |
|
1404 | + } |
|
1405 | + |
|
1406 | + $currentValue = \ini_set($varName, $newValue); |
|
1407 | + |
|
1408 | + if ($currentValue !== false) { |
|
1409 | + $this->iniSettings[$varName] = $currentValue; |
|
1410 | + } else { |
|
1411 | + throw new Exception( |
|
1412 | + \sprintf( |
|
1413 | + 'INI setting "%s" could not be set to "%s".', |
|
1414 | + $varName, |
|
1415 | + $newValue |
|
1416 | + ) |
|
1417 | + ); |
|
1418 | + } |
|
1419 | + } |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * This method is a wrapper for the setlocale() function that automatically |
|
1423 | + * resets the locale to its original value after the test is run. |
|
1424 | + * |
|
1425 | + * @param int $category |
|
1426 | + * @param string $locale |
|
1427 | + * |
|
1428 | + * @throws Exception |
|
1429 | + */ |
|
1430 | + protected function setLocale() |
|
1431 | + { |
|
1432 | + $args = \func_get_args(); |
|
1433 | + |
|
1434 | + if (\count($args) < 2) { |
|
1435 | + throw new Exception; |
|
1436 | + } |
|
1437 | + |
|
1438 | + list($category, $locale) = $args; |
|
1439 | + |
|
1440 | + $categories = [ |
|
1441 | + LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME |
|
1442 | + ]; |
|
1443 | + |
|
1444 | + if (\defined('LC_MESSAGES')) { |
|
1445 | + $categories[] = LC_MESSAGES; |
|
1446 | + } |
|
1447 | + |
|
1448 | + if (!\in_array($category, $categories)) { |
|
1449 | + throw new Exception; |
|
1450 | + } |
|
1451 | + |
|
1452 | + if (!\is_array($locale) && !\is_string($locale)) { |
|
1453 | + throw new Exception; |
|
1454 | + } |
|
1455 | + |
|
1456 | + $this->locale[$category] = \setlocale($category, 0); |
|
1457 | + |
|
1458 | + $result = \call_user_func_array('setlocale', $args); |
|
1459 | + |
|
1460 | + if ($result === false) { |
|
1461 | + throw new Exception( |
|
1462 | + 'The locale functionality is not implemented on your platform, ' . |
|
1463 | + 'the specified locale does not exist or the category name is ' . |
|
1464 | + 'invalid.' |
|
1465 | + ); |
|
1466 | + } |
|
1467 | + } |
|
1468 | + |
|
1469 | + /** |
|
1470 | + * Returns a builder object to create mock objects using a fluent interface. |
|
1471 | + * |
|
1472 | + * @param string|string[] $className |
|
1473 | + * |
|
1474 | + * @return PHPUnit_Framework_MockObject_MockBuilder |
|
1475 | + */ |
|
1476 | + public function getMockBuilder($className) |
|
1477 | + { |
|
1478 | + return new PHPUnit_Framework_MockObject_MockBuilder($this, $className); |
|
1479 | + } |
|
1480 | + |
|
1481 | + /** |
|
1482 | + * Returns a test double for the specified class. |
|
1483 | + * |
|
1484 | + * @param string $originalClassName |
|
1485 | + * |
|
1486 | + * @return PHPUnit_Framework_MockObject_MockObject |
|
1487 | + * |
|
1488 | + * @throws Exception |
|
1489 | + */ |
|
1490 | + protected function createMock($originalClassName) |
|
1491 | + { |
|
1492 | + return $this->getMockBuilder($originalClassName) |
|
1493 | + ->disableOriginalConstructor() |
|
1494 | + ->disableOriginalClone() |
|
1495 | + ->disableArgumentCloning() |
|
1496 | + ->disallowMockingUnknownTypes() |
|
1497 | + ->getMock(); |
|
1498 | + } |
|
1499 | + |
|
1500 | + /** |
|
1501 | + * Returns a configured test double for the specified class. |
|
1502 | + * |
|
1503 | + * @param string $originalClassName |
|
1504 | + * @param array $configuration |
|
1505 | + * |
|
1506 | + * @return PHPUnit_Framework_MockObject_MockObject |
|
1507 | + * |
|
1508 | + * @throws Exception |
|
1509 | + */ |
|
1510 | + protected function createConfiguredMock($originalClassName, array $configuration) |
|
1511 | + { |
|
1512 | + $o = $this->createMock($originalClassName); |
|
1513 | + |
|
1514 | + foreach ($configuration as $method => $return) { |
|
1515 | + $o->method($method)->willReturn($return); |
|
1516 | + } |
|
1517 | + |
|
1518 | + return $o; |
|
1519 | + } |
|
1520 | + |
|
1521 | + /** |
|
1522 | + * Returns a partial test double for the specified class. |
|
1523 | + * |
|
1524 | + * @param string $originalClassName |
|
1525 | + * @param string[] $methods |
|
1526 | + * |
|
1527 | + * @return PHPUnit_Framework_MockObject_MockObject |
|
1528 | + * |
|
1529 | + * @throws Exception |
|
1530 | + */ |
|
1531 | + protected function createPartialMock($originalClassName, array $methods) |
|
1532 | + { |
|
1533 | + return $this->getMockBuilder($originalClassName) |
|
1534 | + ->disableOriginalConstructor() |
|
1535 | + ->disableOriginalClone() |
|
1536 | + ->disableArgumentCloning() |
|
1537 | + ->disallowMockingUnknownTypes() |
|
1538 | + ->setMethods(empty($methods) ? null : $methods) |
|
1539 | + ->getMock(); |
|
1540 | + } |
|
1541 | + |
|
1542 | + /** |
|
1543 | + * Returns a test proxy for the specified class. |
|
1544 | + * |
|
1545 | + * @param string $originalClassName |
|
1546 | + * @param array $constructorArguments |
|
1547 | + * |
|
1548 | + * @return PHPUnit_Framework_MockObject_MockObject |
|
1549 | + * |
|
1550 | + * @throws Exception |
|
1551 | + */ |
|
1552 | + protected function createTestProxy($originalClassName, array $constructorArguments = []) |
|
1553 | + { |
|
1554 | + return $this->getMockBuilder($originalClassName) |
|
1555 | + ->setConstructorArgs($constructorArguments) |
|
1556 | + ->enableProxyingToOriginalMethods() |
|
1557 | + ->getMock(); |
|
1558 | + } |
|
1559 | + |
|
1560 | + /** |
|
1561 | + * Mocks the specified class and returns the name of the mocked class. |
|
1562 | + * |
|
1563 | + * @param string $originalClassName |
|
1564 | + * @param array $methods |
|
1565 | + * @param array $arguments |
|
1566 | + * @param string $mockClassName |
|
1567 | + * @param bool $callOriginalConstructor |
|
1568 | + * @param bool $callOriginalClone |
|
1569 | + * @param bool $callAutoload |
|
1570 | + * @param bool $cloneArguments |
|
1571 | + * |
|
1572 | + * @return string |
|
1573 | + * |
|
1574 | + * @throws Exception |
|
1575 | + */ |
|
1576 | + protected function getMockClass($originalClassName, $methods = [], array $arguments = [], $mockClassName = '', $callOriginalConstructor = false, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false) |
|
1577 | + { |
|
1578 | + $mock = $this->getMockObjectGenerator()->getMock( |
|
1579 | + $originalClassName, |
|
1580 | + $methods, |
|
1581 | + $arguments, |
|
1582 | + $mockClassName, |
|
1583 | + $callOriginalConstructor, |
|
1584 | + $callOriginalClone, |
|
1585 | + $callAutoload, |
|
1586 | + $cloneArguments |
|
1587 | + ); |
|
1588 | + |
|
1589 | + return \get_class($mock); |
|
1590 | + } |
|
1591 | + |
|
1592 | + /** |
|
1593 | + * Returns a mock object for the specified abstract class with all abstract |
|
1594 | + * methods of the class mocked. Concrete methods are not mocked by default. |
|
1595 | + * To mock concrete methods, use the 7th parameter ($mockedMethods). |
|
1596 | + * |
|
1597 | + * @param string $originalClassName |
|
1598 | + * @param array $arguments |
|
1599 | + * @param string $mockClassName |
|
1600 | + * @param bool $callOriginalConstructor |
|
1601 | + * @param bool $callOriginalClone |
|
1602 | + * @param bool $callAutoload |
|
1603 | + * @param array $mockedMethods |
|
1604 | + * @param bool $cloneArguments |
|
1605 | + * |
|
1606 | + * @return PHPUnit_Framework_MockObject_MockObject |
|
1607 | + * |
|
1608 | + * @throws Exception |
|
1609 | + */ |
|
1610 | + protected function getMockForAbstractClass($originalClassName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = false) |
|
1611 | + { |
|
1612 | + $mockObject = $this->getMockObjectGenerator()->getMockForAbstractClass( |
|
1613 | + $originalClassName, |
|
1614 | + $arguments, |
|
1615 | + $mockClassName, |
|
1616 | + $callOriginalConstructor, |
|
1617 | + $callOriginalClone, |
|
1618 | + $callAutoload, |
|
1619 | + $mockedMethods, |
|
1620 | + $cloneArguments |
|
1621 | + ); |
|
1622 | + |
|
1623 | + $this->registerMockObject($mockObject); |
|
1624 | + |
|
1625 | + return $mockObject; |
|
1626 | + } |
|
1627 | + |
|
1628 | + /** |
|
1629 | + * Returns a mock object based on the given WSDL file. |
|
1630 | + * |
|
1631 | + * @param string $wsdlFile |
|
1632 | + * @param string $originalClassName |
|
1633 | + * @param string $mockClassName |
|
1634 | + * @param array $methods |
|
1635 | + * @param bool $callOriginalConstructor |
|
1636 | + * @param array $options An array of options passed to SOAPClient::_construct |
|
1637 | + * |
|
1638 | + * @return PHPUnit_Framework_MockObject_MockObject |
|
1639 | + */ |
|
1640 | + protected function getMockFromWsdl($wsdlFile, $originalClassName = '', $mockClassName = '', array $methods = [], $callOriginalConstructor = true, array $options = []) |
|
1641 | + { |
|
1642 | + if ($originalClassName === '') { |
|
1643 | + $originalClassName = \pathinfo(\basename(\parse_url($wsdlFile)['path']), PATHINFO_FILENAME); |
|
1644 | + } |
|
1645 | + |
|
1646 | + if (!\class_exists($originalClassName)) { |
|
1647 | + eval( |
|
1648 | + $this->getMockObjectGenerator()->generateClassFromWsdl( |
|
1649 | + $wsdlFile, |
|
1650 | + $originalClassName, |
|
1651 | + $methods, |
|
1652 | + $options |
|
1653 | + ) |
|
1654 | + ); |
|
1655 | + } |
|
1656 | + |
|
1657 | + $mockObject = $this->getMockObjectGenerator()->getMock( |
|
1658 | + $originalClassName, |
|
1659 | + $methods, |
|
1660 | + ['', $options], |
|
1661 | + $mockClassName, |
|
1662 | + $callOriginalConstructor, |
|
1663 | + false, |
|
1664 | + false |
|
1665 | + ); |
|
1666 | + |
|
1667 | + $this->registerMockObject($mockObject); |
|
1668 | + |
|
1669 | + return $mockObject; |
|
1670 | + } |
|
1671 | + |
|
1672 | + /** |
|
1673 | + * Returns a mock object for the specified trait with all abstract methods |
|
1674 | + * of the trait mocked. Concrete methods to mock can be specified with the |
|
1675 | + * `$mockedMethods` parameter. |
|
1676 | + * |
|
1677 | + * @param string $traitName |
|
1678 | + * @param array $arguments |
|
1679 | + * @param string $mockClassName |
|
1680 | + * @param bool $callOriginalConstructor |
|
1681 | + * @param bool $callOriginalClone |
|
1682 | + * @param bool $callAutoload |
|
1683 | + * @param array $mockedMethods |
|
1684 | + * @param bool $cloneArguments |
|
1685 | + * |
|
1686 | + * @return PHPUnit_Framework_MockObject_MockObject |
|
1687 | + * |
|
1688 | + * @throws Exception |
|
1689 | + */ |
|
1690 | + protected function getMockForTrait($traitName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = false) |
|
1691 | + { |
|
1692 | + $mockObject = $this->getMockObjectGenerator()->getMockForTrait( |
|
1693 | + $traitName, |
|
1694 | + $arguments, |
|
1695 | + $mockClassName, |
|
1696 | + $callOriginalConstructor, |
|
1697 | + $callOriginalClone, |
|
1698 | + $callAutoload, |
|
1699 | + $mockedMethods, |
|
1700 | + $cloneArguments |
|
1701 | + ); |
|
1702 | + |
|
1703 | + $this->registerMockObject($mockObject); |
|
1704 | + |
|
1705 | + return $mockObject; |
|
1706 | + } |
|
1707 | + |
|
1708 | + /** |
|
1709 | + * Returns an object for the specified trait. |
|
1710 | + * |
|
1711 | + * @param string $traitName |
|
1712 | + * @param array $arguments |
|
1713 | + * @param string $traitClassName |
|
1714 | + * @param bool $callOriginalConstructor |
|
1715 | + * @param bool $callOriginalClone |
|
1716 | + * @param bool $callAutoload |
|
1717 | + * |
|
1718 | + * @return object |
|
1719 | + * |
|
1720 | + * @throws Exception |
|
1721 | + */ |
|
1722 | + protected function getObjectForTrait($traitName, array $arguments = [], $traitClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true) |
|
1723 | + { |
|
1724 | + return $this->getMockObjectGenerator()->getObjectForTrait( |
|
1725 | + $traitName, |
|
1726 | + $arguments, |
|
1727 | + $traitClassName, |
|
1728 | + $callOriginalConstructor, |
|
1729 | + $callOriginalClone, |
|
1730 | + $callAutoload |
|
1731 | + ); |
|
1732 | + } |
|
1733 | + |
|
1734 | + /** |
|
1735 | + * @param string|null $classOrInterface |
|
1736 | + * |
|
1737 | + * @return \Prophecy\Prophecy\ObjectProphecy |
|
1738 | + * |
|
1739 | + * @throws \LogicException |
|
1740 | + */ |
|
1741 | + protected function prophesize($classOrInterface = null) |
|
1742 | + { |
|
1743 | + return $this->getProphet()->prophesize($classOrInterface); |
|
1744 | + } |
|
1745 | + |
|
1746 | + /** |
|
1747 | + * Adds a value to the assertion counter. |
|
1748 | + * |
|
1749 | + * @param int $count |
|
1750 | + */ |
|
1751 | + public function addToAssertionCount($count) |
|
1752 | + { |
|
1753 | + $this->numAssertions += $count; |
|
1754 | + } |
|
1755 | + |
|
1756 | + /** |
|
1757 | + * Returns the number of assertions performed by this test. |
|
1758 | + * |
|
1759 | + * @return int |
|
1760 | + */ |
|
1761 | + public function getNumAssertions() |
|
1762 | + { |
|
1763 | + return $this->numAssertions; |
|
1764 | + } |
|
1765 | + |
|
1766 | + /** |
|
1767 | + * Returns a matcher that matches when the method is executed |
|
1768 | + * zero or more times. |
|
1769 | + * |
|
1770 | + * @return PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount |
|
1771 | + */ |
|
1772 | + public static function any() |
|
1773 | + { |
|
1774 | + return new PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount; |
|
1775 | + } |
|
1776 | + |
|
1777 | + /** |
|
1778 | + * Returns a matcher that matches when the method is never executed. |
|
1779 | + * |
|
1780 | + * @return PHPUnit_Framework_MockObject_Matcher_InvokedCount |
|
1781 | + */ |
|
1782 | + public static function never() |
|
1783 | + { |
|
1784 | + return new PHPUnit_Framework_MockObject_Matcher_InvokedCount(0); |
|
1785 | + } |
|
1786 | + |
|
1787 | + /** |
|
1788 | + * Returns a matcher that matches when the method is executed |
|
1789 | + * at least N times. |
|
1790 | + * |
|
1791 | + * @param int $requiredInvocations |
|
1792 | + * |
|
1793 | + * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastCount |
|
1794 | + */ |
|
1795 | + public static function atLeast($requiredInvocations) |
|
1796 | + { |
|
1797 | + return new PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastCount( |
|
1798 | + $requiredInvocations |
|
1799 | + ); |
|
1800 | + } |
|
1801 | + |
|
1802 | + /** |
|
1803 | + * Returns a matcher that matches when the method is executed at least once. |
|
1804 | + * |
|
1805 | + * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce |
|
1806 | + */ |
|
1807 | + public static function atLeastOnce() |
|
1808 | + { |
|
1809 | + return new PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce; |
|
1810 | + } |
|
1811 | + |
|
1812 | + /** |
|
1813 | + * Returns a matcher that matches when the method is executed exactly once. |
|
1814 | + * |
|
1815 | + * @return PHPUnit_Framework_MockObject_Matcher_InvokedCount |
|
1816 | + */ |
|
1817 | + public static function once() |
|
1818 | + { |
|
1819 | + return new PHPUnit_Framework_MockObject_Matcher_InvokedCount(1); |
|
1820 | + } |
|
1821 | + |
|
1822 | + /** |
|
1823 | + * Returns a matcher that matches when the method is executed |
|
1824 | + * exactly $count times. |
|
1825 | + * |
|
1826 | + * @param int $count |
|
1827 | + * |
|
1828 | + * @return PHPUnit_Framework_MockObject_Matcher_InvokedCount |
|
1829 | + */ |
|
1830 | + public static function exactly($count) |
|
1831 | + { |
|
1832 | + return new PHPUnit_Framework_MockObject_Matcher_InvokedCount($count); |
|
1833 | + } |
|
1834 | + |
|
1835 | + /** |
|
1836 | + * Returns a matcher that matches when the method is executed |
|
1837 | + * at most N times. |
|
1838 | + * |
|
1839 | + * @param int $allowedInvocations |
|
1840 | + * |
|
1841 | + * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtMostCount |
|
1842 | + */ |
|
1843 | + public static function atMost($allowedInvocations) |
|
1844 | + { |
|
1845 | + return new PHPUnit_Framework_MockObject_Matcher_InvokedAtMostCount( |
|
1846 | + $allowedInvocations |
|
1847 | + ); |
|
1848 | + } |
|
1849 | + |
|
1850 | + /** |
|
1851 | + * Returns a matcher that matches when the method is executed |
|
1852 | + * at the given index. |
|
1853 | + * |
|
1854 | + * @param int $index |
|
1855 | + * |
|
1856 | + * @return PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex |
|
1857 | + */ |
|
1858 | + public static function at($index) |
|
1859 | + { |
|
1860 | + return new PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex($index); |
|
1861 | + } |
|
1862 | + |
|
1863 | + /** |
|
1864 | + * @param mixed $value |
|
1865 | + * |
|
1866 | + * @return PHPUnit_Framework_MockObject_Stub_Return |
|
1867 | + */ |
|
1868 | + public static function returnValue($value) |
|
1869 | + { |
|
1870 | + return new PHPUnit_Framework_MockObject_Stub_Return($value); |
|
1871 | + } |
|
1872 | + |
|
1873 | + /** |
|
1874 | + * @param array $valueMap |
|
1875 | + * |
|
1876 | + * @return PHPUnit_Framework_MockObject_Stub_ReturnValueMap |
|
1877 | + */ |
|
1878 | + public static function returnValueMap(array $valueMap) |
|
1879 | + { |
|
1880 | + return new PHPUnit_Framework_MockObject_Stub_ReturnValueMap($valueMap); |
|
1881 | + } |
|
1882 | + |
|
1883 | + /** |
|
1884 | + * @param int $argumentIndex |
|
1885 | + * |
|
1886 | + * @return PHPUnit_Framework_MockObject_Stub_ReturnArgument |
|
1887 | + */ |
|
1888 | + public static function returnArgument($argumentIndex) |
|
1889 | + { |
|
1890 | + return new PHPUnit_Framework_MockObject_Stub_ReturnArgument( |
|
1891 | + $argumentIndex |
|
1892 | + ); |
|
1893 | + } |
|
1894 | + |
|
1895 | + /** |
|
1896 | + * @param mixed $callback |
|
1897 | + * |
|
1898 | + * @return PHPUnit_Framework_MockObject_Stub_ReturnCallback |
|
1899 | + */ |
|
1900 | + public static function returnCallback($callback) |
|
1901 | + { |
|
1902 | + return new PHPUnit_Framework_MockObject_Stub_ReturnCallback($callback); |
|
1903 | + } |
|
1904 | + |
|
1905 | + /** |
|
1906 | + * Returns the current object. |
|
1907 | + * |
|
1908 | + * This method is useful when mocking a fluent interface. |
|
1909 | + * |
|
1910 | + * @return PHPUnit_Framework_MockObject_Stub_ReturnSelf |
|
1911 | + */ |
|
1912 | + public static function returnSelf() |
|
1913 | + { |
|
1914 | + return new PHPUnit_Framework_MockObject_Stub_ReturnSelf(); |
|
1915 | + } |
|
1916 | + |
|
1917 | + /** |
|
1918 | + * @param Throwable $exception |
|
1919 | + * |
|
1920 | + * @return PHPUnit_Framework_MockObject_Stub_Exception |
|
1921 | + */ |
|
1922 | + public static function throwException(Throwable $exception) |
|
1923 | + { |
|
1924 | + return new PHPUnit_Framework_MockObject_Stub_Exception($exception); |
|
1925 | + } |
|
1926 | + |
|
1927 | + /** |
|
1928 | + * @param mixed $value , ... |
|
1929 | + * |
|
1930 | + * @return PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls |
|
1931 | + */ |
|
1932 | + public static function onConsecutiveCalls() |
|
1933 | + { |
|
1934 | + $args = \func_get_args(); |
|
1935 | + |
|
1936 | + return new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls($args); |
|
1937 | + } |
|
1938 | + |
|
1939 | + /** |
|
1940 | + * @return bool |
|
1941 | + */ |
|
1942 | + public function usesDataProvider() |
|
1943 | + { |
|
1944 | + return !empty($this->data); |
|
1945 | + } |
|
1946 | + |
|
1947 | + /** |
|
1948 | + * @return string |
|
1949 | + */ |
|
1950 | + public function dataDescription() |
|
1951 | + { |
|
1952 | + return \is_string($this->dataName) ? $this->dataName : ''; |
|
1953 | + } |
|
1954 | + |
|
1955 | + public function registerComparator(Comparator $comparator) |
|
1956 | + { |
|
1957 | + ComparatorFactory::getInstance()->register($comparator); |
|
1958 | + |
|
1959 | + $this->customComparators[] = $comparator; |
|
1960 | + } |
|
1961 | + |
|
1962 | + /** |
|
1963 | + * Gets the data set description of a TestCase. |
|
1964 | + * |
|
1965 | + * @param bool $includeData |
|
1966 | + * |
|
1967 | + * @return string |
|
1968 | + */ |
|
1969 | + public function getDataSetAsString($includeData = true) |
|
1970 | + { |
|
1971 | + $buffer = ''; |
|
1972 | + |
|
1973 | + if (!empty($this->data)) { |
|
1974 | + if (\is_int($this->dataName)) { |
|
1975 | + $buffer .= \sprintf(' with data set #%d', $this->dataName); |
|
1976 | + } else { |
|
1977 | + $buffer .= \sprintf(' with data set "%s"', $this->dataName); |
|
1978 | + } |
|
1979 | + |
|
1980 | + $exporter = new Exporter; |
|
1981 | + |
|
1982 | + if ($includeData) { |
|
1983 | + $buffer .= \sprintf(' (%s)', $exporter->shortenedRecursiveExport($this->data)); |
|
1984 | + } |
|
1985 | + } |
|
1986 | + |
|
1987 | + return $buffer; |
|
1988 | + } |
|
1989 | + |
|
1990 | + /** |
|
1991 | + * Gets the data set of a TestCase. |
|
1992 | + * |
|
1993 | + * @return array |
|
1994 | + */ |
|
1995 | + protected function getProvidedData() |
|
1996 | + { |
|
1997 | + return $this->data; |
|
1998 | + } |
|
1999 | + |
|
2000 | + /** |
|
2001 | + * Creates a default TestResult object. |
|
2002 | + * |
|
2003 | + * @return TestResult |
|
2004 | + */ |
|
2005 | + protected function createResult() |
|
2006 | + { |
|
2007 | + return new TestResult; |
|
2008 | + } |
|
2009 | + |
|
2010 | + protected function handleDependencies() |
|
2011 | + { |
|
2012 | + if (!empty($this->dependencies) && !$this->inIsolation) { |
|
2013 | + $className = \get_class($this); |
|
2014 | + $passed = $this->result->passed(); |
|
2015 | + $passedKeys = \array_keys($passed); |
|
2016 | + $numKeys = \count($passedKeys); |
|
2017 | + |
|
2018 | + for ($i = 0; $i < $numKeys; $i++) { |
|
2019 | + $pos = \strpos($passedKeys[$i], ' with data set'); |
|
2020 | + |
|
2021 | + if ($pos !== false) { |
|
2022 | + $passedKeys[$i] = \substr($passedKeys[$i], 0, $pos); |
|
2023 | + } |
|
2024 | + } |
|
2025 | + |
|
2026 | + $passedKeys = \array_flip(\array_unique($passedKeys)); |
|
2027 | + |
|
2028 | + foreach ($this->dependencies as $dependency) { |
|
2029 | + $clone = false; |
|
2030 | + |
|
2031 | + if (\strpos($dependency, 'clone ') === 0) { |
|
2032 | + $clone = true; |
|
2033 | + $dependency = \substr($dependency, \strlen('clone ')); |
|
2034 | + } elseif (\strpos($dependency, '!clone ') === 0) { |
|
2035 | + $clone = false; |
|
2036 | + $dependency = \substr($dependency, \strlen('!clone ')); |
|
2037 | + } |
|
2038 | + |
|
2039 | + if (\strpos($dependency, '::') === false) { |
|
2040 | + $dependency = $className . '::' . $dependency; |
|
2041 | + } |
|
2042 | + |
|
2043 | + if (!isset($passedKeys[$dependency])) { |
|
2044 | + $this->result->startTest($this); |
|
2045 | + $this->result->addError( |
|
2046 | + $this, |
|
2047 | + new SkippedTestError( |
|
2048 | + \sprintf( |
|
2049 | + 'This test depends on "%s" to pass.', |
|
2050 | + $dependency |
|
2051 | + ) |
|
2052 | + ), |
|
2053 | + 0 |
|
2054 | + ); |
|
2055 | + $this->result->endTest($this, 0); |
|
2056 | + |
|
2057 | + return false; |
|
2058 | + } |
|
2059 | + |
|
2060 | + if (isset($passed[$dependency])) { |
|
2061 | + if ($passed[$dependency]['size'] != \PHPUnit\Util\Test::UNKNOWN && |
|
2062 | + $this->getSize() != \PHPUnit\Util\Test::UNKNOWN && |
|
2063 | + $passed[$dependency]['size'] > $this->getSize()) { |
|
2064 | + $this->result->addError( |
|
2065 | + $this, |
|
2066 | + new SkippedTestError( |
|
2067 | + 'This test depends on a test that is larger than itself.' |
|
2068 | + ), |
|
2069 | + 0 |
|
2070 | + ); |
|
2071 | + |
|
2072 | + return false; |
|
2073 | + } |
|
2074 | + |
|
2075 | + if ($clone) { |
|
2076 | + $deepCopy = new DeepCopy; |
|
2077 | + $deepCopy->skipUncloneable(false); |
|
2078 | + |
|
2079 | + $this->dependencyInput[$dependency] = $deepCopy->copy($passed[$dependency]['result']); |
|
2080 | + } else { |
|
2081 | + $this->dependencyInput[$dependency] = $passed[$dependency]['result']; |
|
2082 | + } |
|
2083 | + } else { |
|
2084 | + $this->dependencyInput[$dependency] = null; |
|
2085 | + } |
|
2086 | + } |
|
2087 | + } |
|
2088 | + |
|
2089 | + return true; |
|
2090 | + } |
|
2091 | + |
|
2092 | + /** |
|
2093 | + * This method is called before the first test of this test class is run. |
|
2094 | + */ |
|
2095 | + public static function setUpBeforeClass() |
|
2096 | + { |
|
2097 | + } |
|
2098 | + |
|
2099 | + /** |
|
2100 | + * Sets up the fixture, for example, open a network connection. |
|
2101 | + * This method is called before a test is executed. |
|
2102 | + */ |
|
2103 | + protected function setUp() |
|
2104 | + { |
|
2105 | + } |
|
2106 | + |
|
2107 | + /** |
|
2108 | + * Performs assertions shared by all tests of a test case. |
|
2109 | + * |
|
2110 | + * This method is called before the execution of a test starts |
|
2111 | + * and after setUp() is called. |
|
2112 | + */ |
|
2113 | + protected function assertPreConditions() |
|
2114 | + { |
|
2115 | + } |
|
2116 | + |
|
2117 | + /** |
|
2118 | + * Performs assertions shared by all tests of a test case. |
|
2119 | + * |
|
2120 | + * This method is called after the execution of a test ends |
|
2121 | + * and before tearDown() is called. |
|
2122 | + */ |
|
2123 | + protected function assertPostConditions() |
|
2124 | + { |
|
2125 | + } |
|
2126 | + |
|
2127 | + /** |
|
2128 | + * Tears down the fixture, for example, close a network connection. |
|
2129 | + * This method is called after a test is executed. |
|
2130 | + */ |
|
2131 | + protected function tearDown() |
|
2132 | + { |
|
2133 | + } |
|
2134 | + |
|
2135 | + /** |
|
2136 | + * This method is called after the last test of this test class is run. |
|
2137 | + */ |
|
2138 | + public static function tearDownAfterClass() |
|
2139 | + { |
|
2140 | + } |
|
2141 | + |
|
2142 | + /** |
|
2143 | + * This method is called when a test method did not execute successfully. |
|
2144 | + * |
|
2145 | + * @param Throwable $t |
|
2146 | + * |
|
2147 | + * @throws Throwable |
|
2148 | + */ |
|
2149 | + protected function onNotSuccessfulTest(Throwable $t) |
|
2150 | + { |
|
2151 | + throw $t; |
|
2152 | + } |
|
2153 | + |
|
2154 | + /** |
|
2155 | + * Performs custom preparations on the process isolation template. |
|
2156 | + * |
|
2157 | + * @param Text_Template $template |
|
2158 | + */ |
|
2159 | + protected function prepareTemplate(Text_Template $template) |
|
2160 | + { |
|
2161 | + } |
|
2162 | + |
|
2163 | + /** |
|
2164 | + * Get the mock object generator, creating it if it doesn't exist. |
|
2165 | + * |
|
2166 | + * @return PHPUnit_Framework_MockObject_Generator |
|
2167 | + */ |
|
2168 | + private function getMockObjectGenerator() |
|
2169 | + { |
|
2170 | + if (null === $this->mockObjectGenerator) { |
|
2171 | + $this->mockObjectGenerator = new PHPUnit_Framework_MockObject_Generator; |
|
2172 | + } |
|
2173 | + |
|
2174 | + return $this->mockObjectGenerator; |
|
2175 | + } |
|
2176 | + |
|
2177 | + private function startOutputBuffering() |
|
2178 | + { |
|
2179 | + \ob_start(); |
|
2180 | + |
|
2181 | + $this->outputBufferingActive = true; |
|
2182 | + $this->outputBufferingLevel = \ob_get_level(); |
|
2183 | + } |
|
2184 | + |
|
2185 | + private function stopOutputBuffering() |
|
2186 | + { |
|
2187 | + if (\ob_get_level() != $this->outputBufferingLevel) { |
|
2188 | + while (\ob_get_level() >= $this->outputBufferingLevel) { |
|
2189 | + \ob_end_clean(); |
|
2190 | + } |
|
2191 | + |
|
2192 | + throw new RiskyTestError( |
|
2193 | + 'Test code or tested code did not (only) close its own output buffers' |
|
2194 | + ); |
|
2195 | + } |
|
2196 | + |
|
2197 | + $output = \ob_get_contents(); |
|
2198 | + |
|
2199 | + if ($this->outputCallback === false) { |
|
2200 | + $this->output = $output; |
|
2201 | + } else { |
|
2202 | + $this->output = \call_user_func_array( |
|
2203 | + $this->outputCallback, |
|
2204 | + [$output] |
|
2205 | + ); |
|
2206 | + } |
|
2207 | + |
|
2208 | + \ob_end_clean(); |
|
2209 | + |
|
2210 | + $this->outputBufferingActive = false; |
|
2211 | + $this->outputBufferingLevel = \ob_get_level(); |
|
2212 | + } |
|
2213 | + |
|
2214 | + private function snapshotGlobalState() |
|
2215 | + { |
|
2216 | + if ($this->runTestInSeparateProcess || |
|
2217 | + $this->inIsolation || |
|
2218 | + (!$this->backupGlobals === true && !$this->backupStaticAttributes)) { |
|
2219 | + return; |
|
2220 | + } |
|
2221 | + |
|
2222 | + $this->snapshot = $this->createGlobalStateSnapshot($this->backupGlobals === true); |
|
2223 | + } |
|
2224 | + |
|
2225 | + private function restoreGlobalState() |
|
2226 | + { |
|
2227 | + if (!$this->snapshot instanceof Snapshot) { |
|
2228 | + return; |
|
2229 | + } |
|
2230 | + |
|
2231 | + if ($this->beStrictAboutChangesToGlobalState) { |
|
2232 | + try { |
|
2233 | + $this->compareGlobalStateSnapshots( |
|
2234 | + $this->snapshot, |
|
2235 | + $this->createGlobalStateSnapshot($this->backupGlobals === true) |
|
2236 | + ); |
|
2237 | + } catch (RiskyTestError $rte) { |
|
2238 | + // Intentionally left empty |
|
2239 | + } |
|
2240 | + } |
|
2241 | + |
|
2242 | + $restorer = new Restorer; |
|
2243 | + |
|
2244 | + if ($this->backupGlobals === true) { |
|
2245 | + $restorer->restoreGlobalVariables($this->snapshot); |
|
2246 | + } |
|
2247 | + |
|
2248 | + if ($this->backupStaticAttributes) { |
|
2249 | + $restorer->restoreStaticAttributes($this->snapshot); |
|
2250 | + } |
|
2251 | + |
|
2252 | + $this->snapshot = null; |
|
2253 | + |
|
2254 | + if (isset($rte)) { |
|
2255 | + throw $rte; |
|
2256 | + } |
|
2257 | + } |
|
2258 | + |
|
2259 | + /** |
|
2260 | + * @param bool $backupGlobals |
|
2261 | + * |
|
2262 | + * @return Snapshot |
|
2263 | + */ |
|
2264 | + private function createGlobalStateSnapshot($backupGlobals) |
|
2265 | + { |
|
2266 | + $blacklist = new Blacklist; |
|
2267 | + |
|
2268 | + foreach ($this->backupGlobalsBlacklist as $globalVariable) { |
|
2269 | + $blacklist->addGlobalVariable($globalVariable); |
|
2270 | + } |
|
2271 | + |
|
2272 | + if (!\defined('PHPUNIT_TESTSUITE')) { |
|
2273 | + $blacklist->addClassNamePrefix('PHPUnit'); |
|
2274 | + $blacklist->addClassNamePrefix('File_Iterator'); |
|
2275 | + $blacklist->addClassNamePrefix('SebastianBergmann\CodeCoverage'); |
|
2276 | + $blacklist->addClassNamePrefix('PHP_Invoker'); |
|
2277 | + $blacklist->addClassNamePrefix('PHP_Timer'); |
|
2278 | + $blacklist->addClassNamePrefix('PHP_Token'); |
|
2279 | + $blacklist->addClassNamePrefix('Symfony'); |
|
2280 | + $blacklist->addClassNamePrefix('Text_Template'); |
|
2281 | + $blacklist->addClassNamePrefix('Doctrine\Instantiator'); |
|
2282 | + $blacklist->addClassNamePrefix('Prophecy'); |
|
2283 | + |
|
2284 | + foreach ($this->backupStaticAttributesBlacklist as $class => $attributes) { |
|
2285 | + foreach ($attributes as $attribute) { |
|
2286 | + $blacklist->addStaticAttribute($class, $attribute); |
|
2287 | + } |
|
2288 | + } |
|
2289 | + } |
|
2290 | + |
|
2291 | + return new Snapshot( |
|
2292 | + $blacklist, |
|
2293 | + $backupGlobals, |
|
2294 | + (bool) $this->backupStaticAttributes, |
|
2295 | + false, |
|
2296 | + false, |
|
2297 | + false, |
|
2298 | + false, |
|
2299 | + false, |
|
2300 | + false, |
|
2301 | + false |
|
2302 | + ); |
|
2303 | + } |
|
2304 | + |
|
2305 | + /** |
|
2306 | + * @param Snapshot $before |
|
2307 | + * @param Snapshot $after |
|
2308 | + * |
|
2309 | + * @throws RiskyTestError |
|
2310 | + */ |
|
2311 | + private function compareGlobalStateSnapshots(Snapshot $before, Snapshot $after) |
|
2312 | + { |
|
2313 | + $backupGlobals = $this->backupGlobals === null || $this->backupGlobals === true; |
|
2314 | + |
|
2315 | + if ($backupGlobals) { |
|
2316 | + $this->compareGlobalStateSnapshotPart( |
|
2317 | + $before->globalVariables(), |
|
2318 | + $after->globalVariables(), |
|
2319 | + "--- Global variables before the test\n+++ Global variables after the test\n" |
|
2320 | + ); |
|
2321 | + |
|
2322 | + $this->compareGlobalStateSnapshotPart( |
|
2323 | + $before->superGlobalVariables(), |
|
2324 | + $after->superGlobalVariables(), |
|
2325 | + "--- Super-global variables before the test\n+++ Super-global variables after the test\n" |
|
2326 | + ); |
|
2327 | + } |
|
2328 | + |
|
2329 | + if ($this->backupStaticAttributes) { |
|
2330 | + $this->compareGlobalStateSnapshotPart( |
|
2331 | + $before->staticAttributes(), |
|
2332 | + $after->staticAttributes(), |
|
2333 | + "--- Static attributes before the test\n+++ Static attributes after the test\n" |
|
2334 | + ); |
|
2335 | + } |
|
2336 | + } |
|
2337 | + |
|
2338 | + /** |
|
2339 | + * @param array $before |
|
2340 | + * @param array $after |
|
2341 | + * @param string $header |
|
2342 | + * |
|
2343 | + * @throws RiskyTestError |
|
2344 | + */ |
|
2345 | + private function compareGlobalStateSnapshotPart(array $before, array $after, $header) |
|
2346 | + { |
|
2347 | + if ($before != $after) { |
|
2348 | + $differ = new Differ($header); |
|
2349 | + $exporter = new Exporter; |
|
2350 | + |
|
2351 | + $diff = $differ->diff( |
|
2352 | + $exporter->export($before), |
|
2353 | + $exporter->export($after) |
|
2354 | + ); |
|
2355 | + |
|
2356 | + throw new RiskyTestError( |
|
2357 | + $diff |
|
2358 | + ); |
|
2359 | + } |
|
2360 | + } |
|
2361 | + |
|
2362 | + /** |
|
2363 | + * @return Prophecy\Prophet |
|
2364 | + */ |
|
2365 | + private function getProphet() |
|
2366 | + { |
|
2367 | + if ($this->prophet === null) { |
|
2368 | + $this->prophet = new Prophet; |
|
2369 | + } |
|
2370 | + |
|
2371 | + return $this->prophet; |
|
2372 | + } |
|
2373 | + |
|
2374 | + /** |
|
2375 | + * @param PHPUnit_Framework_MockObject_MockObject $mock |
|
2376 | + * |
|
2377 | + * @return bool |
|
2378 | + */ |
|
2379 | + private function shouldInvocationMockerBeReset(PHPUnit_Framework_MockObject_MockObject $mock) |
|
2380 | + { |
|
2381 | + $enumerator = new Enumerator; |
|
2382 | + |
|
2383 | + foreach ($enumerator->enumerate($this->dependencyInput) as $object) { |
|
2384 | + if ($mock === $object) { |
|
2385 | + return false; |
|
2386 | + } |
|
2387 | + } |
|
2388 | + |
|
2389 | + if (!\is_array($this->testResult) && !\is_object($this->testResult)) { |
|
2390 | + return true; |
|
2391 | + } |
|
2392 | + |
|
2393 | + foreach ($enumerator->enumerate($this->testResult) as $object) { |
|
2394 | + if ($mock === $object) { |
|
2395 | + return false; |
|
2396 | + } |
|
2397 | + } |
|
2398 | + |
|
2399 | + return true; |
|
2400 | + } |
|
2401 | + |
|
2402 | + /** |
|
2403 | + * @param array $testArguments |
|
2404 | + * @param array $visited |
|
2405 | + */ |
|
2406 | + private function registerMockObjectsFromTestArguments(array $testArguments, array &$visited = []) |
|
2407 | + { |
|
2408 | + if ($this->registerMockObjectsFromTestArgumentsRecursively) { |
|
2409 | + $enumerator = new Enumerator; |
|
2410 | + |
|
2411 | + foreach ($enumerator->enumerate($testArguments) as $object) { |
|
2412 | + if ($object instanceof PHPUnit_Framework_MockObject_MockObject) { |
|
2413 | + $this->registerMockObject($object); |
|
2414 | + } |
|
2415 | + } |
|
2416 | + } else { |
|
2417 | + foreach ($testArguments as $testArgument) { |
|
2418 | + if ($testArgument instanceof PHPUnit_Framework_MockObject_MockObject) { |
|
2419 | + if ($this->isCloneable($testArgument)) { |
|
2420 | + $testArgument = clone $testArgument; |
|
2421 | + } |
|
2422 | + |
|
2423 | + $this->registerMockObject($testArgument); |
|
2424 | + } elseif (\is_array($testArgument) && !\in_array($testArgument, $visited, true)) { |
|
2425 | + $visited[] = $testArgument; |
|
2426 | + |
|
2427 | + $this->registerMockObjectsFromTestArguments( |
|
2428 | + $testArgument, |
|
2429 | + $visited |
|
2430 | + ); |
|
2431 | + } |
|
2432 | + } |
|
2433 | + } |
|
2434 | + } |
|
2435 | + |
|
2436 | + private function setDoesNotPerformAssertionsFromAnnotation() |
|
2437 | + { |
|
2438 | + $annotations = $this->getAnnotations(); |
|
2439 | + |
|
2440 | + if (isset($annotations['method']['doesNotPerformAssertions'])) { |
|
2441 | + $this->doesNotPerformAssertions = true; |
|
2442 | + } |
|
2443 | + } |
|
2444 | + |
|
2445 | + /** |
|
2446 | + * @param PHPUnit_Framework_MockObject_MockObject $testArgument |
|
2447 | + * |
|
2448 | + * @return bool |
|
2449 | + */ |
|
2450 | + private function isCloneable(PHPUnit_Framework_MockObject_MockObject $testArgument) |
|
2451 | + { |
|
2452 | + $reflector = new ReflectionObject($testArgument); |
|
2453 | + |
|
2454 | + if (!$reflector->isCloneable()) { |
|
2455 | + return false; |
|
2456 | + } |
|
2457 | + |
|
2458 | + if ($reflector->hasMethod('__clone') && |
|
2459 | + $reflector->getMethod('__clone')->isPublic()) { |
|
2460 | + return true; |
|
2461 | + } |
|
2462 | + |
|
2463 | + return false; |
|
2464 | + } |
|
2465 | + |
|
2466 | + private function unregisterCustomComparators() |
|
2467 | + { |
|
2468 | + $factory = ComparatorFactory::getInstance(); |
|
2469 | + |
|
2470 | + foreach ($this->customComparators as $comparator) { |
|
2471 | + $factory->unregister($comparator); |
|
2472 | + } |
|
2473 | + |
|
2474 | + $this->customComparators = []; |
|
2475 | + } |
|
2476 | + |
|
2477 | + private function cleanupIniSettings() |
|
2478 | + { |
|
2479 | + foreach ($this->iniSettings as $varName => $oldValue) { |
|
2480 | + \ini_set($varName, $oldValue); |
|
2481 | + } |
|
2482 | + |
|
2483 | + $this->iniSettings = []; |
|
2484 | + } |
|
2485 | + |
|
2486 | + private function cleanupLocaleSettings() |
|
2487 | + { |
|
2488 | + foreach ($this->locale as $category => $locale) { |
|
2489 | + \setlocale($category, $locale); |
|
2490 | + } |
|
2491 | + |
|
2492 | + $this->locale = []; |
|
2493 | + } |
|
2494 | + |
|
2495 | + private function checkExceptionExpectations(Throwable $throwable): bool |
|
2496 | + { |
|
2497 | + $result = false; |
|
2498 | + |
|
2499 | + if ($this->expectedException !== null || $this->expectedExceptionCode !== null || $this->expectedExceptionMessage !== null || $this->expectedExceptionMessageRegExp !== null) { |
|
2500 | + $result = true; |
|
2501 | + } |
|
2502 | + |
|
2503 | + if ($throwable instanceof Exception) { |
|
2504 | + $result = false; |
|
2505 | + } |
|
2506 | + |
|
2507 | + if (\is_string($this->expectedException)) { |
|
2508 | + $reflector = new ReflectionClass($this->expectedException); |
|
2509 | + |
|
2510 | + if ($this->expectedException === 'PHPUnit\Framework\Exception' || |
|
2511 | + $this->expectedException === '\PHPUnit\Framework\Exception' || |
|
2512 | + $reflector->isSubclassOf('PHPUnit\Framework\Exception')) { |
|
2513 | + $result = true; |
|
2514 | + } |
|
2515 | + } |
|
2516 | + |
|
2517 | + return $result; |
|
2518 | + } |
|
2519 | 2519 | } |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | $this->getName(false) |
365 | 365 | ); |
366 | 366 | |
367 | - return $buffer . $this->getDataSetAsString(); |
|
367 | + return $buffer.$this->getDataSetAsString(); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | public function getName($withDataSet = true) |
414 | 414 | { |
415 | 415 | if ($withDataSet) { |
416 | - return $this->name . $this->getDataSetAsString(false); |
|
416 | + return $this->name.$this->getDataSetAsString(false); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | return $this->name; |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | return; |
783 | 783 | } |
784 | 784 | |
785 | - $runEntireClass = $this->runClassInSeparateProcess && !$this->runTestInSeparateProcess; |
|
785 | + $runEntireClass = $this->runClassInSeparateProcess && !$this->runTestInSeparateProcess; |
|
786 | 786 | |
787 | 787 | if (($this->runTestInSeparateProcess === true || $this->runClassInSeparateProcess === true) && |
788 | 788 | $this->inIsolation !== true && |
@@ -791,11 +791,11 @@ discard block |
||
791 | 791 | |
792 | 792 | if ($runEntireClass) { |
793 | 793 | $template = new Text_Template( |
794 | - __DIR__ . '/../Util/PHP/Template/TestCaseClass.tpl' |
|
794 | + __DIR__.'/../Util/PHP/Template/TestCaseClass.tpl' |
|
795 | 795 | ); |
796 | 796 | } else { |
797 | 797 | $template = new Text_Template( |
798 | - __DIR__ . '/../Util/PHP/Template/TestCaseMethod.tpl' |
|
798 | + __DIR__.'/../Util/PHP/Template/TestCaseMethod.tpl' |
|
799 | 799 | ); |
800 | 800 | } |
801 | 801 | |
@@ -807,7 +807,7 @@ discard block |
||
807 | 807 | } else { |
808 | 808 | $constants = ''; |
809 | 809 | if (!empty($GLOBALS['__PHPUNIT_BOOTSTRAP'])) { |
810 | - $globals = '$GLOBALS[\'__PHPUNIT_BOOTSTRAP\'] = ' . \var_export($GLOBALS['__PHPUNIT_BOOTSTRAP'], true) . ";\n"; |
|
810 | + $globals = '$GLOBALS[\'__PHPUNIT_BOOTSTRAP\'] = '.\var_export($GLOBALS['__PHPUNIT_BOOTSTRAP'], true).";\n"; |
|
811 | 811 | } else { |
812 | 812 | $globals = ''; |
813 | 813 | } |
@@ -847,11 +847,11 @@ discard block |
||
847 | 847 | $codeCoverageFilter = \var_export(\serialize($codeCoverageFilter), true); |
848 | 848 | // must do these fixes because TestCaseMethod.tpl has unserialize('{data}') in it, and we can't break BC |
849 | 849 | // the lines above used to use addcslashes() rather than var_export(), which breaks null byte escape sequences |
850 | - $data = "'." . $data . ".'"; |
|
851 | - $dataName = "'.(" . $dataName . ").'"; |
|
852 | - $dependencyInput = "'." . $dependencyInput . ".'"; |
|
853 | - $includePath = "'." . $includePath . ".'"; |
|
854 | - $codeCoverageFilter = "'." . $codeCoverageFilter . ".'"; |
|
850 | + $data = "'.".$data.".'"; |
|
851 | + $dataName = "'.(".$dataName.").'"; |
|
852 | + $dependencyInput = "'.".$dependencyInput.".'"; |
|
853 | + $includePath = "'.".$includePath.".'"; |
|
854 | + $codeCoverageFilter = "'.".$codeCoverageFilter.".'"; |
|
855 | 855 | |
856 | 856 | $configurationFilePath = $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] ?? ''; |
857 | 857 | |
@@ -1459,8 +1459,8 @@ discard block |
||
1459 | 1459 | |
1460 | 1460 | if ($result === false) { |
1461 | 1461 | throw new Exception( |
1462 | - 'The locale functionality is not implemented on your platform, ' . |
|
1463 | - 'the specified locale does not exist or the category name is ' . |
|
1462 | + 'The locale functionality is not implemented on your platform, '. |
|
1463 | + 'the specified locale does not exist or the category name is '. |
|
1464 | 1464 | 'invalid.' |
1465 | 1465 | ); |
1466 | 1466 | } |
@@ -2037,7 +2037,7 @@ discard block |
||
2037 | 2037 | } |
2038 | 2038 | |
2039 | 2039 | if (\strpos($dependency, '::') === false) { |
2040 | - $dependency = $className . '::' . $dependency; |
|
2040 | + $dependency = $className.'::'.$dependency; |
|
2041 | 2041 | } |
2042 | 2042 | |
2043 | 2043 | if (!isset($passedKeys[$dependency])) { |
@@ -16,89 +16,89 @@ |
||
16 | 16 | */ |
17 | 17 | class TestSuiteIterator implements RecursiveIterator |
18 | 18 | { |
19 | - /** |
|
20 | - * @var int |
|
21 | - */ |
|
22 | - protected $position; |
|
19 | + /** |
|
20 | + * @var int |
|
21 | + */ |
|
22 | + protected $position; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var Test[] |
|
26 | - */ |
|
27 | - protected $tests; |
|
24 | + /** |
|
25 | + * @var Test[] |
|
26 | + */ |
|
27 | + protected $tests; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param TestSuite $testSuite |
|
31 | - */ |
|
32 | - public function __construct(TestSuite $testSuite) |
|
33 | - { |
|
34 | - $this->tests = $testSuite->tests(); |
|
35 | - } |
|
29 | + /** |
|
30 | + * @param TestSuite $testSuite |
|
31 | + */ |
|
32 | + public function __construct(TestSuite $testSuite) |
|
33 | + { |
|
34 | + $this->tests = $testSuite->tests(); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Rewinds the Iterator to the first element. |
|
39 | - */ |
|
40 | - public function rewind() |
|
41 | - { |
|
42 | - $this->position = 0; |
|
43 | - } |
|
37 | + /** |
|
38 | + * Rewinds the Iterator to the first element. |
|
39 | + */ |
|
40 | + public function rewind() |
|
41 | + { |
|
42 | + $this->position = 0; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Checks if there is a current element after calls to rewind() or next(). |
|
47 | - * |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public function valid() |
|
51 | - { |
|
52 | - return $this->position < \count($this->tests); |
|
53 | - } |
|
45 | + /** |
|
46 | + * Checks if there is a current element after calls to rewind() or next(). |
|
47 | + * |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public function valid() |
|
51 | + { |
|
52 | + return $this->position < \count($this->tests); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Returns the key of the current element. |
|
57 | - * |
|
58 | - * @return int |
|
59 | - */ |
|
60 | - public function key() |
|
61 | - { |
|
62 | - return $this->position; |
|
63 | - } |
|
55 | + /** |
|
56 | + * Returns the key of the current element. |
|
57 | + * |
|
58 | + * @return int |
|
59 | + */ |
|
60 | + public function key() |
|
61 | + { |
|
62 | + return $this->position; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Returns the current element. |
|
67 | - * |
|
68 | - * @return Test |
|
69 | - */ |
|
70 | - public function current() |
|
71 | - { |
|
72 | - return $this->valid() ? $this->tests[$this->position] : null; |
|
73 | - } |
|
65 | + /** |
|
66 | + * Returns the current element. |
|
67 | + * |
|
68 | + * @return Test |
|
69 | + */ |
|
70 | + public function current() |
|
71 | + { |
|
72 | + return $this->valid() ? $this->tests[$this->position] : null; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Moves forward to next element. |
|
77 | - */ |
|
78 | - public function next() |
|
79 | - { |
|
80 | - $this->position++; |
|
81 | - } |
|
75 | + /** |
|
76 | + * Moves forward to next element. |
|
77 | + */ |
|
78 | + public function next() |
|
79 | + { |
|
80 | + $this->position++; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Returns the sub iterator for the current element. |
|
85 | - * |
|
86 | - * @return TestSuiteIterator |
|
87 | - */ |
|
88 | - public function getChildren() |
|
89 | - { |
|
90 | - return new self( |
|
91 | - $this->tests[$this->position] |
|
92 | - ); |
|
93 | - } |
|
83 | + /** |
|
84 | + * Returns the sub iterator for the current element. |
|
85 | + * |
|
86 | + * @return TestSuiteIterator |
|
87 | + */ |
|
88 | + public function getChildren() |
|
89 | + { |
|
90 | + return new self( |
|
91 | + $this->tests[$this->position] |
|
92 | + ); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Checks whether the current element has children. |
|
97 | - * |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - public function hasChildren() |
|
101 | - { |
|
102 | - return $this->tests[$this->position] instanceof TestSuite; |
|
103 | - } |
|
95 | + /** |
|
96 | + * Checks whether the current element has children. |
|
97 | + * |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + public function hasChildren() |
|
101 | + { |
|
102 | + return $this->tests[$this->position] instanceof TestSuite; |
|
103 | + } |
|
104 | 104 | } |
@@ -11,43 +11,43 @@ |
||
11 | 11 | |
12 | 12 | trait TestListenerDefaultImplementation |
13 | 13 | { |
14 | - public function addError(Test $test, \Exception $e, $time) |
|
15 | - { |
|
16 | - } |
|
14 | + public function addError(Test $test, \Exception $e, $time) |
|
15 | + { |
|
16 | + } |
|
17 | 17 | |
18 | - public function addWarning(Test $test, Warning $e, $time) |
|
19 | - { |
|
20 | - } |
|
18 | + public function addWarning(Test $test, Warning $e, $time) |
|
19 | + { |
|
20 | + } |
|
21 | 21 | |
22 | - public function addFailure(Test $test, AssertionFailedError $e, $time) |
|
23 | - { |
|
24 | - } |
|
22 | + public function addFailure(Test $test, AssertionFailedError $e, $time) |
|
23 | + { |
|
24 | + } |
|
25 | 25 | |
26 | - public function addIncompleteTest(Test $test, \Exception $e, $time) |
|
27 | - { |
|
28 | - } |
|
26 | + public function addIncompleteTest(Test $test, \Exception $e, $time) |
|
27 | + { |
|
28 | + } |
|
29 | 29 | |
30 | - public function addRiskyTest(Test $test, \Exception $e, $time) |
|
31 | - { |
|
32 | - } |
|
30 | + public function addRiskyTest(Test $test, \Exception $e, $time) |
|
31 | + { |
|
32 | + } |
|
33 | 33 | |
34 | - public function addSkippedTest(Test $test, \Exception $e, $time) |
|
35 | - { |
|
36 | - } |
|
34 | + public function addSkippedTest(Test $test, \Exception $e, $time) |
|
35 | + { |
|
36 | + } |
|
37 | 37 | |
38 | - public function startTestSuite(TestSuite $suite) |
|
39 | - { |
|
40 | - } |
|
38 | + public function startTestSuite(TestSuite $suite) |
|
39 | + { |
|
40 | + } |
|
41 | 41 | |
42 | - public function endTestSuite(TestSuite $suite) |
|
43 | - { |
|
44 | - } |
|
42 | + public function endTestSuite(TestSuite $suite) |
|
43 | + { |
|
44 | + } |
|
45 | 45 | |
46 | - public function startTest(Test $test) |
|
47 | - { |
|
48 | - } |
|
46 | + public function startTest(Test $test) |
|
47 | + { |
|
48 | + } |
|
49 | 49 | |
50 | - public function endTest(Test $test, $time) |
|
51 | - { |
|
52 | - } |
|
50 | + public function endTest(Test $test, $time) |
|
51 | + { |
|
52 | + } |
|
53 | 53 | } |
@@ -23,71 +23,71 @@ |
||
23 | 23 | */ |
24 | 24 | class ExceptionWrapper extends Exception |
25 | 25 | { |
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $className; |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $className; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var ExceptionWrapper|null |
|
33 | - */ |
|
34 | - protected $previous; |
|
31 | + /** |
|
32 | + * @var ExceptionWrapper|null |
|
33 | + */ |
|
34 | + protected $previous; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param Throwable $t |
|
38 | - */ |
|
39 | - public function __construct(Throwable $t) |
|
40 | - { |
|
41 | - // PDOException::getCode() is a string. |
|
42 | - // @see http://php.net/manual/en/class.pdoexception.php#95812 |
|
43 | - parent::__construct($t->getMessage(), (int) $t->getCode()); |
|
36 | + /** |
|
37 | + * @param Throwable $t |
|
38 | + */ |
|
39 | + public function __construct(Throwable $t) |
|
40 | + { |
|
41 | + // PDOException::getCode() is a string. |
|
42 | + // @see http://php.net/manual/en/class.pdoexception.php#95812 |
|
43 | + parent::__construct($t->getMessage(), (int) $t->getCode()); |
|
44 | 44 | |
45 | - $this->className = \get_class($t); |
|
46 | - $this->file = $t->getFile(); |
|
47 | - $this->line = $t->getLine(); |
|
45 | + $this->className = \get_class($t); |
|
46 | + $this->file = $t->getFile(); |
|
47 | + $this->line = $t->getLine(); |
|
48 | 48 | |
49 | - $this->serializableTrace = $t->getTrace(); |
|
49 | + $this->serializableTrace = $t->getTrace(); |
|
50 | 50 | |
51 | - foreach ($this->serializableTrace as $i => $call) { |
|
52 | - unset($this->serializableTrace[$i]['args']); |
|
53 | - } |
|
51 | + foreach ($this->serializableTrace as $i => $call) { |
|
52 | + unset($this->serializableTrace[$i]['args']); |
|
53 | + } |
|
54 | 54 | |
55 | - if ($t->getPrevious()) { |
|
56 | - $this->previous = new self($t->getPrevious()); |
|
57 | - } |
|
58 | - } |
|
55 | + if ($t->getPrevious()) { |
|
56 | + $this->previous = new self($t->getPrevious()); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public function getClassName() |
|
64 | - { |
|
65 | - return $this->className; |
|
66 | - } |
|
60 | + /** |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public function getClassName() |
|
64 | + { |
|
65 | + return $this->className; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return ExceptionWrapper |
|
70 | - */ |
|
71 | - public function getPreviousWrapped() |
|
72 | - { |
|
73 | - return $this->previous; |
|
74 | - } |
|
68 | + /** |
|
69 | + * @return ExceptionWrapper |
|
70 | + */ |
|
71 | + public function getPreviousWrapped() |
|
72 | + { |
|
73 | + return $this->previous; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function __toString() |
|
80 | - { |
|
81 | - $string = TestFailure::exceptionToString($this); |
|
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function __toString() |
|
80 | + { |
|
81 | + $string = TestFailure::exceptionToString($this); |
|
82 | 82 | |
83 | - if ($trace = Filter::getFilteredStacktrace($this)) { |
|
84 | - $string .= "\n" . $trace; |
|
85 | - } |
|
83 | + if ($trace = Filter::getFilteredStacktrace($this)) { |
|
84 | + $string .= "\n" . $trace; |
|
85 | + } |
|
86 | 86 | |
87 | - if ($this->previous) { |
|
88 | - $string .= "\nCaused by\n" . $this->previous; |
|
89 | - } |
|
87 | + if ($this->previous) { |
|
88 | + $string .= "\nCaused by\n" . $this->previous; |
|
89 | + } |
|
90 | 90 | |
91 | - return $string; |
|
92 | - } |
|
91 | + return $string; |
|
92 | + } |
|
93 | 93 | } |
@@ -81,11 +81,11 @@ |
||
81 | 81 | $string = TestFailure::exceptionToString($this); |
82 | 82 | |
83 | 83 | if ($trace = Filter::getFilteredStacktrace($this)) { |
84 | - $string .= "\n" . $trace; |
|
84 | + $string .= "\n".$trace; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | if ($this->previous) { |
88 | - $string .= "\nCaused by\n" . $this->previous; |
|
88 | + $string .= "\nCaused by\n".$this->previous; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | return $string; |
@@ -14,86 +14,86 @@ |
||
14 | 14 | */ |
15 | 15 | interface TestListener |
16 | 16 | { |
17 | - /** |
|
18 | - * An error occurred. |
|
19 | - * |
|
20 | - * @param Test $test |
|
21 | - * @param \Exception $e |
|
22 | - * @param float $time |
|
23 | - */ |
|
24 | - public function addError(Test $test, \Exception $e, $time); |
|
17 | + /** |
|
18 | + * An error occurred. |
|
19 | + * |
|
20 | + * @param Test $test |
|
21 | + * @param \Exception $e |
|
22 | + * @param float $time |
|
23 | + */ |
|
24 | + public function addError(Test $test, \Exception $e, $time); |
|
25 | 25 | |
26 | - /** |
|
27 | - * A warning occurred. |
|
28 | - * |
|
29 | - * @param Test $test |
|
30 | - * @param Warning $e |
|
31 | - * @param float $time |
|
32 | - */ |
|
33 | - public function addWarning(Test $test, Warning $e, $time); |
|
26 | + /** |
|
27 | + * A warning occurred. |
|
28 | + * |
|
29 | + * @param Test $test |
|
30 | + * @param Warning $e |
|
31 | + * @param float $time |
|
32 | + */ |
|
33 | + public function addWarning(Test $test, Warning $e, $time); |
|
34 | 34 | |
35 | - /** |
|
36 | - * A failure occurred. |
|
37 | - * |
|
38 | - * @param Test $test |
|
39 | - * @param AssertionFailedError $e |
|
40 | - * @param float $time |
|
41 | - */ |
|
42 | - public function addFailure(Test $test, AssertionFailedError $e, $time); |
|
35 | + /** |
|
36 | + * A failure occurred. |
|
37 | + * |
|
38 | + * @param Test $test |
|
39 | + * @param AssertionFailedError $e |
|
40 | + * @param float $time |
|
41 | + */ |
|
42 | + public function addFailure(Test $test, AssertionFailedError $e, $time); |
|
43 | 43 | |
44 | - /** |
|
45 | - * Incomplete test. |
|
46 | - * |
|
47 | - * @param Test $test |
|
48 | - * @param \Exception $e |
|
49 | - * @param float $time |
|
50 | - */ |
|
51 | - public function addIncompleteTest(Test $test, \Exception $e, $time); |
|
44 | + /** |
|
45 | + * Incomplete test. |
|
46 | + * |
|
47 | + * @param Test $test |
|
48 | + * @param \Exception $e |
|
49 | + * @param float $time |
|
50 | + */ |
|
51 | + public function addIncompleteTest(Test $test, \Exception $e, $time); |
|
52 | 52 | |
53 | - /** |
|
54 | - * Risky test. |
|
55 | - * |
|
56 | - * @param Test $test |
|
57 | - * @param \Exception $e |
|
58 | - * @param float $time |
|
59 | - */ |
|
60 | - public function addRiskyTest(Test $test, \Exception $e, $time); |
|
53 | + /** |
|
54 | + * Risky test. |
|
55 | + * |
|
56 | + * @param Test $test |
|
57 | + * @param \Exception $e |
|
58 | + * @param float $time |
|
59 | + */ |
|
60 | + public function addRiskyTest(Test $test, \Exception $e, $time); |
|
61 | 61 | |
62 | - /** |
|
63 | - * Skipped test. |
|
64 | - * |
|
65 | - * @param Test $test |
|
66 | - * @param \Exception $e |
|
67 | - * @param float $time |
|
68 | - */ |
|
69 | - public function addSkippedTest(Test $test, \Exception $e, $time); |
|
62 | + /** |
|
63 | + * Skipped test. |
|
64 | + * |
|
65 | + * @param Test $test |
|
66 | + * @param \Exception $e |
|
67 | + * @param float $time |
|
68 | + */ |
|
69 | + public function addSkippedTest(Test $test, \Exception $e, $time); |
|
70 | 70 | |
71 | - /** |
|
72 | - * A test suite started. |
|
73 | - * |
|
74 | - * @param TestSuite $suite |
|
75 | - */ |
|
76 | - public function startTestSuite(TestSuite $suite); |
|
71 | + /** |
|
72 | + * A test suite started. |
|
73 | + * |
|
74 | + * @param TestSuite $suite |
|
75 | + */ |
|
76 | + public function startTestSuite(TestSuite $suite); |
|
77 | 77 | |
78 | - /** |
|
79 | - * A test suite ended. |
|
80 | - * |
|
81 | - * @param TestSuite $suite |
|
82 | - */ |
|
83 | - public function endTestSuite(TestSuite $suite); |
|
78 | + /** |
|
79 | + * A test suite ended. |
|
80 | + * |
|
81 | + * @param TestSuite $suite |
|
82 | + */ |
|
83 | + public function endTestSuite(TestSuite $suite); |
|
84 | 84 | |
85 | - /** |
|
86 | - * A test started. |
|
87 | - * |
|
88 | - * @param Test $test |
|
89 | - */ |
|
90 | - public function startTest(Test $test); |
|
85 | + /** |
|
86 | + * A test started. |
|
87 | + * |
|
88 | + * @param Test $test |
|
89 | + */ |
|
90 | + public function startTest(Test $test); |
|
91 | 91 | |
92 | - /** |
|
93 | - * A test ended. |
|
94 | - * |
|
95 | - * @param Test $test |
|
96 | - * @param float $time |
|
97 | - */ |
|
98 | - public function endTest(Test $test, $time); |
|
92 | + /** |
|
93 | + * A test ended. |
|
94 | + * |
|
95 | + * @param Test $test |
|
96 | + * @param float $time |
|
97 | + */ |
|
98 | + public function endTest(Test $test, $time); |
|
99 | 99 | } |
@@ -33,48 +33,48 @@ |
||
33 | 33 | */ |
34 | 34 | class Exception extends \RuntimeException implements \PHPUnit\Exception |
35 | 35 | { |
36 | - /** |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $serializableTrace; |
|
36 | + /** |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $serializableTrace; |
|
40 | 40 | |
41 | - public function __construct($message = '', $code = 0, \Exception $previous = null) |
|
42 | - { |
|
43 | - parent::__construct($message, $code, $previous); |
|
41 | + public function __construct($message = '', $code = 0, \Exception $previous = null) |
|
42 | + { |
|
43 | + parent::__construct($message, $code, $previous); |
|
44 | 44 | |
45 | - $this->serializableTrace = $this->getTrace(); |
|
45 | + $this->serializableTrace = $this->getTrace(); |
|
46 | 46 | |
47 | - foreach ($this->serializableTrace as $i => $call) { |
|
48 | - unset($this->serializableTrace[$i]['args']); |
|
49 | - } |
|
50 | - } |
|
47 | + foreach ($this->serializableTrace as $i => $call) { |
|
48 | + unset($this->serializableTrace[$i]['args']); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Returns the serializable trace (without 'args'). |
|
54 | - * |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public function getSerializableTrace() |
|
58 | - { |
|
59 | - return $this->serializableTrace; |
|
60 | - } |
|
52 | + /** |
|
53 | + * Returns the serializable trace (without 'args'). |
|
54 | + * |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public function getSerializableTrace() |
|
58 | + { |
|
59 | + return $this->serializableTrace; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function __toString() |
|
66 | - { |
|
67 | - $string = TestFailure::exceptionToString($this); |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function __toString() |
|
66 | + { |
|
67 | + $string = TestFailure::exceptionToString($this); |
|
68 | 68 | |
69 | - if ($trace = Filter::getFilteredStacktrace($this)) { |
|
70 | - $string .= "\n" . $trace; |
|
71 | - } |
|
69 | + if ($trace = Filter::getFilteredStacktrace($this)) { |
|
70 | + $string .= "\n" . $trace; |
|
71 | + } |
|
72 | 72 | |
73 | - return $string; |
|
74 | - } |
|
73 | + return $string; |
|
74 | + } |
|
75 | 75 | |
76 | - public function __sleep() |
|
77 | - { |
|
78 | - return \array_keys(\get_object_vars($this)); |
|
79 | - } |
|
76 | + public function __sleep() |
|
77 | + { |
|
78 | + return \array_keys(\get_object_vars($this)); |
|
79 | + } |
|
80 | 80 | } |
@@ -67,7 +67,7 @@ |
||
67 | 67 | $string = TestFailure::exceptionToString($this); |
68 | 68 | |
69 | 69 | if ($trace = Filter::getFilteredStacktrace($this)) { |
70 | - $string .= "\n" . $trace; |
|
70 | + $string .= "\n".$trace; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | return $string; |
@@ -15,10 +15,10 @@ |
||
15 | 15 | */ |
16 | 16 | interface SelfDescribing |
17 | 17 | { |
18 | - /** |
|
19 | - * Returns a string representation of the object. |
|
20 | - * |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - public function toString(); |
|
18 | + /** |
|
19 | + * Returns a string representation of the object. |
|
20 | + * |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + public function toString(); |
|
24 | 24 | } |
@@ -17,153 +17,153 @@ |
||
17 | 17 | */ |
18 | 18 | class TestFailure |
19 | 19 | { |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - private $testName; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var Test|null |
|
27 | - */ |
|
28 | - protected $failedTest; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var Throwable |
|
32 | - */ |
|
33 | - protected $thrownException; |
|
34 | - |
|
35 | - /** |
|
36 | - * Constructs a TestFailure with the given test and exception. |
|
37 | - * |
|
38 | - * @param Test $failedTest |
|
39 | - * @param Throwable $t |
|
40 | - */ |
|
41 | - public function __construct(Test $failedTest, $t) |
|
42 | - { |
|
43 | - if ($failedTest instanceof SelfDescribing) { |
|
44 | - $this->testName = $failedTest->toString(); |
|
45 | - } else { |
|
46 | - $this->testName = \get_class($failedTest); |
|
47 | - } |
|
48 | - |
|
49 | - if (!$failedTest instanceof TestCase || !$failedTest->isInIsolation()) { |
|
50 | - $this->failedTest = $failedTest; |
|
51 | - } |
|
52 | - |
|
53 | - $this->thrownException = $t; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Returns a short description of the failure. |
|
58 | - * |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function toString() |
|
62 | - { |
|
63 | - return \sprintf( |
|
64 | - '%s: %s', |
|
65 | - $this->testName, |
|
66 | - $this->thrownException->getMessage() |
|
67 | - ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Returns a description for the thrown exception. |
|
72 | - * |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function getExceptionAsString() |
|
76 | - { |
|
77 | - return self::exceptionToString($this->thrownException); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Returns a description for an exception. |
|
82 | - * |
|
83 | - * @param Throwable $e |
|
84 | - * |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public static function exceptionToString(Throwable $e) |
|
88 | - { |
|
89 | - if ($e instanceof SelfDescribing) { |
|
90 | - $buffer = $e->toString(); |
|
91 | - |
|
92 | - if ($e instanceof ExpectationFailedException && $e->getComparisonFailure()) { |
|
93 | - $buffer .= $e->getComparisonFailure()->getDiff(); |
|
94 | - } |
|
95 | - |
|
96 | - if (!empty($buffer)) { |
|
97 | - $buffer = \trim($buffer) . "\n"; |
|
98 | - } |
|
99 | - |
|
100 | - return $buffer; |
|
101 | - } |
|
102 | - |
|
103 | - if ($e instanceof Error) { |
|
104 | - return $e->getMessage() . "\n"; |
|
105 | - } |
|
106 | - |
|
107 | - if ($e instanceof ExceptionWrapper) { |
|
108 | - return $e->getClassName() . ': ' . $e->getMessage() . "\n"; |
|
109 | - } |
|
110 | - |
|
111 | - return \get_class($e) . ': ' . $e->getMessage() . "\n"; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Returns the name of the failing test (including data set, if any). |
|
116 | - * |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - public function getTestName() |
|
120 | - { |
|
121 | - return $this->testName; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Returns the failing test. |
|
126 | - * |
|
127 | - * Note: The test object is not set when the test is executed in process |
|
128 | - * isolation. |
|
129 | - * |
|
130 | - * @see Exception |
|
131 | - * |
|
132 | - * @return Test|null |
|
133 | - */ |
|
134 | - public function failedTest() |
|
135 | - { |
|
136 | - return $this->failedTest; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Gets the thrown exception. |
|
141 | - * |
|
142 | - * @return Throwable |
|
143 | - */ |
|
144 | - public function thrownException() |
|
145 | - { |
|
146 | - return $this->thrownException; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Returns the exception's message. |
|
151 | - * |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - public function exceptionMessage() |
|
155 | - { |
|
156 | - return $this->thrownException()->getMessage(); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Returns true if the thrown exception |
|
161 | - * is of type AssertionFailedError. |
|
162 | - * |
|
163 | - * @return bool |
|
164 | - */ |
|
165 | - public function isFailure() |
|
166 | - { |
|
167 | - return ($this->thrownException() instanceof AssertionFailedError); |
|
168 | - } |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + private $testName; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var Test|null |
|
27 | + */ |
|
28 | + protected $failedTest; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var Throwable |
|
32 | + */ |
|
33 | + protected $thrownException; |
|
34 | + |
|
35 | + /** |
|
36 | + * Constructs a TestFailure with the given test and exception. |
|
37 | + * |
|
38 | + * @param Test $failedTest |
|
39 | + * @param Throwable $t |
|
40 | + */ |
|
41 | + public function __construct(Test $failedTest, $t) |
|
42 | + { |
|
43 | + if ($failedTest instanceof SelfDescribing) { |
|
44 | + $this->testName = $failedTest->toString(); |
|
45 | + } else { |
|
46 | + $this->testName = \get_class($failedTest); |
|
47 | + } |
|
48 | + |
|
49 | + if (!$failedTest instanceof TestCase || !$failedTest->isInIsolation()) { |
|
50 | + $this->failedTest = $failedTest; |
|
51 | + } |
|
52 | + |
|
53 | + $this->thrownException = $t; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Returns a short description of the failure. |
|
58 | + * |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function toString() |
|
62 | + { |
|
63 | + return \sprintf( |
|
64 | + '%s: %s', |
|
65 | + $this->testName, |
|
66 | + $this->thrownException->getMessage() |
|
67 | + ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Returns a description for the thrown exception. |
|
72 | + * |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function getExceptionAsString() |
|
76 | + { |
|
77 | + return self::exceptionToString($this->thrownException); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Returns a description for an exception. |
|
82 | + * |
|
83 | + * @param Throwable $e |
|
84 | + * |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public static function exceptionToString(Throwable $e) |
|
88 | + { |
|
89 | + if ($e instanceof SelfDescribing) { |
|
90 | + $buffer = $e->toString(); |
|
91 | + |
|
92 | + if ($e instanceof ExpectationFailedException && $e->getComparisonFailure()) { |
|
93 | + $buffer .= $e->getComparisonFailure()->getDiff(); |
|
94 | + } |
|
95 | + |
|
96 | + if (!empty($buffer)) { |
|
97 | + $buffer = \trim($buffer) . "\n"; |
|
98 | + } |
|
99 | + |
|
100 | + return $buffer; |
|
101 | + } |
|
102 | + |
|
103 | + if ($e instanceof Error) { |
|
104 | + return $e->getMessage() . "\n"; |
|
105 | + } |
|
106 | + |
|
107 | + if ($e instanceof ExceptionWrapper) { |
|
108 | + return $e->getClassName() . ': ' . $e->getMessage() . "\n"; |
|
109 | + } |
|
110 | + |
|
111 | + return \get_class($e) . ': ' . $e->getMessage() . "\n"; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Returns the name of the failing test (including data set, if any). |
|
116 | + * |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + public function getTestName() |
|
120 | + { |
|
121 | + return $this->testName; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Returns the failing test. |
|
126 | + * |
|
127 | + * Note: The test object is not set when the test is executed in process |
|
128 | + * isolation. |
|
129 | + * |
|
130 | + * @see Exception |
|
131 | + * |
|
132 | + * @return Test|null |
|
133 | + */ |
|
134 | + public function failedTest() |
|
135 | + { |
|
136 | + return $this->failedTest; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Gets the thrown exception. |
|
141 | + * |
|
142 | + * @return Throwable |
|
143 | + */ |
|
144 | + public function thrownException() |
|
145 | + { |
|
146 | + return $this->thrownException; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Returns the exception's message. |
|
151 | + * |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + public function exceptionMessage() |
|
155 | + { |
|
156 | + return $this->thrownException()->getMessage(); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Returns true if the thrown exception |
|
161 | + * is of type AssertionFailedError. |
|
162 | + * |
|
163 | + * @return bool |
|
164 | + */ |
|
165 | + public function isFailure() |
|
166 | + { |
|
167 | + return ($this->thrownException() instanceof AssertionFailedError); |
|
168 | + } |
|
169 | 169 | } |
@@ -94,21 +94,21 @@ |
||
94 | 94 | } |
95 | 95 | |
96 | 96 | if (!empty($buffer)) { |
97 | - $buffer = \trim($buffer) . "\n"; |
|
97 | + $buffer = \trim($buffer)."\n"; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | return $buffer; |
101 | 101 | } |
102 | 102 | |
103 | 103 | if ($e instanceof Error) { |
104 | - return $e->getMessage() . "\n"; |
|
104 | + return $e->getMessage()."\n"; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | if ($e instanceof ExceptionWrapper) { |
108 | - return $e->getClassName() . ': ' . $e->getMessage() . "\n"; |
|
108 | + return $e->getClassName().': '.$e->getMessage()."\n"; |
|
109 | 109 | } |
110 | 110 | |
111 | - return \get_class($e) . ': ' . $e->getMessage() . "\n"; |
|
111 | + return \get_class($e).': '.$e->getMessage()."\n"; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |