Version 1
[yaffs-website] / vendor / phpunit / phpunit / src / TextUI / TestRunner.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 use SebastianBergmann\Environment\Runtime;
12
13 /**
14  * A TestRunner for the Command Line Interface (CLI)
15  * PHP SAPI Module.
16  *
17  * @since Class available since Release 2.0.0
18  */
19 class PHPUnit_TextUI_TestRunner extends PHPUnit_Runner_BaseTestRunner
20 {
21     const SUCCESS_EXIT   = 0;
22     const FAILURE_EXIT   = 1;
23     const EXCEPTION_EXIT = 2;
24
25     /**
26      * @var PHP_CodeCoverage_Filter
27      */
28     protected $codeCoverageFilter;
29
30     /**
31      * @var PHPUnit_Runner_TestSuiteLoader
32      */
33     protected $loader = null;
34
35     /**
36      * @var PHPUnit_TextUI_ResultPrinter
37      */
38     protected $printer = null;
39
40     /**
41      * @var bool
42      */
43     protected static $versionStringPrinted = false;
44
45     /**
46      * @var array
47      */
48     private $missingExtensions = array();
49
50     /**
51      * @var Runtime
52      */
53     private $runtime;
54
55     /**
56      * @param PHPUnit_Runner_TestSuiteLoader $loader
57      * @param PHP_CodeCoverage_Filter        $filter
58      *
59      * @since Method available since Release 3.4.0
60      */
61     public function __construct(PHPUnit_Runner_TestSuiteLoader $loader = null, PHP_CodeCoverage_Filter $filter = null)
62     {
63         if ($filter === null) {
64             $filter = $this->getCodeCoverageFilter();
65         }
66
67         $this->codeCoverageFilter = $filter;
68         $this->loader             = $loader;
69         $this->runtime            = new Runtime;
70     }
71
72     /**
73      * @param PHPUnit_Framework_Test|ReflectionClass $test
74      * @param array                                  $arguments
75      *
76      * @return PHPUnit_Framework_TestResult
77      *
78      * @throws PHPUnit_Framework_Exception
79      */
80     public static function run($test, array $arguments = array())
81     {
82         if ($test instanceof ReflectionClass) {
83             $test = new PHPUnit_Framework_TestSuite($test);
84         }
85
86         if ($test instanceof PHPUnit_Framework_Test) {
87             $aTestRunner = new self;
88
89             return $aTestRunner->doRun(
90                 $test,
91                 $arguments
92             );
93         } else {
94             throw new PHPUnit_Framework_Exception(
95                 'No test case or test suite found.'
96             );
97         }
98     }
99
100     /**
101      * @return PHPUnit_Framework_TestResult
102      */
103     protected function createTestResult()
104     {
105         return new PHPUnit_Framework_TestResult;
106     }
107
108     private function processSuiteFilters(PHPUnit_Framework_TestSuite $suite, array $arguments)
109     {
110         if (!$arguments['filter'] &&
111             empty($arguments['groups']) &&
112             empty($arguments['excludeGroups'])) {
113             return;
114         }
115
116         $filterFactory = new PHPUnit_Runner_Filter_Factory();
117
118         if (!empty($arguments['excludeGroups'])) {
119             $filterFactory->addFilter(
120                 new ReflectionClass('PHPUnit_Runner_Filter_Group_Exclude'),
121                 $arguments['excludeGroups']
122             );
123         }
124
125         if (!empty($arguments['groups'])) {
126             $filterFactory->addFilter(
127                 new ReflectionClass('PHPUnit_Runner_Filter_Group_Include'),
128                 $arguments['groups']
129             );
130         }
131
132         if ($arguments['filter']) {
133             $filterFactory->addFilter(
134                 new ReflectionClass('PHPUnit_Runner_Filter_Test'),
135                 $arguments['filter']
136             );
137         }
138         $suite->injectFilter($filterFactory);
139     }
140
141     /**
142      * @param PHPUnit_Framework_Test $suite
143      * @param array                  $arguments
144      *
145      * @return PHPUnit_Framework_TestResult
146      */
147     public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
148     {
149         if (isset($arguments['configuration'])) {
150             $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] = $arguments['configuration'];
151         }
152
153         $this->handleConfiguration($arguments);
154
155         $this->processSuiteFilters($suite, $arguments);
156
157         if (isset($arguments['bootstrap'])) {
158             $GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap'];
159         }
160
161         if ($arguments['backupGlobals'] === false) {
162             $suite->setBackupGlobals(false);
163         }
164
165         if ($arguments['backupStaticAttributes'] === true) {
166             $suite->setBackupStaticAttributes(true);
167         }
168
169         if ($arguments['disallowChangesToGlobalState'] === true) {
170             $suite->setDisallowChangesToGlobalState(true);
171         }
172
173         if (is_integer($arguments['repeat'])) {
174             $test = new PHPUnit_Extensions_RepeatedTest(
175                 $suite,
176                 $arguments['repeat'],
177                 $arguments['processIsolation']
178             );
179
180             $suite = new PHPUnit_Framework_TestSuite();
181             $suite->addTest($test);
182         }
183
184         $result = $this->createTestResult();
185
186         if (!$arguments['convertErrorsToExceptions']) {
187             $result->convertErrorsToExceptions(false);
188         }
189
190         if (!$arguments['convertNoticesToExceptions']) {
191             PHPUnit_Framework_Error_Notice::$enabled = false;
192         }
193
194         if (!$arguments['convertWarningsToExceptions']) {
195             PHPUnit_Framework_Error_Warning::$enabled = false;
196         }
197
198         if ($arguments['stopOnError']) {
199             $result->stopOnError(true);
200         }
201
202         if ($arguments['stopOnFailure']) {
203             $result->stopOnFailure(true);
204         }
205
206         if ($arguments['stopOnIncomplete']) {
207             $result->stopOnIncomplete(true);
208         }
209
210         if ($arguments['stopOnRisky']) {
211             $result->stopOnRisky(true);
212         }
213
214         if ($arguments['stopOnSkipped']) {
215             $result->stopOnSkipped(true);
216         }
217
218         if ($this->printer === null) {
219             if (isset($arguments['printer']) &&
220                 $arguments['printer'] instanceof PHPUnit_Util_Printer) {
221                 $this->printer = $arguments['printer'];
222             } else {
223                 $printerClass = 'PHPUnit_TextUI_ResultPrinter';
224
225                 if (isset($arguments['printer']) &&
226                     is_string($arguments['printer']) &&
227                     class_exists($arguments['printer'], false)) {
228                     $class = new ReflectionClass($arguments['printer']);
229
230                     if ($class->isSubclassOf('PHPUnit_TextUI_ResultPrinter')) {
231                         $printerClass = $arguments['printer'];
232                     }
233                 }
234
235                 $this->printer = new $printerClass(
236                   isset($arguments['stderr']) ? 'php://stderr' : null,
237                   $arguments['verbose'],
238                   $arguments['colors'],
239                   $arguments['debug'],
240                   $arguments['columns']
241                 );
242             }
243         }
244
245         if (!$this->printer instanceof PHPUnit_Util_Log_TAP) {
246             $this->printer->write(
247                 PHPUnit_Runner_Version::getVersionString() . "\n"
248             );
249
250             self::$versionStringPrinted = true;
251
252             if ($arguments['verbose']) {
253                 $this->printer->write(
254                     sprintf(
255                         "\nRuntime:\t%s",
256                         $this->runtime->getNameWithVersion()
257                     )
258                 );
259
260                 if ($this->runtime->hasXdebug()) {
261                     $this->printer->write(
262                         sprintf(
263                             ' with Xdebug %s',
264                             phpversion('xdebug')
265                         )
266                     );
267                 }
268
269                 if (isset($arguments['configuration'])) {
270                     $this->printer->write(
271                         sprintf(
272                             "\nConfiguration:\t%s",
273                             $arguments['configuration']->getFilename()
274                         )
275                     );
276                 }
277
278                 $this->printer->write("\n");
279             }
280
281             if (isset($arguments['deprecatedStrictModeOption'])) {
282                 print "Warning:\tDeprecated option \"--strict\" used\n";
283             } elseif (isset($arguments['deprecatedStrictModeSetting'])) {
284                 print "Warning:\tDeprecated configuration setting \"strict\" used\n";
285             }
286
287             if (isset($arguments['deprecatedSeleniumConfiguration'])) {
288                 print "Warning:\tDeprecated configuration setting \"selenium\" used\n";
289             }
290         }
291
292         foreach ($arguments['listeners'] as $listener) {
293             $result->addListener($listener);
294         }
295
296         $result->addListener($this->printer);
297
298         if (isset($arguments['testdoxHTMLFile'])) {
299             $result->addListener(
300                 new PHPUnit_Util_TestDox_ResultPrinter_HTML(
301                     $arguments['testdoxHTMLFile']
302                 )
303             );
304         }
305
306         if (isset($arguments['testdoxTextFile'])) {
307             $result->addListener(
308                 new PHPUnit_Util_TestDox_ResultPrinter_Text(
309                     $arguments['testdoxTextFile']
310                 )
311             );
312         }
313
314         $codeCoverageReports = 0;
315
316         if (isset($arguments['coverageClover'])) {
317             $codeCoverageReports++;
318         }
319
320         if (isset($arguments['coverageCrap4J'])) {
321             $codeCoverageReports++;
322         }
323
324         if (isset($arguments['coverageHtml'])) {
325             $codeCoverageReports++;
326         }
327
328         if (isset($arguments['coveragePHP'])) {
329             $codeCoverageReports++;
330         }
331
332         if (isset($arguments['coverageText'])) {
333             $codeCoverageReports++;
334         }
335
336         if (isset($arguments['coverageXml'])) {
337             $codeCoverageReports++;
338         }
339
340         if (isset($arguments['noCoverage'])) {
341             $codeCoverageReports = 0;
342         }
343
344         if ($codeCoverageReports > 0 && (!extension_loaded('tokenizer') || !$this->runtime->canCollectCodeCoverage())) {
345             if (!extension_loaded('tokenizer')) {
346                 $this->showExtensionNotLoadedWarning(
347                     'tokenizer',
348                     'No code coverage will be generated.'
349                 );
350             } elseif (!extension_loaded('Xdebug')) {
351                 $this->showExtensionNotLoadedWarning(
352                     'Xdebug',
353                     'No code coverage will be generated.'
354                 );
355             }
356
357             $codeCoverageReports = 0;
358         }
359
360         if (!$this->printer instanceof PHPUnit_Util_Log_TAP) {
361             if ($codeCoverageReports > 0 && !$this->codeCoverageFilter->hasWhitelist()) {
362                 $this->printer->write("Warning:\tNo whitelist configured for code coverage\n");
363             }
364
365             $this->printer->write("\n");
366         }
367
368         if ($codeCoverageReports > 0) {
369             $codeCoverage = new PHP_CodeCoverage(
370                 null,
371                 $this->codeCoverageFilter
372             );
373
374             $codeCoverage->setAddUncoveredFilesFromWhitelist(
375                 $arguments['addUncoveredFilesFromWhitelist']
376             );
377
378             $codeCoverage->setCheckForUnintentionallyCoveredCode(
379                 $arguments['strictCoverage']
380             );
381
382             $codeCoverage->setProcessUncoveredFilesFromWhitelist(
383                 $arguments['processUncoveredFilesFromWhitelist']
384             );
385
386             if (isset($arguments['forceCoversAnnotation'])) {
387                 $codeCoverage->setForceCoversAnnotation(
388                     $arguments['forceCoversAnnotation']
389                 );
390             }
391
392             if (isset($arguments['mapTestClassNameToCoveredClassName'])) {
393                 $codeCoverage->setMapTestClassNameToCoveredClassName(
394                     $arguments['mapTestClassNameToCoveredClassName']
395                 );
396             }
397
398             $result->setCodeCoverage($codeCoverage);
399         }
400
401         if ($codeCoverageReports > 1) {
402             if (isset($arguments['cacheTokens'])) {
403                 $codeCoverage->setCacheTokens($arguments['cacheTokens']);
404             }
405         }
406
407         if (isset($arguments['jsonLogfile'])) {
408             $result->addListener(
409                 new PHPUnit_Util_Log_JSON($arguments['jsonLogfile'])
410             );
411         }
412
413         if (isset($arguments['tapLogfile'])) {
414             $result->addListener(
415                 new PHPUnit_Util_Log_TAP($arguments['tapLogfile'])
416             );
417         }
418
419         if (isset($arguments['junitLogfile'])) {
420             $result->addListener(
421                 new PHPUnit_Util_Log_JUnit(
422                     $arguments['junitLogfile'],
423                     $arguments['logIncompleteSkipped']
424                 )
425             );
426         }
427
428         $result->beStrictAboutTestsThatDoNotTestAnything($arguments['reportUselessTests']);
429         $result->beStrictAboutOutputDuringTests($arguments['disallowTestOutput']);
430         $result->beStrictAboutTodoAnnotatedTests($arguments['disallowTodoAnnotatedTests']);
431         $result->beStrictAboutTestSize($arguments['enforceTimeLimit']);
432         $result->setTimeoutForSmallTests($arguments['timeoutForSmallTests']);
433         $result->setTimeoutForMediumTests($arguments['timeoutForMediumTests']);
434         $result->setTimeoutForLargeTests($arguments['timeoutForLargeTests']);
435
436         if ($suite instanceof PHPUnit_Framework_TestSuite) {
437             $suite->setRunTestInSeparateProcess($arguments['processIsolation']);
438         }
439
440         $suite->run($result);
441
442         unset($suite);
443         $result->flushListeners();
444
445         if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
446             $this->printer->printResult($result);
447         }
448
449         if (isset($codeCoverage)) {
450             if (isset($arguments['coverageClover'])) {
451                 $this->printer->write(
452                     "\nGenerating code coverage report in Clover XML format ..."
453                 );
454
455                 try {
456                     $writer = new PHP_CodeCoverage_Report_Clover;
457                     $writer->process($codeCoverage, $arguments['coverageClover']);
458
459                     $this->printer->write(" done\n");
460                     unset($writer);
461                 } catch (PHP_CodeCoverage_Exception $e) {
462                     $this->printer->write(
463                         " failed\n" . $e->getMessage() . "\n"
464                     );
465                 }
466             }
467
468             if (isset($arguments['coverageCrap4J'])) {
469                 $this->printer->write(
470                     "\nGenerating Crap4J report XML file ..."
471                 );
472
473                 try {
474                     $writer = new PHP_CodeCoverage_Report_Crap4j($arguments['crap4jThreshold']);
475                     $writer->process($codeCoverage, $arguments['coverageCrap4J']);
476
477                     $this->printer->write(" done\n");
478                     unset($writer);
479                 } catch (PHP_CodeCoverage_Exception $e) {
480                     $this->printer->write(
481                         " failed\n" . $e->getMessage() . "\n"
482                     );
483                 }
484             }
485
486             if (isset($arguments['coverageHtml'])) {
487                 $this->printer->write(
488                     "\nGenerating code coverage report in HTML format ..."
489                 );
490
491                 try {
492                     $writer = new PHP_CodeCoverage_Report_HTML(
493                         $arguments['reportLowUpperBound'],
494                         $arguments['reportHighLowerBound'],
495                         sprintf(
496                             ' and <a href="https://phpunit.de/">PHPUnit %s</a>',
497                             PHPUnit_Runner_Version::id()
498                         )
499                     );
500
501                     $writer->process($codeCoverage, $arguments['coverageHtml']);
502
503                     $this->printer->write(" done\n");
504                     unset($writer);
505                 } catch (PHP_CodeCoverage_Exception $e) {
506                     $this->printer->write(
507                         " failed\n" . $e->getMessage() . "\n"
508                     );
509                 }
510             }
511
512             if (isset($arguments['coveragePHP'])) {
513                 $this->printer->write(
514                     "\nGenerating code coverage report in PHP format ..."
515                 );
516
517                 try {
518                     $writer = new PHP_CodeCoverage_Report_PHP;
519                     $writer->process($codeCoverage, $arguments['coveragePHP']);
520
521                     $this->printer->write(" done\n");
522                     unset($writer);
523                 } catch (PHP_CodeCoverage_Exception $e) {
524                     $this->printer->write(
525                         " failed\n" . $e->getMessage() . "\n"
526                     );
527                 }
528             }
529
530             if (isset($arguments['coverageText'])) {
531                 if ($arguments['coverageText'] == 'php://stdout') {
532                     $outputStream = $this->printer;
533                     $colors       = $arguments['colors'] && $arguments['colors'] != PHPUnit_TextUI_ResultPrinter::COLOR_NEVER;
534                 } else {
535                     $outputStream = new PHPUnit_Util_Printer($arguments['coverageText']);
536                     $colors       = false;
537                 }
538
539                 $processor = new PHP_CodeCoverage_Report_Text(
540                     $arguments['reportLowUpperBound'],
541                     $arguments['reportHighLowerBound'],
542                     $arguments['coverageTextShowUncoveredFiles'],
543                     $arguments['coverageTextShowOnlySummary']
544                 );
545
546                 $outputStream->write(
547                     $processor->process($codeCoverage, $colors)
548                 );
549             }
550
551             if (isset($arguments['coverageXml'])) {
552                 $this->printer->write(
553                     "\nGenerating code coverage report in PHPUnit XML format ..."
554                 );
555
556                 try {
557                     $writer = new PHP_CodeCoverage_Report_XML;
558                     $writer->process($codeCoverage, $arguments['coverageXml']);
559
560                     $this->printer->write(" done\n");
561                     unset($writer);
562                 } catch (PHP_CodeCoverage_Exception $e) {
563                     $this->printer->write(
564                         " failed\n" . $e->getMessage() . "\n"
565                     );
566                 }
567             }
568         }
569
570         return $result;
571     }
572
573     /**
574      * @param PHPUnit_TextUI_ResultPrinter $resultPrinter
575      */
576     public function setPrinter(PHPUnit_TextUI_ResultPrinter $resultPrinter)
577     {
578         $this->printer = $resultPrinter;
579     }
580
581     /**
582      * Override to define how to handle a failed loading of
583      * a test suite.
584      *
585      * @param string $message
586      */
587     protected function runFailed($message)
588     {
589         $this->write($message . PHP_EOL);
590         exit(self::FAILURE_EXIT);
591     }
592
593     /**
594      * @param string $buffer
595      *
596      * @since  Method available since Release 3.1.0
597      */
598     protected function write($buffer)
599     {
600         if (PHP_SAPI != 'cli' && PHP_SAPI != 'phpdbg') {
601             $buffer = htmlspecialchars($buffer);
602         }
603
604         if ($this->printer !== null) {
605             $this->printer->write($buffer);
606         } else {
607             print $buffer;
608         }
609     }
610
611     /**
612      * Returns the loader to be used.
613      *
614      * @return PHPUnit_Runner_TestSuiteLoader
615      *
616      * @since  Method available since Release 2.2.0
617      */
618     public function getLoader()
619     {
620         if ($this->loader === null) {
621             $this->loader = new PHPUnit_Runner_StandardTestSuiteLoader;
622         }
623
624         return $this->loader;
625     }
626
627     /**
628      * @param array $arguments
629      *
630      * @since  Method available since Release 3.2.1
631      */
632     protected function handleConfiguration(array &$arguments)
633     {
634         if (isset($arguments['configuration']) &&
635             !$arguments['configuration'] instanceof PHPUnit_Util_Configuration) {
636             $arguments['configuration'] = PHPUnit_Util_Configuration::getInstance(
637                 $arguments['configuration']
638             );
639         }
640
641         $arguments['debug']     = isset($arguments['debug'])     ? $arguments['debug']     : false;
642         $arguments['filter']    = isset($arguments['filter'])    ? $arguments['filter']    : false;
643         $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
644
645         if (isset($arguments['configuration'])) {
646             $arguments['configuration']->handlePHPConfiguration();
647
648             $phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration();
649
650             if (isset($phpunitConfiguration['deprecatedStrictModeSetting'])) {
651                 $arguments['deprecatedStrictModeSetting'] = true;
652             }
653
654             if (isset($phpunitConfiguration['backupGlobals']) &&
655                 !isset($arguments['backupGlobals'])) {
656                 $arguments['backupGlobals'] = $phpunitConfiguration['backupGlobals'];
657             }
658
659             if (isset($phpunitConfiguration['backupStaticAttributes']) &&
660                 !isset($arguments['backupStaticAttributes'])) {
661                 $arguments['backupStaticAttributes'] = $phpunitConfiguration['backupStaticAttributes'];
662             }
663
664             if (isset($phpunitConfiguration['disallowChangesToGlobalState']) &&
665                 !isset($arguments['disallowChangesToGlobalState'])) {
666                 $arguments['disallowChangesToGlobalState'] = $phpunitConfiguration['disallowChangesToGlobalState'];
667             }
668
669             if (isset($phpunitConfiguration['bootstrap']) &&
670                 !isset($arguments['bootstrap'])) {
671                 $arguments['bootstrap'] = $phpunitConfiguration['bootstrap'];
672             }
673
674             if (isset($phpunitConfiguration['cacheTokens']) &&
675                 !isset($arguments['cacheTokens'])) {
676                 $arguments['cacheTokens'] = $phpunitConfiguration['cacheTokens'];
677             }
678
679             if (isset($phpunitConfiguration['colors']) &&
680                 !isset($arguments['colors'])) {
681                 $arguments['colors'] = $phpunitConfiguration['colors'];
682             }
683
684             if (isset($phpunitConfiguration['convertErrorsToExceptions']) &&
685                 !isset($arguments['convertErrorsToExceptions'])) {
686                 $arguments['convertErrorsToExceptions'] = $phpunitConfiguration['convertErrorsToExceptions'];
687             }
688
689             if (isset($phpunitConfiguration['convertNoticesToExceptions']) &&
690                 !isset($arguments['convertNoticesToExceptions'])) {
691                 $arguments['convertNoticesToExceptions'] = $phpunitConfiguration['convertNoticesToExceptions'];
692             }
693
694             if (isset($phpunitConfiguration['convertWarningsToExceptions']) &&
695                 !isset($arguments['convertWarningsToExceptions'])) {
696                 $arguments['convertWarningsToExceptions'] = $phpunitConfiguration['convertWarningsToExceptions'];
697             }
698
699             if (isset($phpunitConfiguration['processIsolation']) &&
700                 !isset($arguments['processIsolation'])) {
701                 $arguments['processIsolation'] = $phpunitConfiguration['processIsolation'];
702             }
703
704             if (isset($phpunitConfiguration['stopOnError']) &&
705                 !isset($arguments['stopOnError'])) {
706                 $arguments['stopOnError'] = $phpunitConfiguration['stopOnError'];
707             }
708
709             if (isset($phpunitConfiguration['stopOnFailure']) &&
710                 !isset($arguments['stopOnFailure'])) {
711                 $arguments['stopOnFailure'] = $phpunitConfiguration['stopOnFailure'];
712             }
713
714             if (isset($phpunitConfiguration['stopOnIncomplete']) &&
715                 !isset($arguments['stopOnIncomplete'])) {
716                 $arguments['stopOnIncomplete'] = $phpunitConfiguration['stopOnIncomplete'];
717             }
718
719             if (isset($phpunitConfiguration['stopOnRisky']) &&
720                 !isset($arguments['stopOnRisky'])) {
721                 $arguments['stopOnRisky'] = $phpunitConfiguration['stopOnRisky'];
722             }
723
724             if (isset($phpunitConfiguration['stopOnSkipped']) &&
725                 !isset($arguments['stopOnSkipped'])) {
726                 $arguments['stopOnSkipped'] = $phpunitConfiguration['stopOnSkipped'];
727             }
728
729             if (isset($phpunitConfiguration['timeoutForSmallTests']) &&
730                 !isset($arguments['timeoutForSmallTests'])) {
731                 $arguments['timeoutForSmallTests'] = $phpunitConfiguration['timeoutForSmallTests'];
732             }
733
734             if (isset($phpunitConfiguration['timeoutForMediumTests']) &&
735                 !isset($arguments['timeoutForMediumTests'])) {
736                 $arguments['timeoutForMediumTests'] = $phpunitConfiguration['timeoutForMediumTests'];
737             }
738
739             if (isset($phpunitConfiguration['timeoutForLargeTests']) &&
740                 !isset($arguments['timeoutForLargeTests'])) {
741                 $arguments['timeoutForLargeTests'] = $phpunitConfiguration['timeoutForLargeTests'];
742             }
743
744             if (isset($phpunitConfiguration['reportUselessTests']) &&
745                 !isset($arguments['reportUselessTests'])) {
746                 $arguments['reportUselessTests'] = $phpunitConfiguration['reportUselessTests'];
747             }
748
749             if (isset($phpunitConfiguration['strictCoverage']) &&
750                 !isset($arguments['strictCoverage'])) {
751                 $arguments['strictCoverage'] = $phpunitConfiguration['strictCoverage'];
752             }
753
754             if (isset($phpunitConfiguration['disallowTestOutput']) &&
755                 !isset($arguments['disallowTestOutput'])) {
756                 $arguments['disallowTestOutput'] = $phpunitConfiguration['disallowTestOutput'];
757             }
758
759             if (isset($phpunitConfiguration['enforceTimeLimit']) &&
760                 !isset($arguments['enforceTimeLimit'])) {
761                 $arguments['enforceTimeLimit'] = $phpunitConfiguration['enforceTimeLimit'];
762             }
763
764             if (isset($phpunitConfiguration['disallowTodoAnnotatedTests']) &&
765                 !isset($arguments['disallowTodoAnnotatedTests'])) {
766                 $arguments['disallowTodoAnnotatedTests'] = $phpunitConfiguration['disallowTodoAnnotatedTests'];
767             }
768
769             if (isset($phpunitConfiguration['verbose']) &&
770                 !isset($arguments['verbose'])) {
771                 $arguments['verbose'] = $phpunitConfiguration['verbose'];
772             }
773
774             if (isset($phpunitConfiguration['forceCoversAnnotation']) &&
775                 !isset($arguments['forceCoversAnnotation'])) {
776                 $arguments['forceCoversAnnotation'] = $phpunitConfiguration['forceCoversAnnotation'];
777             }
778
779             if (isset($phpunitConfiguration['mapTestClassNameToCoveredClassName']) &&
780                 !isset($arguments['mapTestClassNameToCoveredClassName'])) {
781                 $arguments['mapTestClassNameToCoveredClassName'] = $phpunitConfiguration['mapTestClassNameToCoveredClassName'];
782             }
783
784             $groupCliArgs = array();
785
786             if (!empty($arguments['groups'])) {
787                 $groupCliArgs = $arguments['groups'];
788             }
789
790             $groupConfiguration = $arguments['configuration']->getGroupConfiguration();
791
792             if (!empty($groupConfiguration['include']) &&
793                 !isset($arguments['groups'])) {
794                 $arguments['groups'] = $groupConfiguration['include'];
795             }
796
797             if (!empty($groupConfiguration['exclude']) &&
798                 !isset($arguments['excludeGroups'])) {
799                 $arguments['excludeGroups'] = array_diff($groupConfiguration['exclude'], $groupCliArgs);
800             }
801
802             foreach ($arguments['configuration']->getListenerConfiguration() as $listener) {
803                 if (!class_exists($listener['class'], false) &&
804                     $listener['file'] !== '') {
805                     require_once $listener['file'];
806                 }
807
808                 if (class_exists($listener['class'])) {
809                     if (count($listener['arguments']) == 0) {
810                         $listener = new $listener['class'];
811                     } else {
812                         $listenerClass = new ReflectionClass(
813                             $listener['class']
814                         );
815                         $listener      = $listenerClass->newInstanceArgs(
816                             $listener['arguments']
817                         );
818                     }
819
820                     if ($listener instanceof PHPUnit_Framework_TestListener) {
821                         $arguments['listeners'][] = $listener;
822                     }
823                 }
824             }
825
826             $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration();
827
828             if (isset($loggingConfiguration['coverage-clover']) &&
829                 !isset($arguments['coverageClover'])) {
830                 $arguments['coverageClover'] = $loggingConfiguration['coverage-clover'];
831             }
832
833             if (isset($loggingConfiguration['coverage-crap4j']) &&
834                 !isset($arguments['coverageCrap4J'])) {
835                 $arguments['coverageCrap4J'] = $loggingConfiguration['coverage-crap4j'];
836
837                 if (isset($loggingConfiguration['crap4jThreshold']) &&
838                     !isset($arguments['crap4jThreshold'])) {
839                     $arguments['crap4jThreshold'] = $loggingConfiguration['crap4jThreshold'];
840                 }
841             }
842
843             if (isset($loggingConfiguration['coverage-html']) &&
844                 !isset($arguments['coverageHtml'])) {
845                 if (isset($loggingConfiguration['lowUpperBound']) &&
846                     !isset($arguments['reportLowUpperBound'])) {
847                     $arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound'];
848                 }
849
850                 if (isset($loggingConfiguration['highLowerBound']) &&
851                     !isset($arguments['reportHighLowerBound'])) {
852                     $arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound'];
853                 }
854
855                 $arguments['coverageHtml'] = $loggingConfiguration['coverage-html'];
856             }
857
858             if (isset($loggingConfiguration['coverage-php']) &&
859                 !isset($arguments['coveragePHP'])) {
860                 $arguments['coveragePHP'] = $loggingConfiguration['coverage-php'];
861             }
862
863             if (isset($loggingConfiguration['coverage-text']) &&
864                 !isset($arguments['coverageText'])) {
865                 $arguments['coverageText'] = $loggingConfiguration['coverage-text'];
866                 if (isset($loggingConfiguration['coverageTextShowUncoveredFiles'])) {
867                     $arguments['coverageTextShowUncoveredFiles'] = $loggingConfiguration['coverageTextShowUncoveredFiles'];
868                 } else {
869                     $arguments['coverageTextShowUncoveredFiles'] = false;
870                 }
871                 if (isset($loggingConfiguration['coverageTextShowOnlySummary'])) {
872                     $arguments['coverageTextShowOnlySummary'] = $loggingConfiguration['coverageTextShowOnlySummary'];
873                 } else {
874                     $arguments['coverageTextShowOnlySummary'] = false;
875                 }
876             }
877
878             if (isset($loggingConfiguration['coverage-xml']) &&
879                 !isset($arguments['coverageXml'])) {
880                 $arguments['coverageXml'] = $loggingConfiguration['coverage-xml'];
881             }
882
883             if (isset($loggingConfiguration['json']) &&
884                 !isset($arguments['jsonLogfile'])) {
885                 $arguments['jsonLogfile'] = $loggingConfiguration['json'];
886             }
887
888             if (isset($loggingConfiguration['plain'])) {
889                 $arguments['listeners'][] = new PHPUnit_TextUI_ResultPrinter(
890                     $loggingConfiguration['plain'],
891                     true
892                 );
893             }
894
895             if (isset($loggingConfiguration['tap']) &&
896                 !isset($arguments['tapLogfile'])) {
897                 $arguments['tapLogfile'] = $loggingConfiguration['tap'];
898             }
899
900             if (isset($loggingConfiguration['junit']) &&
901                 !isset($arguments['junitLogfile'])) {
902                 $arguments['junitLogfile'] = $loggingConfiguration['junit'];
903
904                 if (isset($loggingConfiguration['logIncompleteSkipped']) &&
905                     !isset($arguments['logIncompleteSkipped'])) {
906                     $arguments['logIncompleteSkipped'] = $loggingConfiguration['logIncompleteSkipped'];
907                 }
908             }
909
910             if (isset($loggingConfiguration['testdox-html']) &&
911                 !isset($arguments['testdoxHTMLFile'])) {
912                 $arguments['testdoxHTMLFile'] = $loggingConfiguration['testdox-html'];
913             }
914
915             if (isset($loggingConfiguration['testdox-text']) &&
916                 !isset($arguments['testdoxTextFile'])) {
917                 $arguments['testdoxTextFile'] = $loggingConfiguration['testdox-text'];
918             }
919
920             if ((isset($arguments['coverageClover']) ||
921                 isset($arguments['coverageCrap4J']) ||
922                 isset($arguments['coverageHtml']) ||
923                 isset($arguments['coveragePHP']) ||
924                 isset($arguments['coverageText']) ||
925                 isset($arguments['coverageXml'])) &&
926                 $this->runtime->canCollectCodeCoverage()) {
927                 $filterConfiguration                             = $arguments['configuration']->getFilterConfiguration();
928                 $arguments['addUncoveredFilesFromWhitelist']     = $filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist'];
929                 $arguments['processUncoveredFilesFromWhitelist'] = $filterConfiguration['whitelist']['processUncoveredFilesFromWhitelist'];
930
931                 if (empty($filterConfiguration['whitelist']['include']['directory']) &&
932                     empty($filterConfiguration['whitelist']['include']['file'])) {
933                     foreach ($filterConfiguration['blacklist']['include']['directory'] as $dir) {
934                         $this->codeCoverageFilter->addDirectoryToBlacklist(
935                             $dir['path'],
936                             $dir['suffix'],
937                             $dir['prefix'],
938                             $dir['group']
939                         );
940                     }
941
942                     foreach ($filterConfiguration['blacklist']['include']['file'] as $file) {
943                         $this->codeCoverageFilter->addFileToBlacklist($file);
944                     }
945
946                     foreach ($filterConfiguration['blacklist']['exclude']['directory'] as $dir) {
947                         $this->codeCoverageFilter->removeDirectoryFromBlacklist(
948                             $dir['path'],
949                             $dir['suffix'],
950                             $dir['prefix'],
951                             $dir['group']
952                         );
953                     }
954
955                     foreach ($filterConfiguration['blacklist']['exclude']['file'] as $file) {
956                         $this->codeCoverageFilter->removeFileFromBlacklist($file);
957                     }
958                 }
959
960                 foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) {
961                     $this->codeCoverageFilter->addDirectoryToWhitelist(
962                         $dir['path'],
963                         $dir['suffix'],
964                         $dir['prefix']
965                     );
966                 }
967
968                 foreach ($filterConfiguration['whitelist']['include']['file'] as $file) {
969                     $this->codeCoverageFilter->addFileToWhitelist($file);
970                 }
971
972                 foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) {
973                     $this->codeCoverageFilter->removeDirectoryFromWhitelist(
974                         $dir['path'],
975                         $dir['suffix'],
976                         $dir['prefix']
977                     );
978                 }
979
980                 foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) {
981                     $this->codeCoverageFilter->removeFileFromWhitelist($file);
982                 }
983             }
984         }
985
986         $arguments['addUncoveredFilesFromWhitelist']     = isset($arguments['addUncoveredFilesFromWhitelist'])     ? $arguments['addUncoveredFilesFromWhitelist']     : true;
987         $arguments['processUncoveredFilesFromWhitelist'] = isset($arguments['processUncoveredFilesFromWhitelist']) ? $arguments['processUncoveredFilesFromWhitelist'] : false;
988         $arguments['backupGlobals']                      = isset($arguments['backupGlobals'])                      ? $arguments['backupGlobals']                      : null;
989         $arguments['backupStaticAttributes']             = isset($arguments['backupStaticAttributes'])             ? $arguments['backupStaticAttributes']             : null;
990         $arguments['disallowChangesToGlobalState']       = isset($arguments['disallowChangesToGlobalState'])       ? $arguments['disallowChangesToGlobalState']       : null;
991         $arguments['cacheTokens']                        = isset($arguments['cacheTokens'])                        ? $arguments['cacheTokens']                        : false;
992         $arguments['columns']                            = isset($arguments['columns'])                            ? $arguments['columns']                            : 80;
993         $arguments['colors']                             = isset($arguments['colors'])                             ? $arguments['colors']                             : PHPUnit_TextUI_ResultPrinter::COLOR_DEFAULT;
994         $arguments['convertErrorsToExceptions']          = isset($arguments['convertErrorsToExceptions'])          ? $arguments['convertErrorsToExceptions']          : true;
995         $arguments['convertNoticesToExceptions']         = isset($arguments['convertNoticesToExceptions'])         ? $arguments['convertNoticesToExceptions']         : true;
996         $arguments['convertWarningsToExceptions']        = isset($arguments['convertWarningsToExceptions'])        ? $arguments['convertWarningsToExceptions']        : true;
997         $arguments['excludeGroups']                      = isset($arguments['excludeGroups'])                      ? $arguments['excludeGroups']                      : array();
998         $arguments['groups']                             = isset($arguments['groups'])                             ? $arguments['groups']                             : array();
999         $arguments['logIncompleteSkipped']               = isset($arguments['logIncompleteSkipped'])               ? $arguments['logIncompleteSkipped']               : false;
1000         $arguments['processIsolation']                   = isset($arguments['processIsolation'])                   ? $arguments['processIsolation']                   : false;
1001         $arguments['repeat']                             = isset($arguments['repeat'])                             ? $arguments['repeat']                             : false;
1002         $arguments['reportHighLowerBound']               = isset($arguments['reportHighLowerBound'])               ? $arguments['reportHighLowerBound']               : 90;
1003         $arguments['reportLowUpperBound']                = isset($arguments['reportLowUpperBound'])                ? $arguments['reportLowUpperBound']                : 50;
1004         $arguments['crap4jThreshold']                    = isset($arguments['crap4jThreshold'])                    ? $arguments['crap4jThreshold']                    : 30;
1005         $arguments['stopOnError']                        = isset($arguments['stopOnError'])                        ? $arguments['stopOnError']                        : false;
1006         $arguments['stopOnFailure']                      = isset($arguments['stopOnFailure'])                      ? $arguments['stopOnFailure']                      : false;
1007         $arguments['stopOnIncomplete']                   = isset($arguments['stopOnIncomplete'])                   ? $arguments['stopOnIncomplete']                   : false;
1008         $arguments['stopOnRisky']                        = isset($arguments['stopOnRisky'])                        ? $arguments['stopOnRisky']                        : false;
1009         $arguments['stopOnSkipped']                      = isset($arguments['stopOnSkipped'])                      ? $arguments['stopOnSkipped']                      : false;
1010         $arguments['timeoutForSmallTests']               = isset($arguments['timeoutForSmallTests'])               ? $arguments['timeoutForSmallTests']               : 1;
1011         $arguments['timeoutForMediumTests']              = isset($arguments['timeoutForMediumTests'])              ? $arguments['timeoutForMediumTests']              : 10;
1012         $arguments['timeoutForLargeTests']               = isset($arguments['timeoutForLargeTests'])               ? $arguments['timeoutForLargeTests']               : 60;
1013         $arguments['reportUselessTests']                 = isset($arguments['reportUselessTests'])                 ? $arguments['reportUselessTests']                 : false;
1014         $arguments['strictCoverage']                     = isset($arguments['strictCoverage'])                     ? $arguments['strictCoverage']                     : false;
1015         $arguments['disallowTestOutput']                 = isset($arguments['disallowTestOutput'])                 ? $arguments['disallowTestOutput']                 : false;
1016         $arguments['enforceTimeLimit']                   = isset($arguments['enforceTimeLimit'])                   ? $arguments['enforceTimeLimit']                   : false;
1017         $arguments['disallowTodoAnnotatedTests']         = isset($arguments['disallowTodoAnnotatedTests'])         ? $arguments['disallowTodoAnnotatedTests']         : false;
1018         $arguments['verbose']                            = isset($arguments['verbose'])                            ? $arguments['verbose']                            : false;
1019     }
1020
1021     /**
1022      * @param $extension
1023      * @param string $message
1024      *
1025      * @since Method available since Release 4.7.3
1026      */
1027     private function showExtensionNotLoadedWarning($extension, $message = '')
1028     {
1029         if (isset($this->missingExtensions[$extension])) {
1030             return;
1031         }
1032
1033         $this->write("Warning:\t" . 'The ' . $extension . ' extension is not loaded' . "\n");
1034
1035         if (!empty($message)) {
1036             $this->write("\t\t" . $message . "\n");
1037         }
1038
1039         $this->missingExtensions[$extension] = true;
1040     }
1041
1042     /**
1043      * @return PHP_CodeCoverage_Filter
1044      */
1045     private function getCodeCoverageFilter()
1046     {
1047         $filter = new PHP_CodeCoverage_Filter;
1048
1049         if (defined('__PHPUNIT_PHAR__')) {
1050             $filter->addFileToBlacklist(__PHPUNIT_PHAR__);
1051         }
1052
1053         $blacklist = new PHPUnit_Util_Blacklist;
1054
1055         foreach ($blacklist->getBlacklistedDirectories() as $directory) {
1056             $filter->addDirectoryToBlacklist($directory);
1057         }
1058
1059         return $filter;
1060     }
1061 }