Implementation of stream_resolve_include_path() in PHP
for version before PHP 5.3.2.
public static fileExistsInIncludePath ( string $file ) : mixed | ||
$file | string | |
리턴 | mixed |
/** * @param string $type The type of concrete Log subclass to use. * Currently, valid values are 'console', * 'syslog', 'sql', 'file', and 'mcal'. * @param string $name The name of the actually log file, table, or * other specific store to use. Defaults to an * empty string, with which the subclass will * attempt to do something intelligent. * @param string $ident The identity reported to the log system. * @param array $conf A hash containing any additional configuration * information that a subclass might need. * @param int $maxLevel Maximum priority level at which to log. */ public function __construct($type, $name = '', $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG) { if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Log.php')) { require_once 'Log.php'; } else { throw new RuntimeException('Log is not available.'); } $this->log = Log::factory($type, $name, $ident, $conf, $maxLevel); }
/** * Checks if a PHP sourcefile is readable. * The sourcefile is loaded through the load() method. * * @param string $filename * @throws RuntimeException */ public static function checkAndLoad($filename) { $includePathFilename = PHPUnit_Util_Filesystem::fileExistsInIncludePath($filename); if (!$includePathFilename || !is_readable($includePathFilename)) { throw new RuntimeException(sprintf('Cannot open file "%s".' . "\n", $filename)); } self::load($includePathFilename); return $includePathFilename; }
function phpunit_autoload($class) { if (strpos($class, 'PHPUnit_') === 0) { $file = str_replace('_', '/', $class) . '.php'; $file = PHPUnit_Util_Filesystem::fileExistsInIncludePath($file); if ($file) { require_once $file; } } }
function phpunit_autoload($class) { if (strpos($class, 'PHPUnit_') === 0) { $file = str_replace('_', '/', $class) . '.php'; $file = PHPUnit_Util_Filesystem::fileExistsInIncludePath($file); if ($file) { require_once $file; PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist($file, 'PHPUNIT'); } } }
/** * @param string $type The type of concrete Log subclass to use. * Currently, valid values are 'console', * 'syslog', 'sql', 'file', and 'mcal'. * @param string $name The name of the actually log file, table, or * other specific store to use. Defaults to an * empty string, with which the subclass will * attempt to do something intelligent. * @param string $ident The identity reported to the log system. * @param array $conf A hash containing any additional configuration * information that a subclass might need. * @param int $maxLevel Maximum priority level at which to log. */ public function __construct($type, $name = '', $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG) { if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Log.php')) { PHPUnit_Util_Filesystem::collectStart(); require_once 'Log.php'; $this->log = Log::factory($type, $name, $ident, $conf, $maxLevel); foreach (PHPUnit_Util_Filesystem::collectEnd() as $blacklistedFile) { PHPUnit_Util_Filter::addFileToFilter($blacklistedFile, 'PHPUNIT'); } } else { throw new RuntimeException('Log is not available.'); } }
/** * Loads a PHP sourcefile. * * @param string $filename * @return mixed * @since Method available since Release 3.0.0 */ public static function load($filename) { $filename = PHPUnit_Util_Filesystem::fileExistsInIncludePath($filename); $oldVariableNames = array_keys(get_defined_vars()); include_once $filename; $newVariables = get_defined_vars(); $newVariableNames = array_diff(array_keys($newVariables), $oldVariableNames); foreach ($newVariableNames as $variableName) { if ($variableName != 'oldVariableNames') { $GLOBALS[$variableName] = $newVariables[$variableName]; } } return $filename; }
/** * Loads a PHP sourcefile. * * @param string $filename * @return mixed * @since Method available since Release 3.0.0 */ public static function load($filename) { $_filename = PHPUnit_Util_Filesystem::fileExistsInIncludePath($filename); if (!$_filename) { throw new RuntimeException(sprintf('Cannot open file "%s".' . "\n", $filename)); } $filename = $_filename; $oldVariableNames = array_keys(get_defined_vars()); unset($_filename); include_once $filename; $newVariables = get_defined_vars(); $newVariableNames = array_diff(array_keys($newVariables), $oldVariableNames); foreach ($newVariableNames as $variableName) { if ($variableName != 'oldVariableNames') { $GLOBALS[$variableName] = $newVariables[$variableName]; } } return $filename; }
protected function updateTicket($ticketId, $newStatus, $message, $resolution) { if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('XML/RPC2/Client.php')) { PHPUnit_Util_Filesystem::collectStart(); require_once 'XML/RPC2/Client.php'; $ticket = XML_RPC2_Client::create($this->scheme . '://' . $this->username . ':' . $this->password . '@' . $this->hostpath, array('prefix' => 'ticket.')); try { $ticketInfo = $ticket->get($ticketId); } catch (XML_RPC2_FaultException $e) { throw new PHPUnit_Framework_Exception(sprintf("Trac fetch failure: %d: %s\n", $e->getFaultCode(), $e->getFaultString())); } try { printf("Updating Trac ticket #%d, status: %s\n", $ticketId, $newStatus); $ticket->update($ticketId, $message, array('status' => $newStatus, 'resolution' => $resolution)); } catch (XML_RPC2_FaultException $e) { throw new PHPUnit_Framework_Exception(sprintf("Trac update failure: %d: %s\n", $e->getFaultCode(), $e->getFaultString())); } PHPUnit_Util_Filesystem::collectEndAndAddToBlacklist(); } else { throw new PHPUnit_Framework_Exception('XML_RPC2 is not available.'); } }
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @category Testing * @package PHPUnit * @author Sebastian Bergmann <*****@*****.**> * @copyright 2002-2010 Sebastian Bergmann <*****@*****.**> * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 3.0.0 */ require_once 'PHPUnit/Framework.php'; require_once 'PHPUnit/Util/Filter.php'; require_once 'PHPUnit/Util/Printer.php'; require_once 'PHPUnit/Util/Test.php'; if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('SymfonyComponents/YAML/sfYamlDumper.php')) { require_once 'SymfonyComponents/YAML/sfYamlDumper.php'; } PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); /** * A TestListener that generates a logfile of the * test execution using the Test Anything Protocol (TAP). * * @category Testing * @package PHPUnit * @author Sebastian Bergmann <*****@*****.**> * @copyright 2002-2010 Sebastian Bergmann <*****@*****.**> * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 3.4.15 * @link http://www.phpunit.de/ * @since Class available since Release 3.0.0
/** * @param array $checksums * @param array $data * @return array * @since Method available since Release 1.1.0 */ protected function matchPaths(array $checksums, array $data) { $coverageWithLocalPaths = array(); foreach ($data as $originalRemotePath => $coverage) { $remotePath = $originalRemotePath; if (strpos($path, '/') !== FALSE) { $separator = '/'; } else { $separator = '\\'; } while (!($localPath = PHPUnit_Util_Filesystem::fileExistsInIncludePath($remotePath)) && strpos($remotePath, $separator) !== FALSE) { $remotePath = substr($remotePath, strpos($remotePath, $separator) + 1); } if ($localPath && sha1_file($localPath) == $checksums[$originalRemotePath]) { $coverageWithLocalPaths[$localPath] = $coverage; } } return $coverageWithLocalPaths; }
/** * @param string $path * @param boolean $useIncludePath * @return string * @since Method available since Release 3.5.0 */ protected function toAbsolutePath($path, $useIncludePath = FALSE) { // Check whether the path is already absolute. if ($path[0] === '/' || $path[0] === '\\' || strlen($path) > 3 && ctype_alpha($path[0]) && $path[1] === ':' && ($path[2] === '\\' || $path[2] === '/')) { return $path; } // Check whether a stream is used. if (strpos($path, '://') !== FALSE) { return $path; } $file = dirname($this->filename) . DIRECTORY_SEPARATOR . $path; if ($useIncludePath && !file_exists($file)) { $includePathFile = PHPUnit_Util_Filesystem::fileExistsInIncludePath($path); if ($includePathFile) { $file = $includePathFile; } } return $file; }
/** * Constructor. * * @param mixed $out */ public function __construct($out = NULL) { if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) { require_once 'Image/GraphViz.php'; } else { throw new RuntimeException('Image_GraphViz is not available.'); } $this->graph = new Image_GraphViz(TRUE, array('overlap' => 'scale', 'splines' => 'true', 'sep' => '.1', 'fontsize' => '8')); parent::__construct($out); }
/** * @param array $coverage * @return array * @author Mattis Stordalen Flister <*****@*****.**> * @since Method available since Release 3.2.9 */ protected function matchLocalAndRemotePaths(array $coverage) { $coverageWithLocalPaths = array(); foreach ($coverage as $originalRemotePath => $data) { $remotePath = $originalRemotePath; $separator = $this->findDirectorySeparator($remotePath); while (!($localpath = PHPUnit_Util_Filesystem::fileExistsInIncludePath($remotePath)) && strpos($remotePath, $separator) !== FALSE) { $remotePath = substr($remotePath, strpos($remotePath, $separator) + 1); } if ($localpath && md5_file($localpath) == $data['md5']) { $coverageWithLocalPaths[$localpath] = $data['coverage']; } } return $coverageWithLocalPaths; }
/** * Constructor. * * @param mixed $out */ public function __construct($out = NULL) { if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) { PHPUnit_Util_Filesystem::collectStart(); require_once 'Image/GraphViz.php'; $this->graph = new Image_GraphViz(TRUE, array('overlap' => 'scale', 'splines' => 'true', 'sep' => '.1', 'fontsize' => '8')); parent::__construct($out); foreach (PHPUnit_Util_Filesystem::collectEnd() as $blacklistedFile) { PHPUnit_Util_Filter::addFileToFilter($blacklistedFile, 'PHPUNIT'); } } else { throw new RuntimeException('Image_GraphViz is not available.'); } }
/** */ protected static function handleArguments() { $arguments = array('listGroups' => FALSE, 'syntaxCheck' => TRUE); $longOptions = array('ansi', 'bootstrap=', 'configuration=', 'coverage-html=', 'coverage-clover=', 'coverage-source=', 'coverage-xml=', 'exclude-group=', 'filter=', 'group=', 'help', 'list-groups', 'loader=', 'log-graphviz=', 'log-json=', 'log-metrics=', 'log-pmd=', 'log-tap=', 'log-xml=', 'repeat=', 'report=', 'skeleton', 'skeleton-class', 'skeleton-test', 'stop-on-failure', 'story', 'story-html=', 'story-text=', 'tap', 'test-db-dsn=', 'test-db-log-rev=', 'test-db-log-prefix=', 'test-db-log-info=', 'testdox', 'testdox-html=', 'testdox-text=', 'no-syntax-check', 'verbose', 'version', 'wait'); try { $options = PHPUnit_Util_Getopt::getopt($_SERVER['argv'], 'd:', $longOptions); } catch (RuntimeException $e) { PHPUnit_TextUI_TestRunner::showError($e->getMessage()); } if (isset($options[1][0])) { $arguments['test'] = $options[1][0]; } if (isset($options[1][1])) { $arguments['testFile'] = $options[1][1]; } else { $arguments['testFile'] = ''; } foreach ($options[0] as $option) { switch ($option[0]) { case '--ansi': $arguments['ansi'] = TRUE; break; case '--bootstrap': $arguments['bootstrap'] = $option[1]; break; case '--configuration': $arguments['configuration'] = $option[1]; break; case '--coverage-clover': case '--coverage-xml': if (extension_loaded('tokenizer') && extension_loaded('xdebug')) { $arguments['coverageClover'] = $option[1]; } else { if (!extension_loaded('tokenizer')) { self::showMissingDependency('The tokenizer extension is not loaded.'); } else { self::showMissingDependency('The Xdebug extension is not loaded.'); } } break; case '--coverage-source': if (extension_loaded('tokenizer') && extension_loaded('xdebug')) { $arguments['coverageSource'] = $option[1]; } else { if (!extension_loaded('tokenizer')) { self::showMissingDependency('The tokenizer extension is not loaded.'); } else { self::showMissingDependency('The Xdebug extension is not loaded.'); } } break; case '--coverage-html': case '--report': if (extension_loaded('tokenizer') && extension_loaded('xdebug')) { $arguments['reportDirectory'] = $option[1]; } else { if (!extension_loaded('tokenizer')) { self::showMissingDependency('The tokenizer extension is not loaded.'); } else { self::showMissingDependency('The Xdebug extension is not loaded.'); } } break; case 'd': $ini = explode('=', $option[1]); if (isset($ini[0])) { if (isset($ini[1])) { ini_set($ini[0], $ini[1]); } else { ini_set($ini[0], TRUE); } } break; case '--help': self::showHelp(); exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); break; case '--filter': if (preg_match('/^[a-zA-Z0-9_]/', $option[1])) { $arguments['filter'] = '/' . $option[1] . '/'; } else { $arguments['filter'] = $option[1]; } break; case '--group': $arguments['groups'] = explode(',', $option[1]); break; case '--exclude-group': $arguments['excludeGroups'] = explode(',', $option[1]); break; case '--list-groups': $arguments['listGroups'] = TRUE; break; case '--loader': self::handleLoader($option[1]); break; case '--log-json': $arguments['jsonLogfile'] = $option[1]; break; case '--log-graphviz': if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) { $arguments['graphvizLogfile'] = $option[1]; } else { self::showMissingDependency('The Image_GraphViz package is not installed.'); } break; case '--log-tap': $arguments['tapLogfile'] = $option[1]; break; case '--log-xml': $arguments['xmlLogfile'] = $option[1]; break; case '--log-pmd': if (extension_loaded('tokenizer') && extension_loaded('xdebug')) { $arguments['pmdXML'] = $option[1]; } else { if (!extension_loaded('tokenizer')) { self::showMissingDependency('The tokenizer extension is not loaded.'); } else { self::showMissingDependency('The Xdebug extension is not loaded.'); } } break; case '--log-metrics': if (extension_loaded('tokenizer') && extension_loaded('xdebug')) { $arguments['metricsXML'] = $option[1]; } else { if (!extension_loaded('tokenizer')) { self::showMissingDependency('The tokenizer extension is not loaded.'); } else { self::showMissingDependency('The Xdebug extension is not loaded.'); } } break; case '--repeat': $arguments['repeat'] = (int) $option[1]; break; case '--stop-on-failure': $arguments['stopOnFailure'] = TRUE; break; case '--test-db-dsn': if (extension_loaded('pdo')) { $arguments['testDatabaseDSN'] = $option[1]; } else { self::showMissingDependency('The PDO extension is not loaded.'); } break; case '--test-db-log-rev': if (extension_loaded('pdo')) { $arguments['testDatabaseLogRevision'] = $option[1]; } else { self::showMissingDependency('The PDO extension is not loaded.'); } break; case '--test-db-prefix': if (extension_loaded('pdo')) { $arguments['testDatabasePrefix'] = $option[1]; } else { self::showMissingDependency('The PDO extension is not loaded.'); } break; case '--test-db-log-info': if (extension_loaded('pdo')) { $arguments['testDatabaseLogInfo'] = $option[1]; } else { self::showMissingDependency('The PDO extension is not loaded.'); } break; case '--skeleton': case '--skeleton-class': case '--skeleton-test': if (isset($arguments['bootstrap'])) { require_once $arguments['bootstrap']; } if ($option[0] == '--skeleton-class') { require_once 'PHPUnit/Util/Skeleton/Class.php'; $class = 'PHPUnit_Util_Skeleton_Class'; } else { require_once 'PHPUnit/Util/Skeleton/Test.php'; $class = 'PHPUnit_Util_Skeleton_Test'; } if (isset($arguments['test']) && $arguments['test'] !== FALSE && isset($arguments['testFile'])) { PHPUnit_TextUI_TestRunner::printVersionString(); try { $skeleton = new $class($arguments['test'], $arguments['testFile']); $skeleton->write(); } catch (Exception $e) { print $e->getMessage() . "\n"; printf('Could not skeleton for "%s" to "%s".' . "\n", $skeleton->getOutClassName(), $skeleton->getOutSourceFile()); exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } printf('Wrote skeleton for "%s" to "%s".' . "\n", $skeleton->getOutClassName(), $skeleton->getOutSourceFile()); exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); } else { self::showHelp(); exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); } break; case '--tap': require_once 'PHPUnit/Util/Log/TAP.php'; $arguments['printer'] = new PHPUnit_Util_Log_TAP(); break; case '--story': require_once 'PHPUnit/Extensions/Story/ResultPrinter/Text.php'; $arguments['printer'] = new PHPUnit_Extensions_Story_ResultPrinter_Text(); break; case '--story-html': $arguments['storyHTMLFile'] = $option[1]; break; case '--story-text': $arguments['storyTextFile'] = $option[1]; break; case '--testdox': require_once 'PHPUnit/Util/TestDox/ResultPrinter/Text.php'; $arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text(); break; case '--testdox-html': $arguments['testdoxHTMLFile'] = $option[1]; break; case '--testdox-text': $arguments['testdoxTextFile'] = $option[1]; break; case '--no-syntax-check': $arguments['syntaxCheck'] = FALSE; break; case '--verbose': $arguments['verbose'] = TRUE; break; case '--version': PHPUnit_TextUI_TestRunner::printVersionString(); exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); break; case '--wait': $arguments['wait'] = TRUE; break; } } if (!isset($arguments['test']) && isset($arguments['configuration'])) { $configuration = new PHPUnit_Util_Configuration($arguments['configuration']); $configuration->handlePHPConfiguration(); $testSuite = $configuration->getTestSuiteConfiguration(); if ($testSuite !== NULL) { $arguments['test'] = $testSuite; } } if (isset($arguments['test']) && is_string($arguments['test']) && substr($arguments['test'], -5, 5) == '.phpt') { require_once 'PHPUnit/Extensions/PhptTestCase.php'; $test = new PHPUnit_Extensions_PhptTestCase($arguments['test']); $arguments['test'] = new PHPUnit_Framework_TestSuite(); $arguments['test']->addTest($test); } if (!isset($arguments['test']) || isset($arguments['testDatabaseLogRevision']) && !isset($arguments['testDatabaseDSN'])) { self::showHelp(); exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); } return $arguments; }
/** * Loads a PHP sourcefile. * * @param string $filename * @return mixed * @since Method available since Release 3.0.0 */ public static function load($filename) { /* Wikia change begin - @author macbre */ // Copy references to global variables into function's scope (in which tests files are loaded), // so MW global variables can be altered (BugID #902) extract($GLOBALS); /* Wikia change end */ $filename = PHPUnit_Util_Filesystem::fileExistsInIncludePath( $filename ); include_once $filename; return $filename; }
/** * Loads a PHP sourcefile. * * @param string $filename * @return mixed * @since Method available since Release 3.0.0 */ public static function load($filename) { $filename = PHPUnit_Util_Filesystem::fileExistsInIncludePath($filename); if (!$filename) { throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'existing file', $filename); } $oldVariableNames = array_keys(get_defined_vars()); include_once $filename; $newVariables = get_defined_vars(); $newVariableNames = array_diff(array_keys($newVariables), $oldVariableNames); foreach ($newVariableNames as $variableName) { if ($variableName != 'oldVariableNames') { $GLOBALS[$variableName] = $newVariables[$variableName]; } } return $filename; }
/** * @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['pmd'] = $arguments['configuration']->getPMDConfiguration(); } else { $arguments['pmd'] = array(); } $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['repeat'] = isset($arguments['repeat']) ? $arguments['repeat'] : FALSE; $arguments['testDatabasePrefix'] = isset($arguments['testDatabasePrefix']) ? $arguments['testDatabasePrefix'] : ''; $arguments['verbose'] = isset($arguments['verbose']) ? $arguments['verbose'] : FALSE; $arguments['wait'] = isset($arguments['wait']) ? $arguments['wait'] : FALSE; if (isset($arguments['configuration'])) { $arguments['configuration']->handlePHPConfiguration(); $filterConfiguration = $arguments['configuration']->getFilterConfiguration(); PHPUnit_Util_Filter::$addUncoveredFilesFromWhitelist = $filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist']; foreach ($filterConfiguration['blacklist']['include']['directory'] as $dir) { PHPUnit_Util_Filter::addDirectoryToFilter($dir['path'], $dir['suffix'], $dir['group'], $dir['prefix']); } foreach ($filterConfiguration['blacklist']['include']['file'] as $file) { PHPUnit_Util_Filter::addFileToFilter($file); } foreach ($filterConfiguration['blacklist']['exclude']['directory'] as $dir) { PHPUnit_Util_Filter::removeDirectoryFromFilter($dir['path'], $dir['suffix'], $dir['group'], $dir['prefix']); } foreach ($filterConfiguration['blacklist']['exclude']['file'] as $file) { PHPUnit_Util_Filter::removeFileFromFilter($file); } foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) { PHPUnit_Util_Filter::addDirectoryToWhitelist($dir['path'], $dir['suffix'], $dir['prefix']); } foreach ($filterConfiguration['whitelist']['include']['file'] as $file) { PHPUnit_Util_Filter::addFileToWhitelist($file); } foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) { PHPUnit_Util_Filter::removeDirectoryFromWhitelist($dir['path'], $dir['suffix'], $dir['prefix']); } foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) { PHPUnit_Util_Filter::removeFileFromWhitelist($file); } $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']; } $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['coverage-xml']) && !isset($arguments['coverageClover'])) { $arguments['coverageClover'] = $loggingConfiguration['coverage-xml']; } if (isset($loggingConfiguration['coverage-source']) && !isset($arguments['coverageSource'])) { $arguments['coverageSource'] = $loggingConfiguration['coverage-source']; } if (isset($loggingConfiguration['graphviz']) && !isset($arguments['graphvizLogfile'])) { $arguments['graphvizLogfile'] = $loggingConfiguration['graphviz']; } if (isset($loggingConfiguration['json']) && !isset($arguments['jsonLogfile'])) { $arguments['jsonLogfile'] = $loggingConfiguration['json']; } if (isset($loggingConfiguration['metrics-xml']) && !isset($arguments['metricsXML'])) { $arguments['metricsXML'] = $loggingConfiguration['metrics-xml']; } if (isset($loggingConfiguration['plain'])) { $arguments['listeners'][] = new PHPUnit_TextUI_ResultPrinter($loggingConfiguration['plain'], TRUE); } if (isset($loggingConfiguration['pmd-xml']) && !isset($arguments['pmdXML'])) { if (isset($loggingConfiguration['cpdMinLines']) && !isset($arguments['cpdMinLines'])) { $arguments['cpdMinLines'] = $loggingConfiguration['cpdMinLines']; } if (isset($loggingConfiguration['cpdMinMatches']) && !isset($arguments['cpdMinMatches'])) { $arguments['cpdMinMatches'] = $loggingConfiguration['cpdMinMatches']; } $arguments['pmdXML'] = $loggingConfiguration['pmd-xml']; } 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']; } } $arguments['backupGlobals'] = isset($arguments['backupGlobals']) ? $arguments['backupGlobals'] : NULL; $arguments['backupStaticAttributes'] = isset($arguments['backupStaticAttributes']) ? $arguments['backupStaticAttributes'] : NULL; $arguments['cpdMinLines'] = isset($arguments['cpdMinLines']) ? $arguments['cpdMinLines'] : 5; $arguments['cpdMinMatches'] = isset($arguments['cpdMinMatches']) ? $arguments['cpdMinMatches'] : 70; $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'] : TRUE; $arguments['reportHighLowerBound'] = isset($arguments['reportHighLowerBound']) ? $arguments['reportHighLowerBound'] : 70; $arguments['reportLowUpperBound'] = isset($arguments['reportLowUpperBound']) ? $arguments['reportLowUpperBound'] : 35; $arguments['reportYUI'] = FALSE; $arguments['stopOnFailure'] = isset($arguments['stopOnFailure']) ? $arguments['stopOnFailure'] : FALSE; if ($arguments['filter'] !== FALSE && preg_match('/^[a-zA-Z0-9_]/', $arguments['filter'])) { // Escape delimiters in regular expression. Do NOT use preg_quote, // to keep magic characters. $arguments['filter'] = '/' . str_replace('/', '\\/', $arguments['filter']) . '/'; } }
/** * @param PHPUnit_Framework_Test $suite * @param array $arguments * @return PHPUnit_Framework_TestResult */ public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array()) { $this->handleConfiguration($arguments); if (isset($arguments['bootstrap'])) { require_once $arguments['bootstrap']; } if (is_integer($arguments['repeat'])) { $suite = new PHPUnit_Extensions_RepeatedTest($suite, $arguments['repeat'], $arguments['filter'], $arguments['groups'], $arguments['excludeGroups']); } $result = $this->createTestResult(); if (!$arguments['convertErrorsToExceptions']) { $result->convertErrorsToExceptions(FALSE); } if (!$arguments['convertNoticesToExceptions']) { PHPUnit_Framework_Error_Notice::$enabled = FALSE; } if (!$arguments['convertWarningsToExceptions']) { PHPUnit_Framework_Error_Warning::$enabled = FALSE; } if ($arguments['stopOnFailure']) { $result->stopOnFailure(TRUE); } if ($this->printer === NULL) { if (isset($arguments['printer']) && $arguments['printer'] instanceof PHPUnit_Util_Printer) { $this->printer = $arguments['printer']; } else { $this->printer = new PHPUnit_TextUI_ResultPrinter(NULL, $arguments['verbose'], $arguments['ansi']); } } $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n\n"); foreach ($arguments['listeners'] as $listener) { $result->addListener($listener); } $result->addListener($this->printer); if (isset($arguments['storyHTMLFile'])) { require_once 'PHPUnit/Extensions/Story/ResultPrinter/HTML.php'; $result->addListener(new PHPUnit_Extensions_Story_ResultPrinter_HTML($arguments['storyHTMLFile'])); } if (isset($arguments['storyTextFile'])) { require_once 'PHPUnit/Extensions/Story/ResultPrinter/Text.php'; $result->addListener(new PHPUnit_Extensions_Story_ResultPrinter_Text($arguments['storyTextFile'])); } if (isset($arguments['testdoxHTMLFile'])) { require_once 'PHPUnit/Util/TestDox/ResultPrinter/HTML.php'; $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_HTML($arguments['testdoxHTMLFile'])); } if (isset($arguments['testdoxTextFile'])) { require_once 'PHPUnit/Util/TestDox/ResultPrinter/Text.php'; $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_Text($arguments['testdoxTextFile'])); } if (isset($arguments['graphvizLogfile'])) { if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) { require_once 'PHPUnit/Util/Log/GraphViz.php'; $result->addListener(new PHPUnit_Util_Log_GraphViz($arguments['graphvizLogfile'])); } } if ((isset($arguments['coverageClover']) || isset($arguments['coverageSource']) || isset($arguments['metricsXML']) || isset($arguments['pmdXML']) || isset($arguments['reportDirectory'])) && extension_loaded('xdebug')) { $result->collectCodeCoverageInformation(TRUE); } if (isset($arguments['jsonLogfile'])) { require_once 'PHPUnit/Util/Log/JSON.php'; $result->addListener(new PHPUnit_Util_Log_JSON($arguments['jsonLogfile'])); } if (isset($arguments['tapLogfile'])) { require_once 'PHPUnit/Util/Log/TAP.php'; $result->addListener(new PHPUnit_Util_Log_TAP($arguments['tapLogfile'])); } if (isset($arguments['xmlLogfile'])) { require_once 'PHPUnit/Util/Log/XML.php'; $result->addListener(new PHPUnit_Util_Log_XML($arguments['xmlLogfile'], $arguments['logIncompleteSkipped'])); } if (isset($arguments['testDatabaseDSN']) && isset($arguments['testDatabaseLogRevision']) && extension_loaded('pdo')) { $writeToTestDatabase = TRUE; } else { $writeToTestDatabase = FALSE; } if ($writeToTestDatabase) { $dbh = PHPUnit_Util_PDO::factory($arguments['testDatabaseDSN']); require_once 'PHPUnit/Util/Log/Database.php'; $dbListener = PHPUnit_Util_Log_Database::getInstance($dbh, $arguments['testDatabaseLogRevision'], isset($arguments['testDatabaseLogInfo']) ? $arguments['testDatabaseLogInfo'] : ''); $result->addListener($dbListener); $result->collectCodeCoverageInformation(TRUE); } $suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups']); $result->flushListeners(); if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) { $this->printer->printResult($result); } if (extension_loaded('tokenizer') && extension_loaded('xdebug')) { if (isset($arguments['coverageClover'])) { $this->printer->write("\nWriting code coverage data to XML file, this may take a moment."); require_once 'PHPUnit/Util/Log/CodeCoverage/XML/Clover.php'; $writer = new PHPUnit_Util_Log_CodeCoverage_XML_Clover($arguments['coverageClover']); $writer->process($result); $this->printer->write("\n"); } if (isset($arguments['coverageSource'])) { $this->printer->write("\nWriting code coverage data to XML files, this may take a moment."); require_once 'PHPUnit/Util/Log/CodeCoverage/XML/Source.php'; $writer = new PHPUnit_Util_Log_CodeCoverage_XML_Source($arguments['coverageSource']); $writer->process($result); $this->printer->write("\n"); } if ($writeToTestDatabase) { $this->printer->write("\nStoring code coverage and software metrics data in database.\nThis may take a moment."); require_once 'PHPUnit/Util/Log/CodeCoverage/Database.php'; $testDb = new PHPUnit_Util_Log_CodeCoverage_Database($dbh); $testDb->storeCodeCoverage($result, $dbListener->getRunId(), $arguments['testDatabaseLogRevision'], $arguments['testDatabasePrefix']); $this->printer->write("\n"); } if (isset($arguments['metricsXML'])) { $this->printer->write("\nWriting metrics report XML file, this may take a moment."); require_once 'PHPUnit/Util/Log/Metrics.php'; $writer = new PHPUnit_Util_Log_Metrics($arguments['metricsXML']); $writer->process($result); $this->printer->write("\n"); } if (isset($arguments['pmdXML'])) { require_once 'PHPUnit/Util/Log/PMD.php'; $writer = new PHPUnit_Util_Log_PMD($arguments['pmdXML'], $arguments['pmd']); $this->printer->write("\nWriting violations report XML file, this may take a moment."); $writer->process($result); require_once 'PHPUnit/Util/Log/CPD.php'; $writer = new PHPUnit_Util_Log_CPD(str_replace('.xml', '-cpd.xml', $arguments['pmdXML'])); $writer->process($result, $arguments['cpdMinLines'], $arguments['cpdMinMatches']); $this->printer->write("\n"); } if (isset($arguments['reportDirectory'])) { $this->printer->write("\nGenerating code coverage report, this may take a moment."); unset($suite); PHPUnit_Util_Report::render($result, $arguments['reportDirectory'], $arguments['reportCharset'], $arguments['reportYUI'], $arguments['reportHighlight'], $arguments['reportLowUpperBound'], $arguments['reportHighLowerBound']); $this->printer->write("\n"); } } $this->pause($arguments['wait']); return $result; }
/** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ require_once 'PHPUnit/Util/Filesystem.php'; if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('PHPUnit/Autoload.php')) { require_once 'PHPUnit/Autoload.php'; } else { require_once 'PHPUnit/TextUI/TestRunner.php'; require_once 'PHPUnit/Util/Log/PMD.php'; require_once 'PHPUnit/Util/Log/TAP.php'; require_once 'PHPUnit/Util/Configuration.php'; require_once 'PHPUnit/Util/Fileloader.php'; require_once 'PHPUnit/Util/Filter.php'; require_once 'PHPUnit/Util/Getopt.php'; require_once 'PHPUnit/Util/Skeleton.php'; require_once 'PHPUnit/Util/TestDox/ResultPrinter/Text.php'; // this indicates a version < 3.6.0 // --log-xml is replaced by --log-junit by phpunit version 3.6.0 for ($i = 0; $i < count($_SERVER['argv']); $i++) { if ($_SERVER['argv'][$i] == '--log-junit') {
/** * Returns the dependencies between the classes of this project * as GraphViz/DOT markup. * * @return Image_GraphViz * @since Method available since Release 3.2.2 */ public function getDependenciesAsDOT() { if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) { require_once 'Image/GraphViz.php'; } else { throw new RuntimeException('Image_GraphViz is not available.'); } $graph = new Image_GraphViz(TRUE, array('overlap' => 'scale', 'splines' => 'true', 'sep' => '.1', 'fontsize' => '8')); foreach (array_keys($this->dependencies) as $className) { $graph->addNode($className); } foreach ($this->dependencies as $from => $dependencies) { foreach ($dependencies as $to => $flag) { if ($flag === 1) { $graph->addEdge(array($from => $to)); } } } return $graph; }
foreach ($classes as $file) { $result[] = $path . $file; } return $result; } $cn = strtolower($class); if (isset($classes[$cn])) { $file = $path . $classes[$cn]; require $file; } } spl_autoload_register('phpunit_autoload'); if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('PHP/Invoker/Autoload.php')) { require_once 'PHP/Invoker/Autoload.php'; } if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('PHPUnit/Extensions/SeleniumTestCase/Autoload.php')) { require_once 'PHPUnit/Extensions/SeleniumTestCase/Autoload.php'; } if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('PHPUnit/Extensions/Story/Autoload.php')) { require_once 'PHPUnit/Extensions/Story/Autoload.php'; }
/** * Handles the commandline arguments passed. * * @return array the commandline arguments * * @author Felix Gilcher <*****@*****.**> * @since 1.0.0 */ public static function processCommandlineOptions() { $longOptions = array('coverage-html=', 'coverage-clover=', 'coverage-source=', 'coverage-xml=', 'report=', 'environment=', 'help', 'log-graphviz=', 'log-json=', 'log-metrics=', 'log-pmd=', 'log-tap=', 'log-xml=', 'include-suite=', 'exclude-suite='); try { $options = PHPUnit_Util_Getopt::getopt($_SERVER['argv'], 'd:', $longOptions); } catch (RuntimeException $e) { PHPUnit_TextUI_TestRunner::showError($e->getMessage()); } $arguments = array(); foreach ($options[0] as $option) { switch ($option[0]) { case '--coverage-clover': case '--coverage-xml': if (self::checkCodeCoverageDeps()) { $arguments['coverageClover'] = $option[1]; } break; case '--coverage-source': if (self::checkCodeCoverageDeps()) { $arguments['coverageSource'] = $option[1]; } break; case '--coverage-html': case '--report': if (self::checkCodeCoverageDeps()) { $arguments['reportDirectory'] = $option[1]; } break; case '--environment': $arguments['environment'] = $option[1]; break; case '--help': self::showHelp(); exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); break; case '--log-json': $arguments['jsonLogfile'] = $option[1]; break; case '--log-graphviz': if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) { $arguments['graphvizLogfile'] = $option[1]; } else { throw new AgaviException('The Image_GraphViz package is not installed.'); } break; case '--log-tap': $arguments['tapLogfile'] = $option[1]; break; case '--log-xml': $arguments['xmlLogfile'] = $option[1]; break; case '--log-pmd': if (self::checkCodeCoverageDeps()) { $arguments['pmdXML'] = $option[1]; } break; case '--log-metrics': if (self::checkCodeCoverageDeps()) { $arguments['metricsXML'] = $option[1]; } break; case '--include-suite': $arguments['include-suite'] = $option[1]; break; case '--exclude-suite': $arguments['exclude-suite'] = $option[1]; break; } } return $arguments; }
/** * Get a Trac XML_RPC2 client * * @return XML_RPC2_Client */ protected function getClient() { if (!PHPUnit_Util_Filesystem::fileExistsInIncludePath('XML/RPC2/Client.php')) { throw new PHPUnit_Framework_Exception('PEAR/XML_RPC2 is not available.'); } require_once 'XML/RPC2/Client.php'; $url = sprintf('%s://%s:%s@%s', $this->scheme, $this->username, $this->password, $this->hostpath); return XML_RPC2_Client::create($url, array('prefix' => 'ticket.')); }
/** * @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'] . '/'; } }
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package PHPUnit * @subpackage Extensions_PhptTestCase * @author Sebastian Bergmann <*****@*****.**> * @copyright 2002-2010 Sebastian Bergmann <*****@*****.**> * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 3.1.4 */ if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('PEAR/RunTest.php')) { $currentErrorReporting = error_reporting(E_ERROR | E_WARNING | E_PARSE); PHPUnit_Util_Filesystem::collectStart(); require_once 'PEAR/RunTest.php'; error_reporting($currentErrorReporting); PHPUnit_Util_Filesystem::collectEndAndAddToBlacklist(); } require_once 'PHP/CodeCoverage.php'; require_once 'PHP/Timer.php'; /** * Wrapper to run .phpt test cases. * * @package PHPUnit * @subpackage Extensions_PhptTestCase * @author Sebastian Bergmann <*****@*****.**> * @copyright 2002-2010 Sebastian Bergmann <*****@*****.**>
/** * Handles the loading of the PHPUnit_Runner_TestSuiteLoader implementation. * * @param string $loaderClass * @param string $loaderFile */ protected function handleLoader($loaderClass, $loaderFile = '') { if (!class_exists($loaderClass, FALSE)) { if ($loaderFile == '') { $loaderFile = PHPUnit_Util_Filesystem::classNameToFilename($loaderClass); } $loaderFile = PHPUnit_Util_Filesystem::fileExistsInIncludePath($loaderFile); if ($loaderFile !== FALSE) { require $loaderFile; } } if (class_exists($loaderClass, FALSE)) { $class = new ReflectionClass($loaderClass); if ($class->implementsInterface('PHPUnit_Runner_TestSuiteLoader') && $class->isInstantiable()) { $loader = $class->newInstance(); } } if (!isset($loader)) { PHPUnit_TextUI_TestRunner::showError(sprintf('Could not use "%s" as loader.', $loaderClass)); } return $loader; }
/** */ public static function showHelp() { PHPUnit_TextUI_TestRunner::printVersionString(); print "Usage: phpunit [switches] UnitTest [UnitTest.php]\n\n"; if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) { print " --log-graphviz <file> Log test execution in GraphViz markup.\n"; } print " --log-json <file> Log test execution in JSON format.\n" . " --log-tap <file> Log test execution in TAP format to file.\n" . " --log-xml <file> Log test execution in XML format to file.\n"; if (extension_loaded('tokenizer') && extension_loaded('xdebug')) { print " --log-metrics <file> Write metrics report in XML format.\n" . " --log-pmd <file> Write violations report in PMD XML format.\n\n" . " --coverage-html <dir> Generate code coverage report in HTML format.\n" . " --coverage-xml <file> Write code coverage information in XML format.\n\n"; } if (extension_loaded('pdo')) { print " --test-db-dsn <dsn> DSN for the test database.\n" . " --test-db-log-rev <r> Revision information for database logging.\n" . " --test-db-prefix ... Prefix that should be stripped from filenames.\n" . " --test-db-log-info ... Additional information for database logging.\n\n"; } print " --testdox-html <file> Write agile documentation in HTML format to file.\n" . " --testdox-text <file> Write agile documentation in Text format to file.\n\n" . " --filter <pattern> Filter which tests to run.\n" . " --group ... Only runs tests from the specified group(s).\n" . " --exclude-group ... Exclude tests from the specified group(s).\n\n" . " --loader <loader> TestSuiteLoader implementation to use.\n" . " --repeat <times> Runs the test(s) repeatedly.\n\n" . " --tap Report test execution progress in TAP format.\n" . " --testdox Report test execution progress in TestDox format.\n\n" . " --no-syntax-check Disable syntax check of test source files.\n" . " --stop-on-failure Stop execution upon first error or failure.\n" . " --verbose Output more verbose information.\n" . " --wait Waits for a keystroke after each test.\n\n" . " --skeleton Generate skeleton UnitTest class for Unit in Unit.php.\n\n" . " --help Prints this usage information.\n" . " --version Prints the version and exits.\n\n" . " --configuration <file> Read configuration from XML file.\n" . " -d key[=value] Sets a php.ini value.\n"; }