public static function suite() { $srcDir = dirname(dirname(dirname(__DIR__))) . '/src/Pyrus/AtomicFileTransaction/Transaction'; // Setup coverage filters $filter = PHP_CodeCoverage::getInstance()->filter(); $filter->addDirectoryToWhitelist($srcDir); // Build and return test suite return new PHPUnit_Extensions_PhptTestSuite(__DIR__); }
public static function handleError($level, $message, $file, $line) { $isFiltered = false; if (version_compare(PHPUnit_Runner_Version::id(), '3.5.0') >= 0) { $isFiltered = PHP_CodeCoverage::getInstance()->filter()->isFiltered($file, array(), true); } else { $isFiltered = PHPUnit_Util_Filter::isFiltered($file, true, true); } if (!$isFiltered) { return PHPUnit_Util_ErrorHandler::handleError($level, $message, $file, $line); } }
protected function prepare_harness() { if ($this->ver_phpunit < 3.5) { require_once 'PHPUnit/Framework.php'; require_once 'PHPUnit/TextUI/ResultPrinter.php'; require_once 'PHPUnit/TextUI/Command.php'; PHPUnit_Util_Filter::addDirectoryToFilter($this->root, '.php', 'PHPUNIT', ''); } elseif ($this->ver_phpunit < 3.6) { require_once 'PHPUnit/Autoload.php'; require_once 'PHP/CodeCoverage.php'; PHP_CodeCoverage::getInstance()->filter()->addDirectoryToBlacklist($this->root, '.php', '', 'PHPUNIT'); } else { // PHPUnit 3.6+ /** * Change to support PHPUnit 4+ * These libraries are loaded in via phpunit.phar or don't exist in PHPUnit 4+ */ //require_once( 'PHPUnit/Autoload.php' ); //require_once( 'PHP/CodeCoverage.php' ); $this->add_directory_to_blacklist($this->root, '.php'); } }
/** * Constructs a new TestSuite: * * - PHPUnit_Framework_TestSuite() constructs an empty TestSuite. * * - PHPUnit_Framework_TestSuite(ReflectionClass) constructs a * TestSuite from the given class. * * - PHPUnit_Framework_TestSuite(ReflectionClass, String) * constructs a TestSuite from the given class with the given * name. * * - PHPUnit_Framework_TestSuite(String) either constructs a * TestSuite from the given class (if the passed string is the * name of an existing class) or constructs an empty TestSuite * with the given name. * * @param mixed $theClass * @param string $name * @throws InvalidArgumentException */ public function __construct($theClass = '', $name = '') { $argumentsValid = FALSE; if (is_object($theClass) && $theClass instanceof ReflectionClass) { $argumentsValid = TRUE; } else { if (is_string($theClass) && $theClass !== '' && class_exists($theClass, FALSE)) { $argumentsValid = TRUE; if ($name == '') { $name = $theClass; } $theClass = new ReflectionClass($theClass); } else { if (is_string($theClass)) { $this->setName($theClass); return; } } } if (!$argumentsValid) { throw new InvalidArgumentException(); } if (!$theClass->isSubclassOf('PHPUnit_Framework_TestCase')) { throw new InvalidArgumentException('Class does not extend PHPUnit_Framework_TestCase.'); } $filename = $theClass->getFilename(); if (strpos($filename, 'eval()') === FALSE) { PHP_CodeCoverage::getInstance()->filter()->addFileToBlacklist(realpath($filename), 'TESTS'); } if ($name != '') { $this->setName($name); } else { $this->setName($theClass->getName()); } $constructor = $theClass->getConstructor(); if ($constructor !== NULL && !$constructor->isPublic()) { $this->addTest(self::warning(sprintf('Class "%s" has no public constructor.', $theClass->getName()))); return; } foreach ($theClass->getMethods() as $method) { if (strpos($method->getDeclaringClass()->getName(), 'PHPUnit_') !== 0) { $this->addTestMethod($theClass, $method); } } if (empty($this->tests)) { $this->addTest(self::warning(sprintf('No tests found in class "%s".', $theClass->getName()))); } $this->testCase = TRUE; }
/** * @param PHP_CodeCoverage $codeCoverage */ public function __construct(PHP_CodeCoverage $codeCoverage = NULL) { if ($codeCoverage === NULL) { $codeCoverage = PHP_CodeCoverage::getInstance(); } $this->codeCoverage = $codeCoverage; }
/** * @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(); $arguments['wait'] = isset($arguments['wait']) ? $arguments['wait'] : FALSE; if (isset($arguments['configuration'])) { $arguments['configuration']->handlePHPConfiguration(); $phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration(); 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['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['verbose']) && !isset($arguments['verbose'])) { $arguments['verbose'] = $phpunitConfiguration['verbose']; } $groupConfiguration = $arguments['configuration']->getGroupConfiguration(); if (!empty($groupConfiguration['include']) && !isset($arguments['groups'])) { $arguments['groups'] = $groupConfiguration['include']; } if (!empty($groupConfiguration['exclude']) && !isset($arguments['excludeGroups'])) { $arguments['excludeGroups'] = $groupConfiguration['exclude']; } foreach ($arguments['configuration']->getListenerConfiguration() as $listener) { if (!class_exists($listener['class'], FALSE) && $listener['file'] !== '') { $file = PHPUnit_Util_Filesystem::fileExistsInIncludePath($listener['file']); if ($file !== FALSE) { require $file; } } if (class_exists($listener['class'], FALSE)) { 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-html']) && !isset($arguments['reportDirectory'])) { if (isset($loggingConfiguration['charset']) && !isset($arguments['reportCharset'])) { $arguments['reportCharset'] = $loggingConfiguration['charset']; } if (isset($loggingConfiguration['yui']) && !isset($arguments['reportYUI'])) { $arguments['reportYUI'] = $loggingConfiguration['yui']; } if (isset($loggingConfiguration['highlight']) && !isset($arguments['reportHighlight'])) { $arguments['reportHighlight'] = $loggingConfiguration['highlight']; } if (isset($loggingConfiguration['lowUpperBound']) && !isset($arguments['reportLowUpperBound'])) { $arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound']; } if (isset($loggingConfiguration['highLowerBound']) && !isset($arguments['reportHighLowerBound'])) { $arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound']; } $arguments['reportDirectory'] = $loggingConfiguration['coverage-html']; } if (isset($loggingConfiguration['coverage-clover']) && !isset($arguments['coverageClover'])) { $arguments['coverageClover'] = $loggingConfiguration['coverage-clover']; } 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['story-html']) && !isset($arguments['storyHTMLFile'])) { $arguments['storyHTMLFile'] = $loggingConfiguration['story-html']; } if (isset($loggingConfiguration['story-text']) && !isset($arguments['storyTextFile'])) { $arguments['storsTextFile'] = $loggingConfiguration['story-text']; } 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['configuration'])) { $filterConfiguration = $arguments['configuration']->getFilterConfiguration(); $filter = PHP_CodeCoverage_Filter::getInstance(); foreach ($filterConfiguration['blacklist']['include']['directory'] as $dir) { $filter->addDirectoryToBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']); } foreach ($filterConfiguration['blacklist']['include']['file'] as $file) { $filter->addFileToBlacklist($file); } foreach ($filterConfiguration['blacklist']['exclude']['directory'] as $dir) { $filter->removeDirectoryFromBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']); } foreach ($filterConfiguration['blacklist']['exclude']['file'] as $file) { $filter->removeFileFromBlacklist($file); } if ((isset($arguments['coverageClover']) || isset($arguments['reportDirectory'])) && extension_loaded('xdebug')) { PHP_CodeCoverage::getInstance()->setProcessUncoveredFilesFromWhitelist($filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist']); foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) { $filter->addDirectoryToWhitelist($dir['path'], $dir['suffix'], $dir['prefix']); } foreach ($filterConfiguration['whitelist']['include']['file'] as $file) { $filter->addFileToWhitelist($file); } foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) { $filter->removeDirectoryFromWhitelist($dir['path'], $dir['suffix'], $dir['prefix']); } foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) { $filter->removeFileFromWhitelist($file); } } } $arguments['backupGlobals'] = isset($arguments['backupGlobals']) ? $arguments['backupGlobals'] : NULL; $arguments['backupStaticAttributes'] = isset($arguments['backupStaticAttributes']) ? $arguments['backupStaticAttributes'] : NULL; $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['reportCharset'] = isset($arguments['reportCharset']) ? $arguments['reportCharset'] : 'ISO-8859-1'; $arguments['reportHighlight'] = isset($arguments['reportHighlight']) ? $arguments['reportHighlight'] : FALSE; $arguments['reportHighLowerBound'] = isset($arguments['reportHighLowerBound']) ? $arguments['reportHighLowerBound'] : 70; $arguments['reportLowUpperBound'] = isset($arguments['reportLowUpperBound']) ? $arguments['reportLowUpperBound'] : 35; $arguments['reportYUI'] = isset($arguments['reportYUI']) ? $arguments['reportYUI'] : TRUE; $arguments['stopOnFailure'] = isset($arguments['stopOnFailure']) ? $arguments['stopOnFailure'] : FALSE; $arguments['verbose'] = isset($arguments['verbose']) ? $arguments['verbose'] : FALSE; if ($arguments['filter'] !== FALSE && preg_match('/^[a-zA-Z0-9_]/', $arguments['filter'])) { $arguments['filter'] = '/' . $arguments['filter'] . '/'; } }
/** * @covers PHP_CodeCoverage::getInstance */ public function testFactory() { $coverage = PHP_CodeCoverage::getInstance(); $this->assertSame($coverage, PHP_CodeCoverage::getInstance()); }
public static function getIncludedFilesAsString() { $blacklist = PHP_CodeCoverage::getInstance()->filter()->getBlacklist(); $blacklist = array_flip($blacklist['PHPUNIT']); $files = get_included_files(); $result = ''; for ($i = count($files) - 1; $i > 0; $i--) { if (!isset($blacklist[$files[$i]]) && is_file($files[$i])) { $result = 'require_once \'' . $files[$i] . "';\n" . $result; } } return $result; }
/** * Filters stack frames from PHPUnit classes. * * @param Exception $e * @param boolean $filterTests * @param boolean $asString * @return string */ public static function getFilteredStacktrace(Exception $e, $filterTests = TRUE, $asString = TRUE) { if ($asString === TRUE) { $filteredStacktrace = ''; } else { $filteredStacktrace = array(); } $groups = array('DEFAULT'); if (!defined('PHPUNIT_TESTSUITE')) { $groups[] = 'PHPUNIT'; } if ($filterTests) { $groups[] = 'TESTS'; } if ($e instanceof PHPUnit_Framework_SyntheticError) { $eTrace = $e->getSyntheticTrace(); } else { $eTrace = $e->getTrace(); } if (!self::frameExists($eTrace, $e->getFile(), $e->getLine())) { array_unshift($eTrace, array('file' => $e->getFile(), 'line' => $e->getLine())); } foreach ($eTrace as $frame) { if (isset($frame['file']) && is_file($frame['file']) && !PHP_CodeCoverage::getInstance()->filter()->isFiltered($frame['file'], $groups, TRUE)) { if ($asString === TRUE) { $filteredStacktrace .= sprintf("%s:%s\n", $frame['file'], isset($frame['line']) ? $frame['line'] : '?'); } else { $filteredStacktrace[] = $frame; } } } return $filteredStacktrace; }
$ini->loadCache(); // Be sure to have clean content language data eZContentLanguage::expireCache(); $script->startup(); // $options = $script->getOptions(); $script->initialize(); // Avoids Fatal error: eZ Publish did not finish its request if die() is used. eZExecution::setCleanExit(); $version = PHPUnit_Runner_Version::id(); if ( version_compare( $version, '3.5.0' ) == -1 && $version !== '@package_version@' ) { die( "PHPUnit 3.5.0 (or later) is required to run this test suite.\n" ); } require_once 'PHP/CodeCoverage.php'; PHP_CodeCoverage::getInstance()->filter()->addFileToBlacklist( __FILE__, 'PHPUNIT' ); //require_once 'bootstrap.php'; $runner = ezpTestRunner::instance(); $runner->run($_SERVER['argv']); $script->shutdown(); ?>