3 * This file is part of PHPUnit.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 use SebastianBergmann\Environment\Runtime;
14 * A TestRunner for the Command Line Interface (CLI)
17 * @since Class available since Release 2.0.0
19 class PHPUnit_TextUI_TestRunner extends PHPUnit_Runner_BaseTestRunner
21 const SUCCESS_EXIT = 0;
22 const FAILURE_EXIT = 1;
23 const EXCEPTION_EXIT = 2;
26 * @var PHP_CodeCoverage_Filter
28 protected $codeCoverageFilter;
31 * @var PHPUnit_Runner_TestSuiteLoader
33 protected $loader = null;
36 * @var PHPUnit_TextUI_ResultPrinter
38 protected $printer = null;
43 protected static $versionStringPrinted = false;
48 private $missingExtensions = array();
56 * @param PHPUnit_Runner_TestSuiteLoader $loader
57 * @param PHP_CodeCoverage_Filter $filter
59 * @since Method available since Release 3.4.0
61 public function __construct(PHPUnit_Runner_TestSuiteLoader $loader = null, PHP_CodeCoverage_Filter $filter = null)
63 if ($filter === null) {
64 $filter = $this->getCodeCoverageFilter();
67 $this->codeCoverageFilter = $filter;
68 $this->loader = $loader;
69 $this->runtime = new Runtime;
73 * @param PHPUnit_Framework_Test|ReflectionClass $test
74 * @param array $arguments
76 * @return PHPUnit_Framework_TestResult
78 * @throws PHPUnit_Framework_Exception
80 public static function run($test, array $arguments = array())
82 if ($test instanceof ReflectionClass) {
83 $test = new PHPUnit_Framework_TestSuite($test);
86 if ($test instanceof PHPUnit_Framework_Test) {
87 $aTestRunner = new self;
89 return $aTestRunner->doRun(
94 throw new PHPUnit_Framework_Exception(
95 'No test case or test suite found.'
101 * @return PHPUnit_Framework_TestResult
103 protected function createTestResult()
105 return new PHPUnit_Framework_TestResult;
108 private function processSuiteFilters(PHPUnit_Framework_TestSuite $suite, array $arguments)
110 if (!$arguments['filter'] &&
111 empty($arguments['groups']) &&
112 empty($arguments['excludeGroups'])) {
116 $filterFactory = new PHPUnit_Runner_Filter_Factory();
118 if (!empty($arguments['excludeGroups'])) {
119 $filterFactory->addFilter(
120 new ReflectionClass('PHPUnit_Runner_Filter_Group_Exclude'),
121 $arguments['excludeGroups']
125 if (!empty($arguments['groups'])) {
126 $filterFactory->addFilter(
127 new ReflectionClass('PHPUnit_Runner_Filter_Group_Include'),
132 if ($arguments['filter']) {
133 $filterFactory->addFilter(
134 new ReflectionClass('PHPUnit_Runner_Filter_Test'),
138 $suite->injectFilter($filterFactory);
142 * @param PHPUnit_Framework_Test $suite
143 * @param array $arguments
145 * @return PHPUnit_Framework_TestResult
147 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
149 if (isset($arguments['configuration'])) {
150 $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] = $arguments['configuration'];
153 $this->handleConfiguration($arguments);
155 $this->processSuiteFilters($suite, $arguments);
157 if (isset($arguments['bootstrap'])) {
158 $GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap'];
161 if ($arguments['backupGlobals'] === false) {
162 $suite->setBackupGlobals(false);
165 if ($arguments['backupStaticAttributes'] === true) {
166 $suite->setBackupStaticAttributes(true);
169 if ($arguments['disallowChangesToGlobalState'] === true) {
170 $suite->setDisallowChangesToGlobalState(true);
173 if (is_integer($arguments['repeat'])) {
174 $test = new PHPUnit_Extensions_RepeatedTest(
176 $arguments['repeat'],
177 $arguments['processIsolation']
180 $suite = new PHPUnit_Framework_TestSuite();
181 $suite->addTest($test);
184 $result = $this->createTestResult();
186 if (!$arguments['convertErrorsToExceptions']) {
187 $result->convertErrorsToExceptions(false);
190 if (!$arguments['convertNoticesToExceptions']) {
191 PHPUnit_Framework_Error_Notice::$enabled = false;
194 if (!$arguments['convertWarningsToExceptions']) {
195 PHPUnit_Framework_Error_Warning::$enabled = false;
198 if ($arguments['stopOnError']) {
199 $result->stopOnError(true);
202 if ($arguments['stopOnFailure']) {
203 $result->stopOnFailure(true);
206 if ($arguments['stopOnIncomplete']) {
207 $result->stopOnIncomplete(true);
210 if ($arguments['stopOnRisky']) {
211 $result->stopOnRisky(true);
214 if ($arguments['stopOnSkipped']) {
215 $result->stopOnSkipped(true);
218 if ($this->printer === null) {
219 if (isset($arguments['printer']) &&
220 $arguments['printer'] instanceof PHPUnit_Util_Printer) {
221 $this->printer = $arguments['printer'];
223 $printerClass = 'PHPUnit_TextUI_ResultPrinter';
225 if (isset($arguments['printer']) &&
226 is_string($arguments['printer']) &&
227 class_exists($arguments['printer'], false)) {
228 $class = new ReflectionClass($arguments['printer']);
230 if ($class->isSubclassOf('PHPUnit_TextUI_ResultPrinter')) {
231 $printerClass = $arguments['printer'];
235 $this->printer = new $printerClass(
236 isset($arguments['stderr']) ? 'php://stderr' : null,
237 $arguments['verbose'],
238 $arguments['colors'],
240 $arguments['columns']
245 if (!$this->printer instanceof PHPUnit_Util_Log_TAP) {
246 $this->printer->write(
247 PHPUnit_Runner_Version::getVersionString() . "\n"
250 self::$versionStringPrinted = true;
252 if ($arguments['verbose']) {
253 $this->printer->write(
256 $this->runtime->getNameWithVersion()
260 if ($this->runtime->hasXdebug()) {
261 $this->printer->write(
269 if (isset($arguments['configuration'])) {
270 $this->printer->write(
272 "\nConfiguration:\t%s",
273 $arguments['configuration']->getFilename()
278 $this->printer->write("\n");
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";
287 if (isset($arguments['deprecatedSeleniumConfiguration'])) {
288 print "Warning:\tDeprecated configuration setting \"selenium\" used\n";
292 foreach ($arguments['listeners'] as $listener) {
293 $result->addListener($listener);
296 $result->addListener($this->printer);
298 if (isset($arguments['testdoxHTMLFile'])) {
299 $result->addListener(
300 new PHPUnit_Util_TestDox_ResultPrinter_HTML(
301 $arguments['testdoxHTMLFile']
306 if (isset($arguments['testdoxTextFile'])) {
307 $result->addListener(
308 new PHPUnit_Util_TestDox_ResultPrinter_Text(
309 $arguments['testdoxTextFile']
314 $codeCoverageReports = 0;
316 if (isset($arguments['coverageClover'])) {
317 $codeCoverageReports++;
320 if (isset($arguments['coverageCrap4J'])) {
321 $codeCoverageReports++;
324 if (isset($arguments['coverageHtml'])) {
325 $codeCoverageReports++;
328 if (isset($arguments['coveragePHP'])) {
329 $codeCoverageReports++;
332 if (isset($arguments['coverageText'])) {
333 $codeCoverageReports++;
336 if (isset($arguments['coverageXml'])) {
337 $codeCoverageReports++;
340 if (isset($arguments['noCoverage'])) {
341 $codeCoverageReports = 0;
344 if ($codeCoverageReports > 0 && (!extension_loaded('tokenizer') || !$this->runtime->canCollectCodeCoverage())) {
345 if (!extension_loaded('tokenizer')) {
346 $this->showExtensionNotLoadedWarning(
348 'No code coverage will be generated.'
350 } elseif (!extension_loaded('Xdebug')) {
351 $this->showExtensionNotLoadedWarning(
353 'No code coverage will be generated.'
357 $codeCoverageReports = 0;
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");
365 $this->printer->write("\n");
368 if ($codeCoverageReports > 0) {
369 $codeCoverage = new PHP_CodeCoverage(
371 $this->codeCoverageFilter
374 $codeCoverage->setAddUncoveredFilesFromWhitelist(
375 $arguments['addUncoveredFilesFromWhitelist']
378 $codeCoverage->setCheckForUnintentionallyCoveredCode(
379 $arguments['strictCoverage']
382 $codeCoverage->setProcessUncoveredFilesFromWhitelist(
383 $arguments['processUncoveredFilesFromWhitelist']
386 if (isset($arguments['forceCoversAnnotation'])) {
387 $codeCoverage->setForceCoversAnnotation(
388 $arguments['forceCoversAnnotation']
392 if (isset($arguments['mapTestClassNameToCoveredClassName'])) {
393 $codeCoverage->setMapTestClassNameToCoveredClassName(
394 $arguments['mapTestClassNameToCoveredClassName']
398 $result->setCodeCoverage($codeCoverage);
401 if ($codeCoverageReports > 1) {
402 if (isset($arguments['cacheTokens'])) {
403 $codeCoverage->setCacheTokens($arguments['cacheTokens']);
407 if (isset($arguments['jsonLogfile'])) {
408 $result->addListener(
409 new PHPUnit_Util_Log_JSON($arguments['jsonLogfile'])
413 if (isset($arguments['tapLogfile'])) {
414 $result->addListener(
415 new PHPUnit_Util_Log_TAP($arguments['tapLogfile'])
419 if (isset($arguments['junitLogfile'])) {
420 $result->addListener(
421 new PHPUnit_Util_Log_JUnit(
422 $arguments['junitLogfile'],
423 $arguments['logIncompleteSkipped']
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']);
436 if ($suite instanceof PHPUnit_Framework_TestSuite) {
437 $suite->setRunTestInSeparateProcess($arguments['processIsolation']);
440 $suite->run($result);
443 $result->flushListeners();
445 if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
446 $this->printer->printResult($result);
449 if (isset($codeCoverage)) {
450 if (isset($arguments['coverageClover'])) {
451 $this->printer->write(
452 "\nGenerating code coverage report in Clover XML format ..."
456 $writer = new PHP_CodeCoverage_Report_Clover;
457 $writer->process($codeCoverage, $arguments['coverageClover']);
459 $this->printer->write(" done\n");
461 } catch (PHP_CodeCoverage_Exception $e) {
462 $this->printer->write(
463 " failed\n" . $e->getMessage() . "\n"
468 if (isset($arguments['coverageCrap4J'])) {
469 $this->printer->write(
470 "\nGenerating Crap4J report XML file ..."
474 $writer = new PHP_CodeCoverage_Report_Crap4j($arguments['crap4jThreshold']);
475 $writer->process($codeCoverage, $arguments['coverageCrap4J']);
477 $this->printer->write(" done\n");
479 } catch (PHP_CodeCoverage_Exception $e) {
480 $this->printer->write(
481 " failed\n" . $e->getMessage() . "\n"
486 if (isset($arguments['coverageHtml'])) {
487 $this->printer->write(
488 "\nGenerating code coverage report in HTML format ..."
492 $writer = new PHP_CodeCoverage_Report_HTML(
493 $arguments['reportLowUpperBound'],
494 $arguments['reportHighLowerBound'],
496 ' and <a href="https://phpunit.de/">PHPUnit %s</a>',
497 PHPUnit_Runner_Version::id()
501 $writer->process($codeCoverage, $arguments['coverageHtml']);
503 $this->printer->write(" done\n");
505 } catch (PHP_CodeCoverage_Exception $e) {
506 $this->printer->write(
507 " failed\n" . $e->getMessage() . "\n"
512 if (isset($arguments['coveragePHP'])) {
513 $this->printer->write(
514 "\nGenerating code coverage report in PHP format ..."
518 $writer = new PHP_CodeCoverage_Report_PHP;
519 $writer->process($codeCoverage, $arguments['coveragePHP']);
521 $this->printer->write(" done\n");
523 } catch (PHP_CodeCoverage_Exception $e) {
524 $this->printer->write(
525 " failed\n" . $e->getMessage() . "\n"
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;
535 $outputStream = new PHPUnit_Util_Printer($arguments['coverageText']);
539 $processor = new PHP_CodeCoverage_Report_Text(
540 $arguments['reportLowUpperBound'],
541 $arguments['reportHighLowerBound'],
542 $arguments['coverageTextShowUncoveredFiles'],
543 $arguments['coverageTextShowOnlySummary']
546 $outputStream->write(
547 $processor->process($codeCoverage, $colors)
551 if (isset($arguments['coverageXml'])) {
552 $this->printer->write(
553 "\nGenerating code coverage report in PHPUnit XML format ..."
557 $writer = new PHP_CodeCoverage_Report_XML;
558 $writer->process($codeCoverage, $arguments['coverageXml']);
560 $this->printer->write(" done\n");
562 } catch (PHP_CodeCoverage_Exception $e) {
563 $this->printer->write(
564 " failed\n" . $e->getMessage() . "\n"
574 * @param PHPUnit_TextUI_ResultPrinter $resultPrinter
576 public function setPrinter(PHPUnit_TextUI_ResultPrinter $resultPrinter)
578 $this->printer = $resultPrinter;
582 * Override to define how to handle a failed loading of
585 * @param string $message
587 protected function runFailed($message)
589 $this->write($message . PHP_EOL);
590 exit(self::FAILURE_EXIT);
594 * @param string $buffer
596 * @since Method available since Release 3.1.0
598 protected function write($buffer)
600 if (PHP_SAPI != 'cli' && PHP_SAPI != 'phpdbg') {
601 $buffer = htmlspecialchars($buffer);
604 if ($this->printer !== null) {
605 $this->printer->write($buffer);
612 * Returns the loader to be used.
614 * @return PHPUnit_Runner_TestSuiteLoader
616 * @since Method available since Release 2.2.0
618 public function getLoader()
620 if ($this->loader === null) {
621 $this->loader = new PHPUnit_Runner_StandardTestSuiteLoader;
624 return $this->loader;
628 * @param array $arguments
630 * @since Method available since Release 3.2.1
632 protected function handleConfiguration(array &$arguments)
634 if (isset($arguments['configuration']) &&
635 !$arguments['configuration'] instanceof PHPUnit_Util_Configuration) {
636 $arguments['configuration'] = PHPUnit_Util_Configuration::getInstance(
637 $arguments['configuration']
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();
645 if (isset($arguments['configuration'])) {
646 $arguments['configuration']->handlePHPConfiguration();
648 $phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration();
650 if (isset($phpunitConfiguration['deprecatedStrictModeSetting'])) {
651 $arguments['deprecatedStrictModeSetting'] = true;
654 if (isset($phpunitConfiguration['backupGlobals']) &&
655 !isset($arguments['backupGlobals'])) {
656 $arguments['backupGlobals'] = $phpunitConfiguration['backupGlobals'];
659 if (isset($phpunitConfiguration['backupStaticAttributes']) &&
660 !isset($arguments['backupStaticAttributes'])) {
661 $arguments['backupStaticAttributes'] = $phpunitConfiguration['backupStaticAttributes'];
664 if (isset($phpunitConfiguration['disallowChangesToGlobalState']) &&
665 !isset($arguments['disallowChangesToGlobalState'])) {
666 $arguments['disallowChangesToGlobalState'] = $phpunitConfiguration['disallowChangesToGlobalState'];
669 if (isset($phpunitConfiguration['bootstrap']) &&
670 !isset($arguments['bootstrap'])) {
671 $arguments['bootstrap'] = $phpunitConfiguration['bootstrap'];
674 if (isset($phpunitConfiguration['cacheTokens']) &&
675 !isset($arguments['cacheTokens'])) {
676 $arguments['cacheTokens'] = $phpunitConfiguration['cacheTokens'];
679 if (isset($phpunitConfiguration['colors']) &&
680 !isset($arguments['colors'])) {
681 $arguments['colors'] = $phpunitConfiguration['colors'];
684 if (isset($phpunitConfiguration['convertErrorsToExceptions']) &&
685 !isset($arguments['convertErrorsToExceptions'])) {
686 $arguments['convertErrorsToExceptions'] = $phpunitConfiguration['convertErrorsToExceptions'];
689 if (isset($phpunitConfiguration['convertNoticesToExceptions']) &&
690 !isset($arguments['convertNoticesToExceptions'])) {
691 $arguments['convertNoticesToExceptions'] = $phpunitConfiguration['convertNoticesToExceptions'];
694 if (isset($phpunitConfiguration['convertWarningsToExceptions']) &&
695 !isset($arguments['convertWarningsToExceptions'])) {
696 $arguments['convertWarningsToExceptions'] = $phpunitConfiguration['convertWarningsToExceptions'];
699 if (isset($phpunitConfiguration['processIsolation']) &&
700 !isset($arguments['processIsolation'])) {
701 $arguments['processIsolation'] = $phpunitConfiguration['processIsolation'];
704 if (isset($phpunitConfiguration['stopOnError']) &&
705 !isset($arguments['stopOnError'])) {
706 $arguments['stopOnError'] = $phpunitConfiguration['stopOnError'];
709 if (isset($phpunitConfiguration['stopOnFailure']) &&
710 !isset($arguments['stopOnFailure'])) {
711 $arguments['stopOnFailure'] = $phpunitConfiguration['stopOnFailure'];
714 if (isset($phpunitConfiguration['stopOnIncomplete']) &&
715 !isset($arguments['stopOnIncomplete'])) {
716 $arguments['stopOnIncomplete'] = $phpunitConfiguration['stopOnIncomplete'];
719 if (isset($phpunitConfiguration['stopOnRisky']) &&
720 !isset($arguments['stopOnRisky'])) {
721 $arguments['stopOnRisky'] = $phpunitConfiguration['stopOnRisky'];
724 if (isset($phpunitConfiguration['stopOnSkipped']) &&
725 !isset($arguments['stopOnSkipped'])) {
726 $arguments['stopOnSkipped'] = $phpunitConfiguration['stopOnSkipped'];
729 if (isset($phpunitConfiguration['timeoutForSmallTests']) &&
730 !isset($arguments['timeoutForSmallTests'])) {
731 $arguments['timeoutForSmallTests'] = $phpunitConfiguration['timeoutForSmallTests'];
734 if (isset($phpunitConfiguration['timeoutForMediumTests']) &&
735 !isset($arguments['timeoutForMediumTests'])) {
736 $arguments['timeoutForMediumTests'] = $phpunitConfiguration['timeoutForMediumTests'];
739 if (isset($phpunitConfiguration['timeoutForLargeTests']) &&
740 !isset($arguments['timeoutForLargeTests'])) {
741 $arguments['timeoutForLargeTests'] = $phpunitConfiguration['timeoutForLargeTests'];
744 if (isset($phpunitConfiguration['reportUselessTests']) &&
745 !isset($arguments['reportUselessTests'])) {
746 $arguments['reportUselessTests'] = $phpunitConfiguration['reportUselessTests'];
749 if (isset($phpunitConfiguration['strictCoverage']) &&
750 !isset($arguments['strictCoverage'])) {
751 $arguments['strictCoverage'] = $phpunitConfiguration['strictCoverage'];
754 if (isset($phpunitConfiguration['disallowTestOutput']) &&
755 !isset($arguments['disallowTestOutput'])) {
756 $arguments['disallowTestOutput'] = $phpunitConfiguration['disallowTestOutput'];
759 if (isset($phpunitConfiguration['enforceTimeLimit']) &&
760 !isset($arguments['enforceTimeLimit'])) {
761 $arguments['enforceTimeLimit'] = $phpunitConfiguration['enforceTimeLimit'];
764 if (isset($phpunitConfiguration['disallowTodoAnnotatedTests']) &&
765 !isset($arguments['disallowTodoAnnotatedTests'])) {
766 $arguments['disallowTodoAnnotatedTests'] = $phpunitConfiguration['disallowTodoAnnotatedTests'];
769 if (isset($phpunitConfiguration['verbose']) &&
770 !isset($arguments['verbose'])) {
771 $arguments['verbose'] = $phpunitConfiguration['verbose'];
774 if (isset($phpunitConfiguration['forceCoversAnnotation']) &&
775 !isset($arguments['forceCoversAnnotation'])) {
776 $arguments['forceCoversAnnotation'] = $phpunitConfiguration['forceCoversAnnotation'];
779 if (isset($phpunitConfiguration['mapTestClassNameToCoveredClassName']) &&
780 !isset($arguments['mapTestClassNameToCoveredClassName'])) {
781 $arguments['mapTestClassNameToCoveredClassName'] = $phpunitConfiguration['mapTestClassNameToCoveredClassName'];
784 $groupCliArgs = array();
786 if (!empty($arguments['groups'])) {
787 $groupCliArgs = $arguments['groups'];
790 $groupConfiguration = $arguments['configuration']->getGroupConfiguration();
792 if (!empty($groupConfiguration['include']) &&
793 !isset($arguments['groups'])) {
794 $arguments['groups'] = $groupConfiguration['include'];
797 if (!empty($groupConfiguration['exclude']) &&
798 !isset($arguments['excludeGroups'])) {
799 $arguments['excludeGroups'] = array_diff($groupConfiguration['exclude'], $groupCliArgs);
802 foreach ($arguments['configuration']->getListenerConfiguration() as $listener) {
803 if (!class_exists($listener['class'], false) &&
804 $listener['file'] !== '') {
805 require_once $listener['file'];
808 if (class_exists($listener['class'])) {
809 if (count($listener['arguments']) == 0) {
810 $listener = new $listener['class'];
812 $listenerClass = new ReflectionClass(
815 $listener = $listenerClass->newInstanceArgs(
816 $listener['arguments']
820 if ($listener instanceof PHPUnit_Framework_TestListener) {
821 $arguments['listeners'][] = $listener;
826 $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration();
828 if (isset($loggingConfiguration['coverage-clover']) &&
829 !isset($arguments['coverageClover'])) {
830 $arguments['coverageClover'] = $loggingConfiguration['coverage-clover'];
833 if (isset($loggingConfiguration['coverage-crap4j']) &&
834 !isset($arguments['coverageCrap4J'])) {
835 $arguments['coverageCrap4J'] = $loggingConfiguration['coverage-crap4j'];
837 if (isset($loggingConfiguration['crap4jThreshold']) &&
838 !isset($arguments['crap4jThreshold'])) {
839 $arguments['crap4jThreshold'] = $loggingConfiguration['crap4jThreshold'];
843 if (isset($loggingConfiguration['coverage-html']) &&
844 !isset($arguments['coverageHtml'])) {
845 if (isset($loggingConfiguration['lowUpperBound']) &&
846 !isset($arguments['reportLowUpperBound'])) {
847 $arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound'];
850 if (isset($loggingConfiguration['highLowerBound']) &&
851 !isset($arguments['reportHighLowerBound'])) {
852 $arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound'];
855 $arguments['coverageHtml'] = $loggingConfiguration['coverage-html'];
858 if (isset($loggingConfiguration['coverage-php']) &&
859 !isset($arguments['coveragePHP'])) {
860 $arguments['coveragePHP'] = $loggingConfiguration['coverage-php'];
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'];
869 $arguments['coverageTextShowUncoveredFiles'] = false;
871 if (isset($loggingConfiguration['coverageTextShowOnlySummary'])) {
872 $arguments['coverageTextShowOnlySummary'] = $loggingConfiguration['coverageTextShowOnlySummary'];
874 $arguments['coverageTextShowOnlySummary'] = false;
878 if (isset($loggingConfiguration['coverage-xml']) &&
879 !isset($arguments['coverageXml'])) {
880 $arguments['coverageXml'] = $loggingConfiguration['coverage-xml'];
883 if (isset($loggingConfiguration['json']) &&
884 !isset($arguments['jsonLogfile'])) {
885 $arguments['jsonLogfile'] = $loggingConfiguration['json'];
888 if (isset($loggingConfiguration['plain'])) {
889 $arguments['listeners'][] = new PHPUnit_TextUI_ResultPrinter(
890 $loggingConfiguration['plain'],
895 if (isset($loggingConfiguration['tap']) &&
896 !isset($arguments['tapLogfile'])) {
897 $arguments['tapLogfile'] = $loggingConfiguration['tap'];
900 if (isset($loggingConfiguration['junit']) &&
901 !isset($arguments['junitLogfile'])) {
902 $arguments['junitLogfile'] = $loggingConfiguration['junit'];
904 if (isset($loggingConfiguration['logIncompleteSkipped']) &&
905 !isset($arguments['logIncompleteSkipped'])) {
906 $arguments['logIncompleteSkipped'] = $loggingConfiguration['logIncompleteSkipped'];
910 if (isset($loggingConfiguration['testdox-html']) &&
911 !isset($arguments['testdoxHTMLFile'])) {
912 $arguments['testdoxHTMLFile'] = $loggingConfiguration['testdox-html'];
915 if (isset($loggingConfiguration['testdox-text']) &&
916 !isset($arguments['testdoxTextFile'])) {
917 $arguments['testdoxTextFile'] = $loggingConfiguration['testdox-text'];
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'];
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(
942 foreach ($filterConfiguration['blacklist']['include']['file'] as $file) {
943 $this->codeCoverageFilter->addFileToBlacklist($file);
946 foreach ($filterConfiguration['blacklist']['exclude']['directory'] as $dir) {
947 $this->codeCoverageFilter->removeDirectoryFromBlacklist(
955 foreach ($filterConfiguration['blacklist']['exclude']['file'] as $file) {
956 $this->codeCoverageFilter->removeFileFromBlacklist($file);
960 foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) {
961 $this->codeCoverageFilter->addDirectoryToWhitelist(
968 foreach ($filterConfiguration['whitelist']['include']['file'] as $file) {
969 $this->codeCoverageFilter->addFileToWhitelist($file);
972 foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) {
973 $this->codeCoverageFilter->removeDirectoryFromWhitelist(
980 foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) {
981 $this->codeCoverageFilter->removeFileFromWhitelist($file);
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;
1023 * @param string $message
1025 * @since Method available since Release 4.7.3
1027 private function showExtensionNotLoadedWarning($extension, $message = '')
1029 if (isset($this->missingExtensions[$extension])) {
1033 $this->write("Warning:\t" . 'The ' . $extension . ' extension is not loaded' . "\n");
1035 if (!empty($message)) {
1036 $this->write("\t\t" . $message . "\n");
1039 $this->missingExtensions[$extension] = true;
1043 * @return PHP_CodeCoverage_Filter
1045 private function getCodeCoverageFilter()
1047 $filter = new PHP_CodeCoverage_Filter;
1049 if (defined('__PHPUNIT_PHAR__')) {
1050 $filter->addFileToBlacklist(__PHPUNIT_PHAR__);
1053 $blacklist = new PHPUnit_Util_Blacklist;
1055 foreach ($blacklist->getBlacklistedDirectories() as $directory) {
1056 $filter->addDirectoryToBlacklist($directory);