8da7c35bce76818ef86f0087dd89bfa8b2aea331
[yaffs-website] / vendor / phpunit / phpunit / src / Framework / TestResult.php
1 <?php
2 /*
3  * This file is part of PHPUnit.
4  *
5  * (c) Sebastian Bergmann <sebastian@phpunit.de>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * A TestResult collects the results of executing a test case.
13  *
14  * @since Class available since Release 2.0.0
15  */
16 class PHPUnit_Framework_TestResult implements Countable
17 {
18     /**
19      * @var array
20      */
21     protected $passed = array();
22
23     /**
24      * @var array
25      */
26     protected $errors = array();
27
28     /**
29      * @var array
30      */
31     protected $failures = array();
32
33     /**
34      * @var array
35      */
36     protected $notImplemented = array();
37
38     /**
39      * @var array
40      */
41     protected $risky = array();
42
43     /**
44      * @var array
45      */
46     protected $skipped = array();
47
48     /**
49      * @var array
50      */
51     protected $listeners = array();
52
53     /**
54      * @var int
55      */
56     protected $runTests = 0;
57
58     /**
59      * @var float
60      */
61     protected $time = 0;
62
63     /**
64      * @var PHPUnit_Framework_TestSuite
65      */
66     protected $topTestSuite = null;
67
68     /**
69      * Code Coverage information.
70      *
71      * @var PHP_CodeCoverage
72      */
73     protected $codeCoverage;
74
75     /**
76      * @var bool
77      */
78     protected $convertErrorsToExceptions = true;
79
80     /**
81      * @var bool
82      */
83     protected $stop = false;
84
85     /**
86      * @var bool
87      */
88     protected $stopOnError = false;
89
90     /**
91      * @var bool
92      */
93     protected $stopOnFailure = false;
94
95     /**
96      * @var bool
97      */
98     protected $beStrictAboutTestsThatDoNotTestAnything = false;
99
100     /**
101      * @var bool
102      */
103     protected $beStrictAboutOutputDuringTests = false;
104
105     /**
106      * @var bool
107      */
108     protected $beStrictAboutTestSize = false;
109
110     /**
111      * @var bool
112      */
113     protected $beStrictAboutTodoAnnotatedTests = false;
114
115     /**
116      * @var bool
117      */
118     protected $stopOnRisky = false;
119
120     /**
121      * @var bool
122      */
123     protected $stopOnIncomplete = false;
124
125     /**
126      * @var bool
127      */
128     protected $stopOnSkipped = false;
129
130     /**
131      * @var bool
132      */
133     protected $lastTestFailed = false;
134
135     /**
136      * @var int
137      */
138     protected $timeoutForSmallTests = 1;
139
140     /**
141      * @var int
142      */
143     protected $timeoutForMediumTests = 10;
144
145     /**
146      * @var int
147      */
148     protected $timeoutForLargeTests = 60;
149
150     /**
151      * Registers a TestListener.
152      *
153      * @param  PHPUnit_Framework_TestListener
154      */
155     public function addListener(PHPUnit_Framework_TestListener $listener)
156     {
157         $this->listeners[] = $listener;
158     }
159
160     /**
161      * Unregisters a TestListener.
162      *
163      * @param PHPUnit_Framework_TestListener $listener
164      */
165     public function removeListener(PHPUnit_Framework_TestListener $listener)
166     {
167         foreach ($this->listeners as $key => $_listener) {
168             if ($listener === $_listener) {
169                 unset($this->listeners[$key]);
170             }
171         }
172     }
173
174     /**
175      * Flushes all flushable TestListeners.
176      *
177      * @since  Method available since Release 3.0.0
178      */
179     public function flushListeners()
180     {
181         foreach ($this->listeners as $listener) {
182             if ($listener instanceof PHPUnit_Util_Printer) {
183                 $listener->flush();
184             }
185         }
186     }
187
188     /**
189      * Adds an error to the list of errors.
190      *
191      * @param PHPUnit_Framework_Test $test
192      * @param Exception              $e
193      * @param float                  $time
194      */
195     public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
196     {
197         if ($e instanceof PHPUnit_Framework_RiskyTest) {
198             $this->risky[] = new PHPUnit_Framework_TestFailure($test, $e);
199             $notifyMethod  = 'addRiskyTest';
200
201             if ($this->stopOnRisky) {
202                 $this->stop();
203             }
204         } elseif ($e instanceof PHPUnit_Framework_IncompleteTest) {
205             $this->notImplemented[] = new PHPUnit_Framework_TestFailure($test, $e);
206             $notifyMethod           = 'addIncompleteTest';
207
208             if ($this->stopOnIncomplete) {
209                 $this->stop();
210             }
211         } elseif ($e instanceof PHPUnit_Framework_SkippedTest) {
212             $this->skipped[] = new PHPUnit_Framework_TestFailure($test, $e);
213             $notifyMethod    = 'addSkippedTest';
214
215             if ($this->stopOnSkipped) {
216                 $this->stop();
217             }
218         } else {
219             $this->errors[] = new PHPUnit_Framework_TestFailure($test, $e);
220             $notifyMethod   = 'addError';
221
222             if ($this->stopOnError || $this->stopOnFailure) {
223                 $this->stop();
224             }
225         }
226
227         foreach ($this->listeners as $listener) {
228             $listener->$notifyMethod($test, $e, $time);
229         }
230
231         $this->lastTestFailed = true;
232         $this->time          += $time;
233     }
234
235     /**
236      * Adds a failure to the list of failures.
237      * The passed in exception caused the failure.
238      *
239      * @param PHPUnit_Framework_Test                 $test
240      * @param PHPUnit_Framework_AssertionFailedError $e
241      * @param float                                  $time
242      */
243     public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
244     {
245         if ($e instanceof PHPUnit_Framework_RiskyTest ||
246             $e instanceof PHPUnit_Framework_OutputError) {
247             $this->risky[] = new PHPUnit_Framework_TestFailure($test, $e);
248             $notifyMethod  = 'addRiskyTest';
249
250             if ($this->stopOnRisky) {
251                 $this->stop();
252             }
253         } elseif ($e instanceof PHPUnit_Framework_IncompleteTest) {
254             $this->notImplemented[] = new PHPUnit_Framework_TestFailure($test, $e);
255             $notifyMethod           = 'addIncompleteTest';
256
257             if ($this->stopOnIncomplete) {
258                 $this->stop();
259             }
260         } elseif ($e instanceof PHPUnit_Framework_SkippedTest) {
261             $this->skipped[] = new PHPUnit_Framework_TestFailure($test, $e);
262             $notifyMethod    = 'addSkippedTest';
263
264             if ($this->stopOnSkipped) {
265                 $this->stop();
266             }
267         } else {
268             $this->failures[] = new PHPUnit_Framework_TestFailure($test, $e);
269             $notifyMethod     = 'addFailure';
270
271             if ($this->stopOnFailure) {
272                 $this->stop();
273             }
274         }
275
276         foreach ($this->listeners as $listener) {
277             $listener->$notifyMethod($test, $e, $time);
278         }
279
280         $this->lastTestFailed = true;
281         $this->time          += $time;
282     }
283
284     /**
285      * Informs the result that a testsuite will be started.
286      *
287      * @param PHPUnit_Framework_TestSuite $suite
288      *
289      * @since  Method available since Release 2.2.0
290      */
291     public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
292     {
293         if ($this->topTestSuite === null) {
294             $this->topTestSuite = $suite;
295         }
296
297         foreach ($this->listeners as $listener) {
298             $listener->startTestSuite($suite);
299         }
300     }
301
302     /**
303      * Informs the result that a testsuite was completed.
304      *
305      * @param PHPUnit_Framework_TestSuite $suite
306      *
307      * @since  Method available since Release 2.2.0
308      */
309     public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
310     {
311         foreach ($this->listeners as $listener) {
312             $listener->endTestSuite($suite);
313         }
314     }
315
316     /**
317      * Informs the result that a test will be started.
318      *
319      * @param PHPUnit_Framework_Test $test
320      */
321     public function startTest(PHPUnit_Framework_Test $test)
322     {
323         $this->lastTestFailed = false;
324         $this->runTests      += count($test);
325
326         foreach ($this->listeners as $listener) {
327             $listener->startTest($test);
328         }
329     }
330
331     /**
332      * Informs the result that a test was completed.
333      *
334      * @param PHPUnit_Framework_Test $test
335      * @param float                  $time
336      */
337     public function endTest(PHPUnit_Framework_Test $test, $time)
338     {
339         foreach ($this->listeners as $listener) {
340             $listener->endTest($test, $time);
341         }
342
343         if (!$this->lastTestFailed && $test instanceof PHPUnit_Framework_TestCase) {
344             $class  = get_class($test);
345             $key    = $class . '::' . $test->getName();
346
347             $this->passed[$key] = array(
348                 'result' => $test->getResult(),
349                 'size'   => PHPUnit_Util_Test::getSize(
350                     $class,
351                     $test->getName(false)
352                 )
353             );
354
355             $this->time += $time;
356         }
357     }
358
359     /**
360      * Returns true if no risky test occurred.
361      *
362      * @return bool
363      *
364      * @since  Method available since Release 4.0.0
365      */
366     public function allHarmless()
367     {
368         return $this->riskyCount() == 0;
369     }
370
371     /**
372      * Gets the number of risky tests.
373      *
374      * @return int
375      *
376      * @since  Method available since Release 4.0.0
377      */
378     public function riskyCount()
379     {
380         return count($this->risky);
381     }
382
383     /**
384      * Returns true if no incomplete test occurred.
385      *
386      * @return bool
387      */
388     public function allCompletelyImplemented()
389     {
390         return $this->notImplementedCount() == 0;
391     }
392
393     /**
394      * Gets the number of incomplete tests.
395      *
396      * @return int
397      */
398     public function notImplementedCount()
399     {
400         return count($this->notImplemented);
401     }
402
403     /**
404      * Returns an Enumeration for the risky tests.
405      *
406      * @return array
407      *
408      * @since  Method available since Release 4.0.0
409      */
410     public function risky()
411     {
412         return $this->risky;
413     }
414
415     /**
416      * Returns an Enumeration for the incomplete tests.
417      *
418      * @return array
419      */
420     public function notImplemented()
421     {
422         return $this->notImplemented;
423     }
424
425     /**
426      * Returns true if no test has been skipped.
427      *
428      * @return bool
429      *
430      * @since  Method available since Release 3.0.0
431      */
432     public function noneSkipped()
433     {
434         return $this->skippedCount() == 0;
435     }
436
437     /**
438      * Gets the number of skipped tests.
439      *
440      * @return int
441      *
442      * @since  Method available since Release 3.0.0
443      */
444     public function skippedCount()
445     {
446         return count($this->skipped);
447     }
448
449     /**
450      * Returns an Enumeration for the skipped tests.
451      *
452      * @return array
453      *
454      * @since  Method available since Release 3.0.0
455      */
456     public function skipped()
457     {
458         return $this->skipped;
459     }
460
461     /**
462      * Gets the number of detected errors.
463      *
464      * @return int
465      */
466     public function errorCount()
467     {
468         return count($this->errors);
469     }
470
471     /**
472      * Returns an Enumeration for the errors.
473      *
474      * @return array
475      */
476     public function errors()
477     {
478         return $this->errors;
479     }
480
481     /**
482      * Gets the number of detected failures.
483      *
484      * @return int
485      */
486     public function failureCount()
487     {
488         return count($this->failures);
489     }
490
491     /**
492      * Returns an Enumeration for the failures.
493      *
494      * @return array
495      */
496     public function failures()
497     {
498         return $this->failures;
499     }
500
501     /**
502      * Returns the names of the tests that have passed.
503      *
504      * @return array
505      *
506      * @since  Method available since Release 3.4.0
507      */
508     public function passed()
509     {
510         return $this->passed;
511     }
512
513     /**
514      * Returns the (top) test suite.
515      *
516      * @return PHPUnit_Framework_TestSuite
517      *
518      * @since  Method available since Release 3.0.0
519      */
520     public function topTestSuite()
521     {
522         return $this->topTestSuite;
523     }
524
525     /**
526      * Returns whether code coverage information should be collected.
527      *
528      * @return bool If code coverage should be collected
529      *
530      * @since  Method available since Release 3.2.0
531      */
532     public function getCollectCodeCoverageInformation()
533     {
534         return $this->codeCoverage !== null;
535     }
536
537     /**
538      * Runs a TestCase.
539      *
540      * @param PHPUnit_Framework_Test $test
541      */
542     public function run(PHPUnit_Framework_Test $test)
543     {
544         PHPUnit_Framework_Assert::resetCount();
545
546         $error      = false;
547         $failure    = false;
548         $incomplete = false;
549         $risky      = false;
550         $skipped    = false;
551
552         $this->startTest($test);
553
554         $errorHandlerSet = false;
555
556         if ($this->convertErrorsToExceptions) {
557             $oldErrorHandler = set_error_handler(
558                 array('PHPUnit_Util_ErrorHandler', 'handleError'),
559                 E_ALL | E_STRICT
560             );
561
562             if ($oldErrorHandler === null) {
563                 $errorHandlerSet = true;
564             } else {
565                 restore_error_handler();
566             }
567         }
568
569         $collectCodeCoverage = $this->codeCoverage !== null &&
570                                !$test instanceof PHPUnit_Extensions_SeleniumTestCase &&
571                                !$test instanceof PHPUnit_Framework_Warning;
572
573         if ($collectCodeCoverage) {
574             // We need to blacklist test source files when no whitelist is used.
575             if (!$this->codeCoverage->filter()->hasWhitelist()) {
576                 $classes = $this->getHierarchy(get_class($test), true);
577
578                 foreach ($classes as $class) {
579                     $this->codeCoverage->filter()->addFileToBlacklist(
580                         $class->getFileName()
581                     );
582                 }
583             }
584
585             $this->codeCoverage->start($test);
586         }
587
588         PHP_Timer::start();
589
590         try {
591             if (!$test instanceof PHPUnit_Framework_Warning &&
592                 $test->getSize() != PHPUnit_Util_Test::UNKNOWN &&
593                 $this->beStrictAboutTestSize &&
594                 extension_loaded('pcntl') && class_exists('PHP_Invoker')) {
595                 switch ($test->getSize()) {
596                     case PHPUnit_Util_Test::SMALL:
597                         $_timeout = $this->timeoutForSmallTests;
598                         break;
599
600                     case PHPUnit_Util_Test::MEDIUM:
601                         $_timeout = $this->timeoutForMediumTests;
602                         break;
603
604                     case PHPUnit_Util_Test::LARGE:
605                         $_timeout = $this->timeoutForLargeTests;
606                         break;
607                 }
608
609                 $invoker = new PHP_Invoker;
610                 $invoker->invoke(array($test, 'runBare'), array(), $_timeout);
611             } else {
612                 $test->runBare();
613             }
614         } catch (PHPUnit_Framework_AssertionFailedError $e) {
615             $failure = true;
616
617             if ($e instanceof PHPUnit_Framework_RiskyTestError) {
618                 $risky = true;
619             } elseif ($e instanceof PHPUnit_Framework_IncompleteTestError) {
620                 $incomplete = true;
621             } elseif ($e instanceof PHPUnit_Framework_SkippedTestError) {
622                 $skipped = true;
623             }
624         } catch (PHPUnit_Framework_Exception $e) {
625             $error = true;
626         } catch (Throwable $e) {
627             $e     = new PHPUnit_Framework_ExceptionWrapper($e);
628             $error = true;
629         } catch (Exception $e) {
630             $e     = new PHPUnit_Framework_ExceptionWrapper($e);
631             $error = true;
632         }
633
634         $time = PHP_Timer::stop();
635         $test->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
636
637         if ($this->beStrictAboutTestsThatDoNotTestAnything &&
638             $test->getNumAssertions() == 0) {
639             $risky = true;
640         }
641
642         if ($collectCodeCoverage) {
643             $append           = !$risky && !$incomplete && !$skipped;
644             $linesToBeCovered = array();
645             $linesToBeUsed    = array();
646
647             if ($append && $test instanceof PHPUnit_Framework_TestCase) {
648                 $linesToBeCovered = PHPUnit_Util_Test::getLinesToBeCovered(
649                     get_class($test),
650                     $test->getName(false)
651                 );
652
653                 $linesToBeUsed = PHPUnit_Util_Test::getLinesToBeUsed(
654                     get_class($test),
655                     $test->getName(false)
656                 );
657             }
658
659             try {
660                 $this->codeCoverage->stop(
661                     $append,
662                     $linesToBeCovered,
663                     $linesToBeUsed
664                 );
665             } catch (PHP_CodeCoverage_Exception_UnintentionallyCoveredCode $cce) {
666                 $this->addFailure(
667                     $test,
668                     new PHPUnit_Framework_UnintentionallyCoveredCodeError(
669                         'This test executed code that is not listed as code to be covered or used:' .
670                         PHP_EOL . $cce->getMessage()
671                     ),
672                     $time
673                 );
674             } catch (PHPUnit_Framework_InvalidCoversTargetException $cce) {
675                 $this->addFailure(
676                     $test,
677                     new PHPUnit_Framework_InvalidCoversTargetError(
678                         $cce->getMessage()
679                     ),
680                     $time
681                 );
682             } catch (PHP_CodeCoverage_Exception $cce) {
683                 $error = true;
684
685                 if (!isset($e)) {
686                     $e = $cce;
687                 }
688             }
689         }
690
691         if ($errorHandlerSet === true) {
692             restore_error_handler();
693         }
694
695         if ($error === true) {
696             $this->addError($test, $e, $time);
697         } elseif ($failure === true) {
698             $this->addFailure($test, $e, $time);
699         } elseif ($this->beStrictAboutTestsThatDoNotTestAnything &&
700                  $test->getNumAssertions() == 0) {
701             $this->addFailure(
702                 $test,
703                 new PHPUnit_Framework_RiskyTestError(
704                     'This test did not perform any assertions'
705                 ),
706                 $time
707             );
708         } elseif ($this->beStrictAboutOutputDuringTests && $test->hasOutput()) {
709             $this->addFailure(
710                 $test,
711                 new PHPUnit_Framework_OutputError(
712                     sprintf(
713                         'This test printed output: %s',
714                         $test->getActualOutput()
715                     )
716                 ),
717                 $time
718             );
719         } elseif ($this->beStrictAboutTodoAnnotatedTests && $test instanceof PHPUnit_Framework_TestCase) {
720             $annotations = $test->getAnnotations();
721
722             if (isset($annotations['method']['todo'])) {
723                 $this->addFailure(
724                     $test,
725                     new PHPUnit_Framework_RiskyTestError(
726                         'Test method is annotated with @todo'
727                     ),
728                     $time
729                 );
730             }
731         }
732
733         $this->endTest($test, $time);
734     }
735
736     /**
737      * Gets the number of run tests.
738      *
739      * @return int
740      */
741     public function count()
742     {
743         return $this->runTests;
744     }
745
746     /**
747      * Checks whether the test run should stop.
748      *
749      * @return bool
750      */
751     public function shouldStop()
752     {
753         return $this->stop;
754     }
755
756     /**
757      * Marks that the test run should stop.
758      */
759     public function stop()
760     {
761         $this->stop = true;
762     }
763
764     /**
765      * Returns the PHP_CodeCoverage object.
766      *
767      * @return PHP_CodeCoverage
768      *
769      * @since  Method available since Release 3.5.0
770      */
771     public function getCodeCoverage()
772     {
773         return $this->codeCoverage;
774     }
775
776     /**
777      * Sets the PHP_CodeCoverage object.
778      *
779      * @param PHP_CodeCoverage $codeCoverage
780      *
781      * @since Method available since Release 3.6.0
782      */
783     public function setCodeCoverage(PHP_CodeCoverage $codeCoverage)
784     {
785         $this->codeCoverage = $codeCoverage;
786     }
787
788     /**
789      * Enables or disables the error-to-exception conversion.
790      *
791      * @param bool $flag
792      *
793      * @throws PHPUnit_Framework_Exception
794      *
795      * @since  Method available since Release 3.2.14
796      */
797     public function convertErrorsToExceptions($flag)
798     {
799         if (!is_bool($flag)) {
800             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean');
801         }
802
803         $this->convertErrorsToExceptions = $flag;
804     }
805
806     /**
807      * Returns the error-to-exception conversion setting.
808      *
809      * @return bool
810      *
811      * @since  Method available since Release 3.4.0
812      */
813     public function getConvertErrorsToExceptions()
814     {
815         return $this->convertErrorsToExceptions;
816     }
817
818     /**
819      * Enables or disables the stopping when an error occurs.
820      *
821      * @param bool $flag
822      *
823      * @throws PHPUnit_Framework_Exception
824      *
825      * @since  Method available since Release 3.5.0
826      */
827     public function stopOnError($flag)
828     {
829         if (!is_bool($flag)) {
830             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean');
831         }
832
833         $this->stopOnError = $flag;
834     }
835
836     /**
837      * Enables or disables the stopping when a failure occurs.
838      *
839      * @param bool $flag
840      *
841      * @throws PHPUnit_Framework_Exception
842      *
843      * @since  Method available since Release 3.1.0
844      */
845     public function stopOnFailure($flag)
846     {
847         if (!is_bool($flag)) {
848             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean');
849         }
850
851         $this->stopOnFailure = $flag;
852     }
853
854     /**
855      * @param bool $flag
856      *
857      * @throws PHPUnit_Framework_Exception
858      *
859      * @since  Method available since Release 4.0.0
860      */
861     public function beStrictAboutTestsThatDoNotTestAnything($flag)
862     {
863         if (!is_bool($flag)) {
864             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean');
865         }
866
867         $this->beStrictAboutTestsThatDoNotTestAnything = $flag;
868     }
869
870     /**
871      * @return bool
872      *
873      * @since  Method available since Release 4.0.0
874      */
875     public function isStrictAboutTestsThatDoNotTestAnything()
876     {
877         return $this->beStrictAboutTestsThatDoNotTestAnything;
878     }
879
880     /**
881      * @param bool $flag
882      *
883      * @throws PHPUnit_Framework_Exception
884      *
885      * @since  Method available since Release 4.0.0
886      */
887     public function beStrictAboutOutputDuringTests($flag)
888     {
889         if (!is_bool($flag)) {
890             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean');
891         }
892
893         $this->beStrictAboutOutputDuringTests = $flag;
894     }
895
896     /**
897      * @return bool
898      *
899      * @since  Method available since Release 4.0.0
900      */
901     public function isStrictAboutOutputDuringTests()
902     {
903         return $this->beStrictAboutOutputDuringTests;
904     }
905
906     /**
907      * @param bool $flag
908      *
909      * @throws PHPUnit_Framework_Exception
910      *
911      * @since  Method available since Release 4.0.0
912      */
913     public function beStrictAboutTestSize($flag)
914     {
915         if (!is_bool($flag)) {
916             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean');
917         }
918
919         $this->beStrictAboutTestSize = $flag;
920     }
921
922     /**
923      * @return bool
924      *
925      * @since  Method available since Release 4.0.0
926      */
927     public function isStrictAboutTestSize()
928     {
929         return $this->beStrictAboutTestSize;
930     }
931
932     /**
933      * @param bool $flag
934      *
935      * @throws PHPUnit_Framework_Exception
936      *
937      * @since  Method available since Release 4.2.0
938      */
939     public function beStrictAboutTodoAnnotatedTests($flag)
940     {
941         if (!is_bool($flag)) {
942             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean');
943         }
944
945         $this->beStrictAboutTodoAnnotatedTests = $flag;
946     }
947
948     /**
949      * @return bool
950      *
951      * @since  Method available since Release 4.2.0
952      */
953     public function isStrictAboutTodoAnnotatedTests()
954     {
955         return $this->beStrictAboutTodoAnnotatedTests;
956     }
957
958     /**
959      * Enables or disables the stopping for risky tests.
960      *
961      * @param bool $flag
962      *
963      * @throws PHPUnit_Framework_Exception
964      *
965      * @since  Method available since Release 4.0.0
966      */
967     public function stopOnRisky($flag)
968     {
969         if (!is_bool($flag)) {
970             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean');
971         }
972
973         $this->stopOnRisky = $flag;
974     }
975
976     /**
977      * Enables or disables the stopping for incomplete tests.
978      *
979      * @param bool $flag
980      *
981      * @throws PHPUnit_Framework_Exception
982      *
983      * @since  Method available since Release 3.5.0
984      */
985     public function stopOnIncomplete($flag)
986     {
987         if (!is_bool($flag)) {
988             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean');
989         }
990
991         $this->stopOnIncomplete = $flag;
992     }
993
994     /**
995      * Enables or disables the stopping for skipped tests.
996      *
997      * @param bool $flag
998      *
999      * @throws PHPUnit_Framework_Exception
1000      *
1001      * @since  Method available since Release 3.1.0
1002      */
1003     public function stopOnSkipped($flag)
1004     {
1005         if (!is_bool($flag)) {
1006             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean');
1007         }
1008
1009         $this->stopOnSkipped = $flag;
1010     }
1011
1012     /**
1013      * Returns the time spent running the tests.
1014      *
1015      * @return float
1016      */
1017     public function time()
1018     {
1019         return $this->time;
1020     }
1021
1022     /**
1023      * Returns whether the entire test was successful or not.
1024      *
1025      * @return bool
1026      */
1027     public function wasSuccessful()
1028     {
1029         return empty($this->errors) && empty($this->failures);
1030     }
1031
1032     /**
1033      * Sets the timeout for small tests.
1034      *
1035      * @param int $timeout
1036      *
1037      * @throws PHPUnit_Framework_Exception
1038      *
1039      * @since  Method available since Release 3.6.0
1040      */
1041     public function setTimeoutForSmallTests($timeout)
1042     {
1043         if (!is_integer($timeout)) {
1044             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer');
1045         }
1046
1047         $this->timeoutForSmallTests = $timeout;
1048     }
1049
1050     /**
1051      * Sets the timeout for medium tests.
1052      *
1053      * @param int $timeout
1054      *
1055      * @throws PHPUnit_Framework_Exception
1056      *
1057      * @since  Method available since Release 3.6.0
1058      */
1059     public function setTimeoutForMediumTests($timeout)
1060     {
1061         if (!is_integer($timeout)) {
1062             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer');
1063         }
1064
1065         $this->timeoutForMediumTests = $timeout;
1066     }
1067
1068     /**
1069      * Sets the timeout for large tests.
1070      *
1071      * @param int $timeout
1072      *
1073      * @throws PHPUnit_Framework_Exception
1074      *
1075      * @since  Method available since Release 3.6.0
1076      */
1077     public function setTimeoutForLargeTests($timeout)
1078     {
1079         if (!is_integer($timeout)) {
1080             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer');
1081         }
1082
1083         $this->timeoutForLargeTests = $timeout;
1084     }
1085
1086     /**
1087      * Returns the class hierarchy for a given class.
1088      *
1089      * @param string $className
1090      * @param bool   $asReflectionObjects
1091      *
1092      * @return array
1093      */
1094     protected function getHierarchy($className, $asReflectionObjects = false)
1095     {
1096         if ($asReflectionObjects) {
1097             $classes = array(new ReflectionClass($className));
1098         } else {
1099             $classes = array($className);
1100         }
1101
1102         $done = false;
1103
1104         while (!$done) {
1105             if ($asReflectionObjects) {
1106                 $class = new ReflectionClass(
1107                     $classes[count($classes) - 1]->getName()
1108                 );
1109             } else {
1110                 $class = new ReflectionClass($classes[count($classes) - 1]);
1111             }
1112
1113             $parent = $class->getParentClass();
1114
1115             if ($parent !== false) {
1116                 if ($asReflectionObjects) {
1117                     $classes[] = $parent;
1118                 } else {
1119                     $classes[] = $parent->getName();
1120                 }
1121             } else {
1122                 $done = true;
1123             }
1124         }
1125
1126         return $classes;
1127     }
1128 }