/** * @return PHP_CodeCoverage_Filter */ private function getCodeCoverageFilter() { $filter = new PHP_CodeCoverage_Filter(); if (defined('__PHPUNIT_PHAR__')) { $filter->addFileToBlacklist(__PHPUNIT_PHAR__); } $blacklist = new PHPUnit_Util_Blacklist(); foreach ($blacklist->getBlacklistedDirectories() as $directory) { $filter->addDirectoryToBlacklist($directory); } return $filter; }
private function initialize() { if (self::$directories === null) { self::$directories = array(); foreach (self::$blacklistedClassNames as $className => $parent) { if (!class_exists($className)) { continue; } $reflector = new ReflectionClass($className); $directory = $reflector->getFileName(); for ($i = 0; $i < $parent; $i++) { $directory = dirname($directory); } self::$directories[] = $directory; } // Hide process isolation workaround on Windows. // @see PHPUnit_Util_PHP::factory() // @see PHPUnit_Util_PHP_Windows::process() if (DIRECTORY_SEPARATOR === '\\') { // tempnam() prefix is limited to first 3 chars. // @see http://php.net/manual/en/function.tempnam.php self::$directories[] = sys_get_temp_dir() . '\\PHP'; } } }
/** * Filters stack frames from PHPUnit classes. * * @param Exception $e * @param bool $asString * @return string */ public static function getFilteredStacktrace(Exception $e, $asString = true) { $prefix = false; $script = realpath($GLOBALS['_SERVER']['SCRIPT_NAME']); if (defined('__PHPUNIT_PHAR_ROOT__')) { $prefix = __PHPUNIT_PHAR_ROOT__; } if ($asString === true) { $filteredStacktrace = ''; } else { $filteredStacktrace = array(); } if ($e instanceof PHPUnit_Framework_SyntheticError) { $eTrace = $e->getSyntheticTrace(); $eFile = $e->getSyntheticFile(); $eLine = $e->getSyntheticLine(); } elseif ($e instanceof PHPUnit_Framework_Exception) { $eTrace = $e->getSerializableTrace(); $eFile = $e->getFile(); $eLine = $e->getLine(); } else { if ($e->getPrevious()) { $e = $e->getPrevious(); } $eTrace = $e->getTrace(); $eFile = $e->getFile(); $eLine = $e->getLine(); } if (!self::frameExists($eTrace, $eFile, $eLine)) { array_unshift($eTrace, array('file' => $eFile, 'line' => $eLine)); } $blacklist = new PHPUnit_Util_Blacklist(); foreach ($eTrace as $frame) { if (isset($frame['file']) && is_file($frame['file']) && !$blacklist->isBlacklisted($frame['file']) && ($prefix === false || strpos($frame['file'], $prefix) !== 0) && $frame['file'] !== $script) { if ($asString === true) { $filteredStacktrace .= sprintf("%s:%s\n", $frame['file'], isset($frame['line']) ? $frame['line'] : '?'); } else { $filteredStacktrace[] = $frame; } } } return $filteredStacktrace; }
public static function processIncludedFilesAsString(array $files) { $blacklist = new PHPUnit_Util_Blacklist(); $prefix = false; $result = ''; if (defined('__PHPUNIT_PHAR__')) { $prefix = 'phar://' . __PHPUNIT_PHAR__ . '/'; } for ($i = count($files) - 1; $i > 0; $i--) { $file = $files[$i]; if ($prefix !== false && strpos($file, $prefix) === 0) { continue; } // Skip virtual file system protocols if (preg_match('/^(vfs|phpvfs[a-z0-9]+):/', $file)) { continue; } if (!$blacklist->isBlacklisted($file) && is_file($file)) { $result = 'require_once \'' . $file . "';\n" . $result; } } return $result; }
private function initialize() { if (self::$directories === null) { self::$directories = array(); foreach (PHP_CodeCoverage_Filter::$blacklistClassNames as $className => $parent) { if (!class_exists($className)) { continue; } $reflector = new ReflectionClass($className); $directory = $reflector->getFileName(); for ($i = 0; $i < $parent; $i++) { $directory = dirname($directory); } self::$directories[] = $directory; } } }
/** * Runs a TestCase. * * @param PHPUnit_Framework_Test $test */ public function run(PHPUnit_Framework_Test $test) { PHPUnit_Framework_Assert::resetCount(); $error = false; $failure = false; $warning = false; $incomplete = false; $risky = false; $skipped = false; $this->startTest($test); $errorHandlerSet = false; if ($this->convertErrorsToExceptions) { $oldErrorHandler = set_error_handler(['PHPUnit_Util_ErrorHandler', 'handleError'], E_ALL | E_STRICT); if ($oldErrorHandler === null) { $errorHandlerSet = true; } else { restore_error_handler(); } } $collectCodeCoverage = $this->codeCoverage !== null && !$test instanceof PHPUnit_Framework_WarningTestCase; if ($collectCodeCoverage) { $this->codeCoverage->start($test); } $monitorFunctions = $this->beStrictAboutResourceUsageDuringSmallTests && !$test instanceof PHPUnit_Framework_WarningTestCase && $test->getSize() == PHPUnit_Util_Test::SMALL && function_exists('xdebug_start_function_monitor'); if ($monitorFunctions) { xdebug_start_function_monitor(ResourceOperations::getFunctions()); } PHP_Timer::start(); try { if (!$test instanceof PHPUnit_Framework_WarningTestCase && $test->getSize() != PHPUnit_Util_Test::UNKNOWN && $this->enforceTimeLimit && extension_loaded('pcntl') && class_exists('PHP_Invoker')) { switch ($test->getSize()) { case PHPUnit_Util_Test::SMALL: $_timeout = $this->timeoutForSmallTests; break; case PHPUnit_Util_Test::MEDIUM: $_timeout = $this->timeoutForMediumTests; break; case PHPUnit_Util_Test::LARGE: $_timeout = $this->timeoutForLargeTests; break; } $invoker = new PHP_Invoker(); $invoker->invoke([$test, 'runBare'], [], $_timeout); } else { $test->runBare(); } } catch (PHPUnit_Framework_AssertionFailedError $e) { $failure = true; if ($e instanceof PHPUnit_Framework_RiskyTestError) { $risky = true; } elseif ($e instanceof PHPUnit_Framework_IncompleteTestError) { $incomplete = true; } elseif ($e instanceof PHPUnit_Framework_SkippedTestError) { $skipped = true; } } catch (PHPUnit_Framework_Warning $e) { $warning = true; } catch (PHPUnit_Framework_Exception $e) { $error = true; } catch (Throwable $e) { $e = new PHPUnit_Framework_ExceptionWrapper($e); $error = true; } catch (Exception $e) { $e = new PHPUnit_Framework_ExceptionWrapper($e); $error = true; } $time = PHP_Timer::stop(); $test->addToAssertionCount(PHPUnit_Framework_Assert::getCount()); if ($monitorFunctions) { $blacklist = new PHPUnit_Util_Blacklist(); $functions = xdebug_get_monitored_functions(); xdebug_stop_function_monitor(); foreach ($functions as $function) { if (!$blacklist->isBlacklisted($function['filename'])) { $this->addFailure($test, new PHPUnit_Framework_RiskyTestError(sprintf('%s() used in %s:%s', $function['function'], $function['filename'], $function['lineno'])), $time); } } } if ($this->beStrictAboutTestsThatDoNotTestAnything && $test->getNumAssertions() == 0) { $risky = true; } if ($collectCodeCoverage) { $append = !$risky && !$incomplete && !$skipped; $linesToBeCovered = []; $linesToBeUsed = []; if ($append && $test instanceof PHPUnit_Framework_TestCase) { $linesToBeCovered = PHPUnit_Util_Test::getLinesToBeCovered(get_class($test), $test->getName(false)); $linesToBeUsed = PHPUnit_Util_Test::getLinesToBeUsed(get_class($test), $test->getName(false)); } try { $this->codeCoverage->stop($append, $linesToBeCovered, $linesToBeUsed); } catch (PHP_CodeCoverage_UnintentionallyCoveredCodeException $cce) { $this->addFailure($test, new PHPUnit_Framework_UnintentionallyCoveredCodeError('This test executed code that is not listed as code to be covered or used:' . PHP_EOL . $cce->getMessage()), $time); } catch (PHPUnit_Framework_InvalidCoversTargetException $cce) { $this->addFailure($test, new PHPUnit_Framework_InvalidCoversTargetError($cce->getMessage()), $time); } catch (PHP_CodeCoverage_Exception $cce) { $error = true; if (!isset($e)) { $e = $cce; } } } if ($errorHandlerSet === true) { restore_error_handler(); } if ($error === true) { $this->addError($test, $e, $time); } elseif ($failure === true) { $this->addFailure($test, $e, $time); } elseif ($warning === true) { $this->addWarning($test, $e, $time); } elseif ($this->beStrictAboutTestsThatDoNotTestAnything && $test->getNumAssertions() == 0) { $this->addFailure($test, new PHPUnit_Framework_RiskyTestError('This test did not perform any assertions'), $time); } elseif ($this->beStrictAboutOutputDuringTests && $test->hasOutput()) { $this->addFailure($test, new PHPUnit_Framework_OutputError(sprintf('This test printed output: %s', $test->getActualOutput())), $time); } elseif ($this->beStrictAboutTodoAnnotatedTests && $test instanceof PHPUnit_Framework_TestCase) { $annotations = $test->getAnnotations(); if (isset($annotations['method']['todo'])) { $this->addFailure($test, new PHPUnit_Framework_RiskyTestError('Test method is annotated with @todo'), $time); } } $this->endTest($test, $time); }
public static function getIncludedFilesAsString() { $blacklist = new PHPUnit_Util_Blacklist(); $files = get_included_files(); $prefix = false; $result = ''; if (defined('__PHPUNIT_PHAR__')) { $prefix = 'phar://' . __PHPUNIT_PHAR__ . '/'; } for ($i = count($files) - 1; $i > 0; $i--) { $file = $files[$i]; if ($prefix !== false && strpos($file, $prefix) === 0) { continue; } if (!$blacklist->isBlacklisted($file) && is_file($file)) { $result = 'require_once \'' . $file . "';\n" . $result; } } return $result; }
/** * @param array $arguments * @since Method available since Release 3.2.1 */ protected function handleConfiguration(array &$arguments) { if (isset($arguments['configuration']) && !$arguments['configuration'] instanceof PHPUnit_Util_Configuration) { $arguments['configuration'] = PHPUnit_Util_Configuration::getInstance($arguments['configuration']); } $arguments['debug'] = isset($arguments['debug']) ? $arguments['debug'] : false; $arguments['filter'] = isset($arguments['filter']) ? $arguments['filter'] : false; $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array(); if (isset($arguments['configuration'])) { $arguments['configuration']->handlePHPConfiguration(); $phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration(); if (isset($phpunitConfiguration['deprecatedStrictModeSetting'])) { $arguments['deprecatedStrictModeSetting'] = true; } if (isset($phpunitConfiguration['backupGlobals']) && !isset($arguments['backupGlobals'])) { $arguments['backupGlobals'] = $phpunitConfiguration['backupGlobals']; } if (isset($phpunitConfiguration['backupStaticAttributes']) && !isset($arguments['backupStaticAttributes'])) { $arguments['backupStaticAttributes'] = $phpunitConfiguration['backupStaticAttributes']; } if (isset($phpunitConfiguration['bootstrap']) && !isset($arguments['bootstrap'])) { $arguments['bootstrap'] = $phpunitConfiguration['bootstrap']; } if (isset($phpunitConfiguration['cacheTokens']) && !isset($arguments['cacheTokens'])) { $arguments['cacheTokens'] = $phpunitConfiguration['cacheTokens']; } if (isset($phpunitConfiguration['colors']) && !isset($arguments['colors'])) { $arguments['colors'] = $phpunitConfiguration['colors']; } if (isset($phpunitConfiguration['convertErrorsToExceptions']) && !isset($arguments['convertErrorsToExceptions'])) { $arguments['convertErrorsToExceptions'] = $phpunitConfiguration['convertErrorsToExceptions']; } if (isset($phpunitConfiguration['convertNoticesToExceptions']) && !isset($arguments['convertNoticesToExceptions'])) { $arguments['convertNoticesToExceptions'] = $phpunitConfiguration['convertNoticesToExceptions']; } if (isset($phpunitConfiguration['convertWarningsToExceptions']) && !isset($arguments['convertWarningsToExceptions'])) { $arguments['convertWarningsToExceptions'] = $phpunitConfiguration['convertWarningsToExceptions']; } if (isset($phpunitConfiguration['processIsolation']) && !isset($arguments['processIsolation'])) { $arguments['processIsolation'] = $phpunitConfiguration['processIsolation']; } if (isset($phpunitConfiguration['stopOnFailure']) && !isset($arguments['stopOnFailure'])) { $arguments['stopOnFailure'] = $phpunitConfiguration['stopOnFailure']; } if (isset($phpunitConfiguration['timeoutForSmallTests']) && !isset($arguments['timeoutForSmallTests'])) { $arguments['timeoutForSmallTests'] = $phpunitConfiguration['timeoutForSmallTests']; } if (isset($phpunitConfiguration['timeoutForMediumTests']) && !isset($arguments['timeoutForMediumTests'])) { $arguments['timeoutForMediumTests'] = $phpunitConfiguration['timeoutForMediumTests']; } if (isset($phpunitConfiguration['timeoutForLargeTests']) && !isset($arguments['timeoutForLargeTests'])) { $arguments['timeoutForLargeTests'] = $phpunitConfiguration['timeoutForLargeTests']; } if (isset($phpunitConfiguration['reportUselessTests']) && !isset($arguments['reportUselessTests'])) { $arguments['reportUselessTests'] = $phpunitConfiguration['reportUselessTests']; } if (isset($phpunitConfiguration['strictCoverage']) && !isset($arguments['strictCoverage'])) { $arguments['strictCoverage'] = $phpunitConfiguration['strictCoverage']; } if (isset($phpunitConfiguration['disallowTestOutput']) && !isset($arguments['disallowTestOutput'])) { $arguments['disallowTestOutput'] = $phpunitConfiguration['disallowTestOutput']; } if (isset($phpunitConfiguration['enforceTimeLimit']) && !isset($arguments['enforceTimeLimit'])) { $arguments['enforceTimeLimit'] = $phpunitConfiguration['enforceTimeLimit']; } if (isset($phpunitConfiguration['disallowTodoAnnotatedTests']) && !isset($arguments['disallowTodoAnnotatedTests'])) { $arguments['disallowTodoAnnotatedTests'] = $phpunitConfiguration['disallowTodoAnnotatedTests']; } if (isset($phpunitConfiguration['verbose']) && !isset($arguments['verbose'])) { $arguments['verbose'] = $phpunitConfiguration['verbose']; } if (isset($phpunitConfiguration['forceCoversAnnotation']) && !isset($arguments['forceCoversAnnotation'])) { $arguments['forceCoversAnnotation'] = $phpunitConfiguration['forceCoversAnnotation']; } if (isset($phpunitConfiguration['mapTestClassNameToCoveredClassName']) && !isset($arguments['mapTestClassNameToCoveredClassName'])) { $arguments['mapTestClassNameToCoveredClassName'] = $phpunitConfiguration['mapTestClassNameToCoveredClassName']; } $groupCliArgs = array(); if (!empty($arguments['groups'])) { $groupCliArgs = $arguments['groups']; } $groupConfiguration = $arguments['configuration']->getGroupConfiguration(); if (!empty($groupConfiguration['include']) && !isset($arguments['groups'])) { $arguments['groups'] = $groupConfiguration['include']; } if (!empty($groupConfiguration['exclude']) && !isset($arguments['excludeGroups'])) { $arguments['excludeGroups'] = array_diff($groupConfiguration['exclude'], $groupCliArgs); } foreach ($arguments['configuration']->getListenerConfiguration() as $listener) { if (!class_exists($listener['class'], false) && $listener['file'] !== '') { require_once $listener['file']; } if (class_exists($listener['class'])) { if (count($listener['arguments']) == 0) { $listener = new $listener['class'](); } else { $listenerClass = new ReflectionClass($listener['class']); $listener = $listenerClass->newInstanceArgs($listener['arguments']); } if ($listener instanceof PHPUnit_Framework_TestListener) { $arguments['listeners'][] = $listener; } } } $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration(); if (isset($loggingConfiguration['coverage-clover']) && !isset($arguments['coverageClover'])) { $arguments['coverageClover'] = $loggingConfiguration['coverage-clover']; } if (isset($loggingConfiguration['coverage-crap4j']) && !isset($arguments['coverageCrap4J'])) { $arguments['coverageCrap4J'] = $loggingConfiguration['coverage-crap4j']; } if (isset($loggingConfiguration['coverage-html']) && !isset($arguments['coverageHtml'])) { if (isset($loggingConfiguration['lowUpperBound']) && !isset($arguments['reportLowUpperBound'])) { $arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound']; } if (isset($loggingConfiguration['highLowerBound']) && !isset($arguments['reportHighLowerBound'])) { $arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound']; } $arguments['coverageHtml'] = $loggingConfiguration['coverage-html']; } if (isset($loggingConfiguration['coverage-php']) && !isset($arguments['coveragePHP'])) { $arguments['coveragePHP'] = $loggingConfiguration['coverage-php']; } if (isset($loggingConfiguration['coverage-text']) && !isset($arguments['coverageText'])) { $arguments['coverageText'] = $loggingConfiguration['coverage-text']; if (isset($loggingConfiguration['coverageTextShowUncoveredFiles'])) { $arguments['coverageTextShowUncoveredFiles'] = $loggingConfiguration['coverageTextShowUncoveredFiles']; } else { $arguments['coverageTextShowUncoveredFiles'] = false; } if (isset($loggingConfiguration['coverageTextShowOnlySummary'])) { $arguments['coverageTextShowOnlySummary'] = $loggingConfiguration['coverageTextShowOnlySummary']; } else { $arguments['coverageTextShowOnlySummary'] = false; } } if (isset($loggingConfiguration['coverage-xml']) && !isset($arguments['coverageXml'])) { $arguments['coverageXml'] = $loggingConfiguration['coverage-xml']; } if (isset($loggingConfiguration['json']) && !isset($arguments['jsonLogfile'])) { $arguments['jsonLogfile'] = $loggingConfiguration['json']; } if (isset($loggingConfiguration['plain'])) { $arguments['listeners'][] = new PHPUnit_TextUI_ResultPrinter($loggingConfiguration['plain'], true); } if (isset($loggingConfiguration['tap']) && !isset($arguments['tapLogfile'])) { $arguments['tapLogfile'] = $loggingConfiguration['tap']; } if (isset($loggingConfiguration['junit']) && !isset($arguments['junitLogfile'])) { $arguments['junitLogfile'] = $loggingConfiguration['junit']; if (isset($loggingConfiguration['logIncompleteSkipped']) && !isset($arguments['logIncompleteSkipped'])) { $arguments['logIncompleteSkipped'] = $loggingConfiguration['logIncompleteSkipped']; } } if (isset($loggingConfiguration['testdox-html']) && !isset($arguments['testdoxHTMLFile'])) { $arguments['testdoxHTMLFile'] = $loggingConfiguration['testdox-html']; } if (isset($loggingConfiguration['testdox-text']) && !isset($arguments['testdoxTextFile'])) { $arguments['testdoxTextFile'] = $loggingConfiguration['testdox-text']; } if ((isset($arguments['coverageClover']) || isset($arguments['coverageCrap4J']) || isset($arguments['coverageHtml']) || isset($arguments['coveragePHP']) || isset($arguments['coverageText']) || isset($arguments['coverageXml'])) && $this->canCollectCodeCoverage) { $filterConfiguration = $arguments['configuration']->getFilterConfiguration(); $arguments['addUncoveredFilesFromWhitelist'] = $filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist']; $arguments['processUncoveredFilesFromWhitelist'] = $filterConfiguration['whitelist']['processUncoveredFilesFromWhitelist']; if (empty($filterConfiguration['whitelist']['include']['directory']) && empty($filterConfiguration['whitelist']['include']['file'])) { if (defined('__PHPUNIT_PHAR__')) { $this->codeCoverageFilter->addFileToBlacklist(__PHPUNIT_PHAR__); } $blacklist = new PHPUnit_Util_Blacklist(); foreach ($blacklist->getBlacklistedDirectories() as $directory) { $this->codeCoverageFilter->addDirectoryToBlacklist($directory); } foreach ($filterConfiguration['blacklist']['include']['directory'] as $dir) { $this->codeCoverageFilter->addDirectoryToBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']); } foreach ($filterConfiguration['blacklist']['include']['file'] as $file) { $this->codeCoverageFilter->addFileToBlacklist($file); } foreach ($filterConfiguration['blacklist']['exclude']['directory'] as $dir) { $this->codeCoverageFilter->removeDirectoryFromBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']); } foreach ($filterConfiguration['blacklist']['exclude']['file'] as $file) { $this->codeCoverageFilter->removeFileFromBlacklist($file); } } foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) { $this->codeCoverageFilter->addDirectoryToWhitelist($dir['path'], $dir['suffix'], $dir['prefix']); } foreach ($filterConfiguration['whitelist']['include']['file'] as $file) { $this->codeCoverageFilter->addFileToWhitelist($file); } foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) { $this->codeCoverageFilter->removeDirectoryFromWhitelist($dir['path'], $dir['suffix'], $dir['prefix']); } foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) { $this->codeCoverageFilter->removeFileFromWhitelist($file); } } } $arguments['addUncoveredFilesFromWhitelist'] = isset($arguments['addUncoveredFilesFromWhitelist']) ? $arguments['addUncoveredFilesFromWhitelist'] : true; $arguments['processUncoveredFilesFromWhitelist'] = isset($arguments['processUncoveredFilesFromWhitelist']) ? $arguments['processUncoveredFilesFromWhitelist'] : false; $arguments['backupGlobals'] = isset($arguments['backupGlobals']) ? $arguments['backupGlobals'] : null; $arguments['backupStaticAttributes'] = isset($arguments['backupStaticAttributes']) ? $arguments['backupStaticAttributes'] : null; $arguments['cacheTokens'] = isset($arguments['cacheTokens']) ? $arguments['cacheTokens'] : false; $arguments['columns'] = isset($arguments['columns']) ? $arguments['columns'] : 80; $arguments['colors'] = isset($arguments['colors']) ? $arguments['colors'] : false; $arguments['convertErrorsToExceptions'] = isset($arguments['convertErrorsToExceptions']) ? $arguments['convertErrorsToExceptions'] : true; $arguments['convertNoticesToExceptions'] = isset($arguments['convertNoticesToExceptions']) ? $arguments['convertNoticesToExceptions'] : true; $arguments['convertWarningsToExceptions'] = isset($arguments['convertWarningsToExceptions']) ? $arguments['convertWarningsToExceptions'] : true; $arguments['excludeGroups'] = isset($arguments['excludeGroups']) ? $arguments['excludeGroups'] : array(); $arguments['groups'] = isset($arguments['groups']) ? $arguments['groups'] : array(); $arguments['logIncompleteSkipped'] = isset($arguments['logIncompleteSkipped']) ? $arguments['logIncompleteSkipped'] : false; $arguments['processIsolation'] = isset($arguments['processIsolation']) ? $arguments['processIsolation'] : false; $arguments['repeat'] = isset($arguments['repeat']) ? $arguments['repeat'] : false; $arguments['reportHighLowerBound'] = isset($arguments['reportHighLowerBound']) ? $arguments['reportHighLowerBound'] : 90; $arguments['reportLowUpperBound'] = isset($arguments['reportLowUpperBound']) ? $arguments['reportLowUpperBound'] : 50; $arguments['stopOnError'] = isset($arguments['stopOnError']) ? $arguments['stopOnError'] : false; $arguments['stopOnFailure'] = isset($arguments['stopOnFailure']) ? $arguments['stopOnFailure'] : false; $arguments['stopOnIncomplete'] = isset($arguments['stopOnIncomplete']) ? $arguments['stopOnIncomplete'] : false; $arguments['stopOnRisky'] = isset($arguments['stopOnRisky']) ? $arguments['stopOnRisky'] : false; $arguments['stopOnSkipped'] = isset($arguments['stopOnSkipped']) ? $arguments['stopOnSkipped'] : false; $arguments['timeoutForSmallTests'] = isset($arguments['timeoutForSmallTests']) ? $arguments['timeoutForSmallTests'] : 1; $arguments['timeoutForMediumTests'] = isset($arguments['timeoutForMediumTests']) ? $arguments['timeoutForMediumTests'] : 10; $arguments['timeoutForLargeTests'] = isset($arguments['timeoutForLargeTests']) ? $arguments['timeoutForLargeTests'] : 60; $arguments['reportUselessTests'] = isset($arguments['reportUselessTests']) ? $arguments['reportUselessTests'] : false; $arguments['strictCoverage'] = isset($arguments['strictCoverage']) ? $arguments['strictCoverage'] : false; $arguments['disallowTestOutput'] = isset($arguments['disallowTestOutput']) ? $arguments['disallowTestOutput'] : false; $arguments['enforceTimeLimit'] = isset($arguments['enforceTimeLimit']) ? $arguments['enforceTimeLimit'] : false; $arguments['disallowTodoAnnotatedTests'] = isset($arguments['disallowTodoAnnotatedTests']) ? $arguments['disallowTodoAnnotatedTests'] : false; $arguments['verbose'] = isset($arguments['verbose']) ? $arguments['verbose'] : false; }
/** * Get the dependend classes of this test. * * @return string[] An array containing class names as keys and path to the * file's defining class as value. * * @author Dominik del Bondio <*****@*****.**> * @since 1.1.0 */ private function getDependendClasses() { // We need to collect the dependend classes in case there is a test which // has set @agaviBootstrap to off. That results in the Agavi autoloader not // being started and if the test class depends on any files from Agavi (like // AgaviPhpUnitTestCase) it would not be loaded when the test is instantiated $classesInTest = array(); $reflectionClass = new ReflectionClass(get_class($this)); $testFile = $reflectionClass->getFileName(); $getDeclaredFuncs = array('get_declared_classes', 'get_declared_interfaces'); if (version_compare(PHP_VERSION, '5.4', '>=')) { $getDeclaredFuncs[] = 'get_declared_traits'; } foreach ($getDeclaredFuncs as $getDeclaredFunc) { foreach ($getDeclaredFunc() as $name) { $reflectionClass = new ReflectionClass($name); if ($testFile === $reflectionClass->getFileName()) { $classesInTest[] = $name; } } } // FIXME: added by phpunit 4.x if (class_exists('PHPUnit_Util_Blacklist')) { $blacklist = new PHPUnit_Util_Blacklist(); $isBlacklisted = function ($file) use($testFile, $blacklist) { return $file === $testFile || $blacklist->isBlacklisted($file); }; } elseif (is_callable(array('PHPUnit_Util_GlobalState', 'phpunitFiles'))) { $blacklist = PHPUnit_Util_GlobalState::phpunitFiles(); $isBlacklisted = function ($file) use($testFile, $blacklist) { return $file === $testFile || isset($blacklist[$file]); }; } else { $isBlacklisted = function ($file) use($testFile) { return $file === $testFile; }; } $classesToFile = array('AgaviTesting' => realpath(__DIR__ . '/AgaviTesting.class.php')); foreach ($classesInTest as $className) { $classesToFile = array_merge($classesToFile, $this->getClassDependendFiles(new ReflectionClass($className), $isBlacklisted)); } return $classesToFile; }