本文整理汇总了PHP中PHPUnit_Util_Fileloader::load方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Fileloader::load方法的具体用法?PHP PHPUnit_Util_Fileloader::load怎么用?PHP PHPUnit_Util_Fileloader::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Util_Fileloader
的用法示例。
在下文中一共展示了PHPUnit_Util_Fileloader::load方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
public static function main($configFile)
{
$arguments = array('listGroups' => FALSE, 'loader' => NULL, 'useDefaultConfiguration' => TRUE, 'configuration' => $configFile);
$configuration = PHPUnit_Util_Configuration::getInstance($configFile);
$configuration->handlePHPConfiguration();
$phpunit = $configuration->getPHPUnitConfiguration();
if (isset($phpunit['bootstrap'])) {
PHPUnit_Util_Fileloader::load($phpunit['bootstrap']);
}
$testSuite = $configuration->getTestSuiteConfiguration();
return self::runTest($testSuite, $arguments);
}
示例2: handleArguments
/**
* Handles the command-line arguments.
*
* A child class of PHPUnit_TextUI_Command can hook into the argument
* parsing by adding the switch(es) to the $longOptions array and point to a
* callback method that handles the switch(es) in the child class like this
*
* <code>
* <?php
* class MyCommand extends PHPUnit_TextUI_Command
* {
* public function __construct()
* {
* $this->longOptions['--my-switch'] = 'myHandler';
* }
*
* // --my-switch foo -> myHandler('foo')
* protected function myHandler($value)
* {
* }
* }
* </code>
*
* @param array $argv
*/
protected function handleArguments(array $argv)
{
try {
$this->options = PHPUnit_Util_Getopt::getopt($argv, 'd:', array_keys($this->longOptions));
} catch (RuntimeException $e) {
PHPUnit_TextUI_TestRunner::showError($e->getMessage());
}
$skeletonClass = FALSE;
$skeletonTest = FALSE;
foreach ($this->options[0] as $option) {
switch ($option[0]) {
case '--ansi':
$this->showMessage('The --ansi option is deprecated, please use --colors ' . 'instead.', FALSE);
case '--colors':
$this->arguments['colors'] = TRUE;
break;
case '--bootstrap':
$this->arguments['bootstrap'] = $option[1];
break;
case '--configuration':
$this->arguments['configuration'] = $option[1];
break;
case '--coverage-xml':
$this->showMessage('The --coverage-xml option is deprecated, please use ' . '--coverage-clover instead.', FALSE);
case '--coverage-clover':
if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
$this->arguments['coverageClover'] = $option[1];
} else {
if (!extension_loaded('tokenizer')) {
$this->showMessage('The tokenizer extension is not loaded.');
} else {
$this->showMessage('The Xdebug extension is not loaded.');
}
}
break;
case '--coverage-source':
if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
$this->arguments['coverageSource'] = $option[1];
} else {
if (!extension_loaded('tokenizer')) {
$this->showMessage('The tokenizer extension is not loaded.');
} else {
$this->showMessage('The Xdebug extension is not loaded.');
}
}
break;
case '--report':
$this->showMessage('The --report option is deprecated, please use ' . '--coverage-html instead.', FALSE);
case '--coverage-html':
if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
$this->arguments['reportDirectory'] = $option[1];
} else {
if (!extension_loaded('tokenizer')) {
$this->showMessage('The tokenizer extension is not loaded.');
} else {
$this->showMessage('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 '--debug':
$this->arguments['debug'] = TRUE;
break;
case '--help':
$this->showHelp();
exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
//.........这里部分代码省略.........
示例3: doRun
/**
* @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'])) {
$bootstrap = PHPUnit_Util_Fileloader::load($arguments['bootstrap']);
if ($bootstrap) {
$GLOBALS['__PHPUNIT_BOOTSTRAP'] = $bootstrap;
}
}
if ($arguments['backupGlobals'] === FALSE) {
$suite->setBackupGlobals(FALSE);
}
if ($arguments['backupStaticAttributes'] === FALSE) {
$suite->setBackupStaticAttributes(FALSE);
}
$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['colors'], $arguments['debug']);
}
}
if (!$this->printer instanceof PHPUnit_Util_Log_TAP && !self::$versionStringPrinted) {
$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['coverageClover']) || isset($arguments['reportDirectory'])) && extension_loaded('xdebug')) {
$result->collectCodeCoverageInformation(TRUE);
}
if (isset($arguments['logDbus'])) {
require_once 'PHPUnit/Util/Log/DBUS.php';
$result->addListener(new PHPUnit_Util_Log_DBUS());
}
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['junitLogfile'])) {
require_once 'PHPUnit/Util/Log/JUnit.php';
$result->addListener(new PHPUnit_Util_Log_JUnit($arguments['junitLogfile'], $arguments['logIncompleteSkipped']));
}
$suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
unset($suite);
$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 'PHP/CodeCoverage/Report/Clover.php';
$writer = new PHP_CodeCoverage_Report_Clover();
$writer->process($result->getCodeCoverage(), $arguments['coverageClover']);
$this->printer->write("\n");
unset($writer);
}
if (isset($arguments['reportDirectory'])) {
$this->printer->write("\nGenerating code coverage report, this may take a moment.");
$title = '';
//.........这里部分代码省略.........
示例4: addTestFile
/**
* Wraps both <code>addTest()</code> and <code>addTestSuite</code>
* as well as the separate import statements for the user's convenience.
*
* If the named file cannot be read or there are no new tests that can be
* added, a <code>PHPUnit_Framework_Warning</code> will be created instead,
* leaving the current test run untouched.
*
* @param string $filename
* @param array $phptOptions Array with ini settings for the php instance
* run, key being the name if the setting,
* value the ini value.
* @throws InvalidArgumentException
* @since Method available since Release 2.3.0
* @author Stefano F. Rausch <stefano@rausch-e.net>
*/
public function addTestFile($filename, $phptOptions = array())
{
if (!is_string($filename)) {
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
}
if (file_exists($filename) && substr($filename, -5) == '.phpt') {
require_once 'PHPUnit/Extensions/PhptTestCase.php';
$this->addTest(new PHPUnit_Extensions_PhptTestCase($filename, $phptOptions));
return;
}
if (!file_exists($filename)) {
$includePaths = explode(PATH_SEPARATOR, get_include_path());
foreach ($includePaths as $includePath) {
$file = $includePath . DIRECTORY_SEPARATOR . $filename;
if (file_exists($file)) {
$filename = $file;
break;
}
}
}
PHPUnit_Util_Class::collectStart();
PHPUnit_Util_Fileloader::load($filename);
$newClasses = PHPUnit_Util_Class::collectEnd();
$baseName = str_replace('.php', '', basename($filename));
foreach ($newClasses as $className) {
if (substr($className, 0 - strlen($baseName)) == $baseName) {
$newClasses = array($className);
break;
}
}
$testsFound = FALSE;
foreach ($newClasses as $className) {
$class = new ReflectionClass($className);
if (!$class->isAbstract()) {
if ($class->hasMethod(PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME)) {
$method = $class->getMethod(PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME);
if ($method->isStatic()) {
$this->addTest($method->invoke(NULL, $className));
$testsFound = TRUE;
}
} else {
if ($class->implementsInterface('PHPUnit_Framework_Test')) {
$this->addTestSuite($class);
$testsFound = TRUE;
}
}
}
}
$this->numTests = -1;
}
示例5: doRun
/**
* @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'])) {
PHPUnit_Util_Fileloader::load($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['colors'], $arguments['debug']);
}
}
if (!$this->printer instanceof PHPUnit_Util_Log_TAP) {
$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']);
//.........这里部分代码省略.........
示例6: handleArguments
/**
*/
protected static function handleArguments()
{
$arguments = array('listGroups' => FALSE, 'syntaxCheck' => TRUE);
$longOptions = array('ansi', 'colors', 'bootstrap=', 'configuration=', 'coverage-html=', 'coverage-clover=', 'coverage-source=', 'coverage-xml=', 'debug', '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'] = '';
}
if (isset($arguments['test']) && is_file($arguments['test'])) {
$arguments['testFile'] = realpath($arguments['test']);
$arguments['test'] = substr($arguments['test'], 0, strrpos($arguments['test'], '.'));
}
foreach ($options[0] as $option) {
switch ($option[0]) {
case '--ansi':
case '--colors':
$arguments['colors'] = TRUE;
break;
case '--bootstrap':
$arguments['bootstrap'] = $option[1];
PHPUnit_Util_Fileloader::load($arguments['bootstrap']);
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 '--debug':
$arguments['debug'] = TRUE;
break;
case '--help':
self::showHelp();
exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
break;
case '--filter':
$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;
//.........这里部分代码省略.........
示例7: handleArguments
/**
* Handles the command-line arguments.
*
* A child class of PHPUnit_TextUI_Command can hook into the argument
* parsing by adding the switch(es) to the $longOptions array and point to a
* callback method that handles the switch(es) in the child class like this
*
* <code>
* <?php
* class MyCommand extends PHPUnit_TextUI_Command
* {
* public function __construct()
* {
* $this->longOptions['--my-switch'] = 'myHandler';
* }
*
* // --my-switch foo -> myHandler('foo')
* protected function myHandler($value)
* {
* }
* }
* </code>
*
* @param array $argv
*/
protected function handleArguments(array $argv)
{
try {
$this->options = PHPUnit_Util_Getopt::getopt($argv, 'd:c:', array_keys($this->longOptions));
} catch (RuntimeException $e) {
PHPUnit_TextUI_TestRunner::showError($e->getMessage());
}
$skeletonClass = FALSE;
$skeletonTest = FALSE;
foreach ($this->options[0] as $option) {
switch ($option[0]) {
case '--colors':
$this->arguments['colors'] = TRUE;
break;
case '--bootstrap':
$this->arguments['bootstrap'] = $option[1];
break;
case 'c':
case '--configuration':
$this->arguments['configuration'] = $option[1];
break;
case '--coverage-clover':
if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
$this->arguments['coverageClover'] = $option[1];
} else {
if (!extension_loaded('tokenizer')) {
$this->showMessage('The tokenizer extension is not loaded.');
} else {
$this->showMessage('The Xdebug extension is not loaded.');
}
}
break;
case '--coverage-html':
if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
$this->arguments['reportDirectory'] = $option[1];
} else {
if (!extension_loaded('tokenizer')) {
$this->showMessage('The tokenizer extension is not loaded.');
} else {
$this->showMessage('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 '--debug':
$this->arguments['debug'] = TRUE;
break;
case '--help':
$this->showHelp();
exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
break;
case '--filter':
$this->arguments['filter'] = $option[1];
break;
case '--group':
$this->arguments['groups'] = explode(',', $option[1]);
break;
case '--exclude-group':
$this->arguments['excludeGroups'] = explode(',', $option[1]);
break;
case '--include-path':
$includePath = $option[1];
break;
case '--list-groups':
$this->arguments['listGroups'] = TRUE;
break;
//.........这里部分代码省略.........
示例8: load
/**
* @param string $suiteClassName
* @param string $suiteClassFile
* @return ReflectionClass
* @throws RuntimeException
*/
public function load($suiteClassName, $suiteClassFile = '')
{
$suiteClassName = str_replace('.php', '', $suiteClassName);
if (empty($suiteClassFile)) {
$suiteClassFile = PHPUnit_Util_Filesystem::classNameToFilename($suiteClassName);
}
if (!class_exists($suiteClassName, FALSE)) {
if (!file_exists($suiteClassFile)) {
$includePaths = explode(PATH_SEPARATOR, get_include_path());
foreach ($includePaths as $includePath) {
$file = $includePath . DIRECTORY_SEPARATOR . $suiteClassFile;
if (file_exists($file)) {
$suiteClassFile = $file;
break;
}
}
}
PHPUnit_Util_Class::collectStart();
PHPUnit_Util_Fileloader::load($suiteClassFile);
$loadedClasses = PHPUnit_Util_Class::collectEnd();
}
if (!class_exists($suiteClassName, FALSE) && !empty($loadedClasses)) {
$offset = 0 - strlen($suiteClassName);
foreach ($loadedClasses as $loadedClass) {
if (substr($loadedClass, $offset) === $suiteClassName) {
$suiteClassName = $loadedClass;
break;
}
}
}
if (!class_exists($suiteClassName, FALSE) && !empty($loadedClasses)) {
$testCaseClass = 'PHPUnit_Framework_TestCase';
foreach ($loadedClasses as $loadedClass) {
$class = new ReflectionClass($loadedClass);
$classFile = $class->getFileName();
if ($class->isSubclassOf($testCaseClass) && !$class->isAbstract()) {
$suiteClassName = $loadedClass;
$testCaseClass = $loadedClass;
if ($classFile == realpath($suiteClassFile)) {
break;
}
}
if ($class->hasMethod('suite')) {
$method = $class->getMethod('suite');
if (!$method->isAbstract() && $method->isPublic() && $method->isStatic()) {
$suiteClassName = $loadedClass;
if ($classFile == realpath($suiteClassFile)) {
break;
}
}
}
}
}
if (class_exists($suiteClassName, FALSE)) {
$class = new ReflectionClass($suiteClassName);
if ($class->getFileName() == realpath($suiteClassFile)) {
return $class;
}
}
throw new PHPUnit_Framework_Exception(sprintf('Class %s could not be found in %s.', $suiteClassName, $suiteClassFile));
}
示例9: main
public static function main()
{
global $isLocal;
// check number of arguments
$isLocal = !isset($_SERVER['HTTP_USER_AGENT']);
$arguments = array('listGroups' => FALSE, 'loader' => NULL, 'useDefaultConfiguration' => TRUE);
$loader = NULL;
$startPos = 1;
$canCountTest = true;
global $config_file;
if ($isLocal && $_SERVER['argv'][1] == "-config" || !$isLocal && strcmp($config_file, "") != 0 && strcmp($config_file, "/*config_xml*/") != 0) {
// check if configuration specified
$canCountTest = false;
$path = $isLocal ? $_SERVER['argv'][2] : $config_file;
//$_GET["config_xml"];
$arguments['configuration'] = $path;
$startPos = 3;
$configuration = PHPUnit_Util_Configuration::getInstance($path);
$phpunit = $configuration->getPHPUnitConfiguration();
if (isset($phpunit['testSuiteLoaderClass'])) {
if (isset($phpunit['testSuiteLoaderFile'])) {
$file = $phpunit['testSuiteLoaderFile'];
} else {
$file = '';
}
$command = new PHPUnit_TextUI_Command();
$loader = $command->handleLoader($phpunit['testSuiteLoaderClass'], $file);
$arguments['loader'] = $loader;
}
$configuration->handlePHPConfiguration();
$phpunitConfiguration = $configuration->getPHPUnitConfiguration();
if (isset($phpunitConfiguration['bootstrap'])) {
PHPUnit_Util_Fileloader::load($phpunitConfiguration['bootstrap']);
}
$browsers = $configuration->getSeleniumBrowserConfiguration();
if (!empty($browsers)) {
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers;
}
}
if ($isLocal && $_SERVER['argv'][$startPos] == "-group" || !$isLocal && isset($_GET["groups"])) {
$arguments['groups'] = explode(',', $isLocal ? $_SERVER['argv'][$startPos + 1] : $_GET["groups"]);
$startPos += 2;
}
if ($isLocal && $_SERVER['argv'][$startPos] == "-exclude-group" || !$isLocal && isset($_GET["exclude_groups"])) {
$arguments['excludeGroups'] = explode(',', $isLocal ? $_SERVER['argv'][$startPos + 1] : $_GET["exclude_groups"]);
$startPos += 2;
}
$check = $isLocal ? $_SERVER['argv'][$startPos] : $_GET["mode"];
if ($check == "c") {
$suiteClassName = $isLocal ? $_SERVER['argv'][$startPos + 1] : $_GET["class"];
$suiteClassFile = $isLocal ? $_SERVER['argv'][$startPos + 2] : $_GET["file"];
try {
// $testClass = ();
if ($loader == NULL) {
$loader = new PHPUnit_Runner_StandardTestSuiteLoader();
}
$testClass = $loader->load($suiteClassName, $suiteClassFile, FALSE);
} catch (Exception $e) {
myExceptionHandler($e);
return;
}
try {
// if class is a suite
$suiteMethod = $testClass->getMethod('suite');
if ($suiteMethod->isAbstract() || !$suiteMethod->isPublic() || !$suiteMethod->isStatic()) {
return;
}
try {
// ?? suite does not have testName argument
$test = $suiteMethod->invoke(NULL, $testClass->getName());
$test->setName($suiteClassName);
if ($canCountTest) {
print traceCommand("testCount", "count", (string) sizeof($test));
}
self::runTest($test, $suiteClassFile, $arguments);
} catch (ReflectionException $e) {
myExceptionHandler($e);
return;
}
} catch (ReflectionException $e) {
$test = new PHPUnit_Framework_TestSuite($testClass);
if ($canCountTest) {
print traceCommand("testCount", "count", (string) sizeof($test));
}
self::runTest($test, $suiteClassFile, $arguments);
}
} else {
if ($check == "d") {
// if run directory
// in remote case we put this script in the test directory
$suiteDirName = $isLocal ? $_SERVER['argv'][$startPos + 1] : dirname(__FILE__);
if (is_dir($suiteDirName) && !is_file($suiteDirName . '.php')) {
$testCollector = new PHPUnit_Runner_IncludePathTestCollector(array($suiteDirName));
// $test = new PHPUnit_Framework_TestSuite($suiteDirName);
$filenames = $testCollector->collectTests();
$number = 0;
$alltests = array();
foreach ($filenames as $filename) {
$tests = self::collectTestsFromFile($filename);
//.........这里部分代码省略.........
示例10: addTestFile
/**
* Wraps both <code>addTest()</code> and <code>addTestSuite</code>
* as well as the separate import statements for the user's convenience.
*
* If the named file cannot be read or there are no new tests that can be
* added, a <code>PHPUnit_Framework_Warning</code> will be created instead,
* leaving the current test run untouched.
*
* @param string $filename
* @param boolean $syntaxCheck
* @param array $phptOptions Array with ini settings for the php instance
* run, key being the name if the setting,
* value the ini value.
* @throws InvalidArgumentException
*/
public function addTestFile($filename, $syntaxCheck = FALSE, $phptOptions = array())
{
if (!is_string($filename)) {
throw \PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
}
// Ensure we can read the file
if (!$filename || !is_readable($filename)) {
throw new \RuntimeException(sprintf('Cannot open file "%s".' . "\n", $filename));
}
// Try to convert it to a relative path
if (strpos($filename, getcwd()) === 0) {
$filename = substr($filename, strlen(getcwd()) + 1);
} else {
if (strpos($filename, './') === 0) {
$filename = substr($filename, strlen('./'));
}
}
// Use stream wrapper for spec files
$furl = Spec::SCHEME . '://' . $filename;
// Setup the environment to collect tests
\DrSlump\Spec::reset($this);
\PHPUnit_Util_Fileloader::load($furl);
$this->numTests = -1;
}