/** * 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:hv', array_keys($this->longOptions)); } catch (PHPUnit_Framework_Exception $e) { PHPUnit_TextUI_TestRunner::showError($e->getMessage()); } 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': case '--coverage-html': case '--coverage-php': case '--coverage-text': if (!extension_loaded('tokenizer')) { $this->showExtensionNotLoadedMessage('tokenizer', 'No code coverage will be generated.'); continue; } if (!extension_loaded('xdebug')) { $this->showExtensionNotLoadedMessage('Xdebug', 'No code coverage will be generated.'); continue; } switch ($option[0]) { case '--coverage-clover': $this->arguments['coverageClover'] = $option[1]; break; case '--coverage-html': $this->arguments['reportDirectory'] = $option[1]; break; case '--coverage-php': $this->arguments['coveragePHP'] = $option[1]; break; case '--coverage-text': if ($option[1] === NULL) { $option[1] = 'php://stdout'; } $this->arguments['coverageText'] = $option[1]; $this->arguments['coverageTextShowUncoveredFiles'] = FALSE; break; } 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 'h': 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; case '--printer': $this->arguments['printer'] = $option[1]; break; case '--loader': $this->arguments['loader'] = $option[1]; break; case '--log-json': $this->arguments['jsonLogfile'] = $option[1]; break; case '--log-junit': $this->arguments['junitLogfile'] = $option[1]; break; case '--log-tap': $this->arguments['tapLogfile'] = $option[1]; break; case '--process-isolation': $this->arguments['processIsolation'] = TRUE; break; case '--repeat': $this->arguments['repeat'] = (int) $option[1]; break; case '--stderr': $this->arguments['printer'] = new PHPUnit_TextUI_ResultPrinter('php://stderr', isset($this->arguments['verbose']) ? $this->arguments['verbose'] : FALSE); break; case '--stop-on-error': $this->arguments['stopOnError'] = TRUE; break; case '--stop-on-failure': $this->arguments['stopOnFailure'] = TRUE; break; case '--stop-on-incomplete': $this->arguments['stopOnIncomplete'] = TRUE; break; case '--stop-on-skipped': $this->arguments['stopOnSkipped'] = TRUE; break; case '--tap': $this->arguments['printer'] = new PHPUnit_Util_Log_TAP(); break; case '--testdox': $this->arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text(); break; case '--testdox-html': $this->arguments['testdoxHTMLFile'] = $option[1]; break; case '--testdox-text': $this->arguments['testdoxTextFile'] = $option[1]; break; case '--no-configuration': $this->arguments['useDefaultConfiguration'] = FALSE; break; case '--no-globals-backup': $this->arguments['backupGlobals'] = FALSE; break; case '--static-backup': $this->arguments['backupStaticAttributes'] = TRUE; break; case 'v': case '--verbose': $this->arguments['verbose'] = TRUE; break; case '--version': PHPUnit_TextUI_TestRunner::printVersionString(); exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); break; case '--strict': $this->arguments['strict'] = TRUE; break; default: $optionName = str_replace('--', '', $option[0]); if (isset($this->longOptions[$optionName])) { $handler = $this->longOptions[$optionName]; } else { if (isset($this->longOptions[$optionName . '='])) { $handler = $this->longOptions[$optionName . '=']; } } if (isset($handler) && is_callable(array($this, $handler))) { $this->{$handler}($option[1]); } } } $this->handleCustomTestSuite(); if (!isset($this->arguments['test'])) { if (count($this->options[1]) > 2) { $this->showMessage('More than two positional arguments provided.', FALSE); $this->showHelp(); exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } if (isset($this->options[1][0])) { $this->arguments['test'] = $this->options[1][0]; } if (isset($this->options[1][1])) { $this->arguments['testFile'] = $this->options[1][1]; } else { $this->arguments['testFile'] = ''; } if (isset($this->arguments['test']) && is_file($this->arguments['test']) && substr($this->arguments['test'], -5, 5) != '.phpt') { $this->arguments['testFile'] = realpath($this->arguments['test']); $this->arguments['test'] = substr($this->arguments['test'], 0, strrpos($this->arguments['test'], '.')); } } if (isset($includePath)) { ini_set('include_path', $includePath . PATH_SEPARATOR . ini_get('include_path')); } if (isset($this->arguments['bootstrap'])) { $this->handleBootstrap($this->arguments['bootstrap']); } if (isset($this->arguments['printer']) && is_string($this->arguments['printer'])) { $this->arguments['printer'] = $this->handlePrinter($this->arguments['printer']); } if ($this->arguments['loader'] !== NULL) { $this->arguments['loader'] = $this->handleLoader($this->arguments['loader']); } if (isset($this->arguments['configuration']) && is_dir($this->arguments['configuration'])) { $configurationFile = $this->arguments['configuration'] . '/phpunit.xml'; if (file_exists($configurationFile)) { $this->arguments['configuration'] = realpath($configurationFile); } else { if (file_exists($configurationFile . '.dist')) { $this->arguments['configuration'] = realpath($configurationFile . '.dist'); } } } else { if (!isset($this->arguments['configuration']) && $this->arguments['useDefaultConfiguration']) { if (file_exists('phpunit.xml')) { $this->arguments['configuration'] = realpath('phpunit.xml'); } else { if (file_exists('phpunit.xml.dist')) { $this->arguments['configuration'] = realpath('phpunit.xml.dist'); } } } } if (isset($this->arguments['configuration'])) { try { $configuration = PHPUnit_Util_Configuration::getInstance($this->arguments['configuration']); } catch (Exception $e) { print $e->getMessage() . "\n"; exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } $phpunit = $configuration->getPHPUnitConfiguration(); $configuration->handlePHPConfiguration(); if (!isset($this->arguments['bootstrap']) && isset($phpunit['bootstrap'])) { $this->handleBootstrap($phpunit['bootstrap']); } if (isset($phpunit['printerClass'])) { if (isset($phpunit['printerFile'])) { $file = $phpunit['printerFile']; } else { $file = ''; } $this->arguments['printer'] = $this->handlePrinter($phpunit['printerClass'], $file); } if (isset($phpunit['testSuiteLoaderClass'])) { if (isset($phpunit['testSuiteLoaderFile'])) { $file = $phpunit['testSuiteLoaderFile']; } else { $file = ''; } $this->arguments['loader'] = $this->handleLoader($phpunit['testSuiteLoaderClass'], $file); } $logging = $configuration->getLoggingConfiguration(); if (isset($logging['coverage-html']) || isset($logging['coverage-clover']) || isset($logging['coverage-text'])) { if (!extension_loaded('tokenizer')) { $this->showExtensionNotLoadedMessage('tokenizer', 'No code coverage will be generated.'); } else { if (!extension_loaded('Xdebug')) { $this->showExtensionNotLoadedMessage('Xdebug', 'No code coverage will be generated.'); } } } $browsers = $configuration->getSeleniumBrowserConfiguration(); if (!empty($browsers) && class_exists('PHPUnit_Extensions_SeleniumTestCase')) { PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers; } if (!isset($this->arguments['test'])) { $testSuite = $configuration->getTestSuiteConfiguration(); if ($testSuite !== NULL) { $this->arguments['test'] = $testSuite; } } } if (isset($this->arguments['test']) && is_string($this->arguments['test']) && substr($this->arguments['test'], -5, 5) == '.phpt') { $test = new PHPUnit_Extensions_PhptTestCase($this->arguments['test']); $this->arguments['test'] = new PHPUnit_Framework_TestSuite(); $this->arguments['test']->addTest($test); } if (!isset($this->arguments['test']) || isset($this->arguments['testDatabaseLogRevision']) && !isset($this->arguments['testDatabaseDSN'])) { $this->showHelp(); exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); } }
/** * 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); 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; case '--loader': $this->arguments['loader'] = $option[1]; break; case '--log-json': $this->arguments['jsonLogfile'] = $option[1]; break; case '--log-xml': $this->showMessage('The --log-xml option is deprecated, please use ' . '--log-junit instead.', FALSE); case '--log-junit': $this->arguments['junitLogfile'] = $option[1]; break; case '--log-graphviz': $this->showMessage('The --log-graphviz functionality is deprecated and ' . 'will be removed in the future.', FALSE); if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) { $this->arguments['graphvizLogfile'] = $option[1]; } else { $this->showMessage('The Image_GraphViz package is not installed.'); } break; case '--log-tap': $this->arguments['tapLogfile'] = $option[1]; break; case '--log-pmd': $this->showMessage('The --log-pmd functionality is deprecated and will be ' . 'removed in the future.', FALSE); if (extension_loaded('tokenizer') && extension_loaded('xdebug')) { $this->arguments['pmdXML'] = $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 '--log-metrics': $this->showMessage('The --log-metrics functionality is deprecated and ' . 'will be removed in the future.', FALSE); if (extension_loaded('tokenizer') && extension_loaded('xdebug')) { $this->arguments['metricsXML'] = $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 '--process-isolation': $this->arguments['processIsolation'] = TRUE; $this->arguments['syntaxCheck'] = FALSE; break; case '--repeat': $this->showMessage('The --repeat functionality is deprecated and will be ' . 'removed in the future.', FALSE); $this->arguments['repeat'] = (int) $option[1]; break; case '--stderr': $this->arguments['printer'] = new PHPUnit_TextUI_ResultPrinter('php://stderr', isset($this->arguments['verbose']) ? $this->arguments['verbose'] : FALSE); break; case '--stop-on-failure': $this->arguments['stopOnFailure'] = TRUE; break; case '--test-db-dsn': $this->showMessage('The test database functionality is deprecated and ' . 'will be removed in the future.', FALSE); if (extension_loaded('pdo')) { $this->arguments['testDatabaseDSN'] = $option[1]; } else { $this->showMessage('The PDO extension is not loaded.'); } break; case '--test-db-log-rev': if (extension_loaded('pdo')) { $this->arguments['testDatabaseLogRevision'] = $option[1]; } else { $this->showMessage('The PDO extension is not loaded.'); } break; case '--test-db-prefix': if (extension_loaded('pdo')) { $this->arguments['testDatabasePrefix'] = $option[1]; } else { $this->showMessage('The PDO extension is not loaded.'); } break; case '--test-db-log-info': if (extension_loaded('pdo')) { $this->arguments['testDatabaseLogInfo'] = $option[1]; } else { $this->showMessage('The PDO extension is not loaded.'); } break; case '--skeleton': $this->showMessage('The --skeleton option is deprecated, please use ' . '--skeleton-test instead.', FALSE); case '--skeleton-test': $skeletonTest = TRUE; $skeletonClass = FALSE; break; case '--skeleton-class': $skeletonClass = TRUE; $skeletonTest = FALSE; break; case '--tap': require_once PATH_TO_ROOT . '/test/PHPUnit/Util/Log/TAP.php'; $this->arguments['printer'] = new PHPUnit_Util_Log_TAP(); break; case '--story': require_once PATH_TO_ROOT . '/test/PHPUnit/Extensions/Story/ResultPrinter/Text.php'; $this->arguments['printer'] = new PHPUnit_Extensions_Story_ResultPrinter_Text(); break; case '--story-html': $this->arguments['storyHTMLFile'] = $option[1]; break; case '--story-text': $this->arguments['storyTextFile'] = $option[1]; break; case '--syntax-check': $this->arguments['syntaxCheck'] = TRUE; break; case '--testdox': require_once PATH_TO_ROOT . '/test/PHPUnit/Util/TestDox/ResultPrinter/Text.php'; $this->arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text(); break; case '--testdox-html': $this->arguments['testdoxHTMLFile'] = $option[1]; break; case '--testdox-text': $this->arguments['testdoxTextFile'] = $option[1]; break; case '--no-configuration': $this->arguments['useDefaultConfiguration'] = FALSE; break; case '--no-globals-backup': $this->arguments['backupGlobals'] = FALSE; break; case '--static-backup': $this->arguments['backupStaticAttributes'] = TRUE; break; case '--verbose': $this->arguments['verbose'] = TRUE; break; case '--version': PHPUnit_TextUI_TestRunner::printVersionString(); exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); break; case '--wait': $this->arguments['wait'] = TRUE; break; default: $optionName = str_replace('--', '', $option[0]); if (isset($this->longOptions[$optionName])) { $handler = $this->longOptions[$optionName]; } else { if (isset($this->longOptions[$optionName . '='])) { $handler = $this->longOptions[$optionName . '=']; } } if (isset($handler) && is_callable(array($this, $handler))) { $this->{$handler}($option[1]); } } } if (isset($this->arguments['printer']) && $this->arguments['printer'] instanceof PHPUnit_Extensions_Story_ResultPrinter_Text && isset($this->arguments['processIsolation']) && $this->arguments['processIsolation']) { $this->showMessage('The story result printer cannot be used in process isolation.'); } $this->handleCustomTestSuite(); if (!isset($this->arguments['test'])) { if (isset($this->options[1][0])) { $this->arguments['test'] = $this->options[1][0]; } if (isset($this->options[1][1])) { $this->arguments['testFile'] = $this->options[1][1]; } else { $this->arguments['testFile'] = ''; } if (isset($this->arguments['test']) && is_file($this->arguments['test'])) { $this->arguments['testFile'] = realpath($this->arguments['test']); $this->arguments['test'] = substr($this->arguments['test'], 0, strrpos($this->arguments['test'], '.')); } } if (isset($includePath)) { ini_set('include_path', $includePath . PATH_SEPARATOR . ini_get('include_path')); } if (isset($this->arguments['bootstrap'])) { PHPUnit_Util_Fileloader::load($this->arguments['bootstrap']); } if ($this->arguments['loader'] !== NULL) { $this->arguments['loader'] = $this->handleLoader($this->arguments['loader']); } if (!isset($this->arguments['configuration']) && $this->arguments['useDefaultConfiguration']) { if (file_exists('phpunit.xml')) { $this->arguments['configuration'] = realpath('phpunit.xml'); } else { if (file_exists('phpunit.xml.dist')) { $this->arguments['configuration'] = realpath('phpunit.xml.dist'); } } } if (isset($this->arguments['configuration'])) { $configuration = PHPUnit_Util_Configuration::getInstance($this->arguments['configuration']); $phpunit = $configuration->getPHPUnitConfiguration(); if (isset($phpunit['syntaxCheck'])) { $this->arguments['syntaxCheck'] = $phpunit['syntaxCheck']; } if (isset($phpunit['testSuiteLoaderClass'])) { if (isset($phpunit['testSuiteLoaderFile'])) { $file = $phpunit['testSuiteLoaderFile']; } else { $file = ''; } $this->arguments['loader'] = $this->handleLoader($phpunit['testSuiteLoaderClass'], $file); } $configuration->handlePHPConfiguration(); if (!isset($this->arguments['bootstrap'])) { $phpunitConfiguration = $configuration->getPHPUnitConfiguration(); if (isset($phpunitConfiguration['bootstrap'])) { PHPUnit_Util_Fileloader::load($phpunitConfiguration['bootstrap']); } } $browsers = $configuration->getSeleniumBrowserConfiguration(); if (!empty($browsers)) { require_once PATH_TO_ROOT . '/test/PHPUnit/Extensions/SeleniumTestCase.php'; PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers; } if (!isset($this->arguments['test'])) { $testSuite = $configuration->getTestSuiteConfiguration($this->arguments['syntaxCheck']); if ($testSuite !== NULL) { $this->arguments['test'] = $testSuite; } } } if (isset($this->arguments['test']) && is_string($this->arguments['test']) && substr($this->arguments['test'], -5, 5) == '.phpt') { require_once PATH_TO_ROOT . '/test/PHPUnit/Extensions/PhptTestCase.php'; $test = new PHPUnit_Extensions_PhptTestCase($this->arguments['test']); $this->arguments['test'] = new PHPUnit_Framework_TestSuite(); $this->arguments['test']->addTest($test); } if (!isset($this->arguments['test']) || isset($this->arguments['testDatabaseLogRevision']) && !isset($this->arguments['testDatabaseDSN'])) { $this->showHelp(); exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); } if (!isset($this->arguments['syntaxCheck'])) { $this->arguments['syntaxCheck'] = FALSE; } if ($skeletonClass || $skeletonTest) { if (isset($this->arguments['test']) && $this->arguments['test'] !== FALSE) { PHPUnit_TextUI_TestRunner::printVersionString(); if ($skeletonClass) { require_once PATH_TO_ROOT . '/test/PHPUnit/Util/Skeleton/Class.php'; $class = 'PHPUnit_Util_Skeleton_Class'; } else { require_once PATH_TO_ROOT . '/test/PHPUnit/Util/Skeleton/Test.php'; $class = 'PHPUnit_Util_Skeleton_Test'; } try { $args = array(); $reflector = new ReflectionClass($class); for ($i = 0; $i <= 3; $i++) { if (isset($this->options[1][$i])) { $args[] = $this->options[1][$i]; } } $skeleton = $reflector->newInstanceArgs($args); $skeleton->write(); } catch (Exception $e) { print $e->getMessage() . "\n"; 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 { $this->showHelp(); exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); } } }
/** * Load and processes the PHPUnit configuration * * @param $configuration * * @throws BuildException * @return array */ protected function handlePHPUnitConfiguration($configuration) { if (!$configuration->exists()) { throw new BuildException("Unable to find PHPUnit configuration file '" . (string) $configuration . "'"); } $config = PHPUnit_Util_Configuration::getInstance($configuration->getAbsolutePath()); if (empty($config)) { return; } $phpunit = $config->getPHPUnitConfiguration(); if (empty($phpunit)) { return; } $config->handlePHPConfiguration(); if (isset($phpunit['bootstrap'])) { $this->setBootstrap($phpunit['bootstrap']); } if (isset($phpunit['stopOnFailure'])) { $this->setHaltonfailure($phpunit['stopOnFailure']); } if (isset($phpunit['stopOnError'])) { $this->setHaltonerror($phpunit['stopOnError']); } if (isset($phpunit['stopOnSkipped'])) { $this->setHaltonskipped($phpunit['stopOnSkipped']); } if (isset($phpunit['stopOnIncomplete'])) { $this->setHaltonincomplete($phpunit['stopOnIncomplete']); } if (isset($phpunit['processIsolation'])) { $this->setProcessIsolation($phpunit['processIsolation']); } foreach ($config->getListenerConfiguration() as $listener) { if (!class_exists($listener['class'], false) && $listener['file'] !== '') { require_once $listener['file']; } if (class_exists($listener['class'])) { if (count($listener['arguments']) == 0) { $listener = new $listener['class'](); } else { $listenerClass = new ReflectionClass($listener['class']); $listener = $listenerClass->newInstanceArgs($listener['arguments']); } if ($listener instanceof PHPUnit_Framework_TestListener) { $this->addListener($listener); } } } $browsers = $config->getSeleniumBrowserConfiguration(); if (!empty($browsers) && class_exists('PHPUnit_Extensions_SeleniumTestCase')) { PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers; } return $phpunit; }
/** * This function is cut&paste from PHPUnit_TextUI_Command::handleArguments * Removed the need for a required unnamed command option ( 'test') **/ 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; case '--loader': { $this->arguments['loader'] = $option[1]; } break; case '--log-dbus': { $this->arguments['logDbus'] = TRUE; } break; case '--log-json': { $this->arguments['jsonLogfile'] = $option[1]; } break; case '--log-junit': { $this->arguments['junitLogfile'] = $option[1]; } break; case '--log-tap': { $this->arguments['tapLogfile'] = $option[1]; } break; case '--process-isolation': { $this->arguments['processIsolation'] = TRUE; $this->arguments['syntaxCheck'] = FALSE; } break; case '--repeat': { $this->arguments['repeat'] = (int)$option[1]; } break; case '--stderr': { $this->arguments['printer'] = new PHPUnit_TextUI_ResultPrinter( 'php://stderr', isset($this->arguments['verbose']) ? $this->arguments['verbose'] : FALSE ); } break; case '--stop-on-error': { $this->arguments['stopOnError'] = TRUE; } break; case '--stop-on-failure': { $this->arguments['stopOnFailure'] = TRUE; } break; case '--stop-on-incomplete': { $this->arguments['stopOnIncomplete'] = TRUE; } break; case '--stop-on-skipped': { $this->arguments['stopOnSkipped'] = TRUE; } break; case '--skeleton-test': { $skeletonTest = TRUE; $skeletonClass = FALSE; } break; case '--skeleton-class': { $skeletonClass = TRUE; $skeletonTest = FALSE; } break; case '--tap': { $this->arguments['printer'] = new PHPUnit_Util_Log_TAP; } break; case '--story': { $this->showMessage( 'The --story functionality is deprecated and ' . 'will be removed in the future.', FALSE ); $this->arguments['printer'] = new PHPUnit_Extensions_Story_ResultPrinter_Text; } break; case '--story-html': { $this->showMessage( 'The --story-html functionality is deprecated and ' . 'will be removed in the future.', FALSE ); $this->arguments['storyHTMLFile'] = $option[1]; } break; case '--story-text': { $this->showMessage( 'The --story-text functionality is deprecated and ' . 'will be removed in the future.', FALSE ); $this->arguments['storyTextFile'] = $option[1]; } break; case '--syntax-check': { $this->arguments['syntaxCheck'] = TRUE; } break; case '--testdox': { $this->arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text; } break; case '--testdox-html': { $this->arguments['testdoxHTMLFile'] = $option[1]; } break; case '--testdox-text': { $this->arguments['testdoxTextFile'] = $option[1]; } break; case '--no-configuration': { $this->arguments['useDefaultConfiguration'] = FALSE; } break; case '--no-globals-backup': { $this->arguments['backupGlobals'] = FALSE; } break; case '--static-backup': { $this->arguments['backupStaticAttributes'] = TRUE; } break; case '--verbose': { $this->arguments['verbose'] = TRUE; } break; case '--version': { PHPUnit_TextUI_TestRunner::printVersionString(); exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); } break; case '--wait': { $this->arguments['wait'] = TRUE; } break; case '--strict': { $this->arguments['strict'] = TRUE; } break; default: { $optionName = str_replace('--', '', $option[0]); if (isset($this->longOptions[$optionName])) { $handler = $this->longOptions[$optionName]; } else if (isset($this->longOptions[$optionName . '='])) { $handler = $this->longOptions[$optionName . '=']; } if (isset($handler) && is_callable(array($this, $handler))) { $this->$handler($option[1]); } } } } if (isset($this->arguments['printer']) && $this->arguments['printer'] instanceof PHPUnit_Extensions_Story_ResultPrinter_Text && isset($this->arguments['processIsolation']) && $this->arguments['processIsolation']) { $this->showMessage( 'The story result printer cannot be used in process isolation.' ); } $this->handleCustomTestSuite(); if (!isset($this->arguments['test'])) { if (isset($this->options[1][0])) { $this->arguments['test'] = $this->options[1][0]; } if (isset($this->options[1][1])) { $this->arguments['testFile'] = $this->options[1][1]; } else { $this->arguments['testFile'] = ''; } if (isset($this->arguments['test']) && is_file($this->arguments['test'])) { $this->arguments['testFile'] = realpath($this->arguments['test']); $this->arguments['test'] = substr($this->arguments['test'], 0, strrpos($this->arguments['test'], '.')); } } if (isset($includePath)) { ini_set( 'include_path', $includePath . PATH_SEPARATOR . ini_get('include_path') ); } if (isset($this->arguments['bootstrap'])) { $this->handleBootstrap($this->arguments['bootstrap'], $this->arguments['syntaxCheck']); } if ($this->arguments['loader'] !== NULL) { $this->arguments['loader'] = $this->handleLoader($this->arguments['loader']); } if (isset($this->arguments['configuration']) && is_dir($this->arguments['configuration'])) { $configurationFile = $this->arguments['configuration'] . '/phpunit.xml'; if (file_exists($configurationFile)) { $this->arguments['configuration'] = realpath( $configurationFile ); } else if (file_exists($configurationFile . '.dist')) { $this->arguments['configuration'] = realpath( $configurationFile . '.dist' ); } } else if (!isset($this->arguments['configuration']) && $this->arguments['useDefaultConfiguration']) { if (file_exists('phpunit.xml')) { $this->arguments['configuration'] = realpath('phpunit.xml'); } else if (file_exists('phpunit.xml.dist')) { $this->arguments['configuration'] = realpath( 'phpunit.xml.dist' ); } } if (isset($this->arguments['configuration'])) { try { $configuration = PHPUnit_Util_Configuration::getInstance( $this->arguments['configuration'] ); } catch (Exception $e) { print $e->getMessage() . "\n"; exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } $phpunit = $configuration->getPHPUnitConfiguration(); if (isset($phpunit['syntaxCheck'])) { $this->arguments['syntaxCheck'] = $phpunit['syntaxCheck']; } if (isset($phpunit['testSuiteLoaderClass'])) { if (isset($phpunit['testSuiteLoaderFile'])) { $file = $phpunit['testSuiteLoaderFile']; } else { $file = ''; } $this->arguments['loader'] = $this->handleLoader( $phpunit['testSuiteLoaderClass'], $file ); } $configuration->handlePHPConfiguration(); if (!isset($this->arguments['bootstrap'])) { $phpunitConfiguration = $configuration->getPHPUnitConfiguration(); if (isset($phpunitConfiguration['bootstrap'])) { $this->handleBootstrap($phpunitConfiguration['bootstrap'], $this->arguments['syntaxCheck']); } } $browsers = $configuration->getSeleniumBrowserConfiguration(); if (!empty($browsers)) { PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers; } if (!isset($this->arguments['test'])) { $testSuite = $configuration->getTestSuiteConfiguration( $this->arguments['syntaxCheck'] ); if ($testSuite !== NULL) { $this->arguments['test'] = $testSuite; } } } if (isset($this->arguments['test']) && is_string($this->arguments['test']) && substr($this->arguments['test'], -5, 5) == '.phpt') { $test = new PHPUnit_Extensions_PhptTestCase($this->arguments['test']); $this->arguments['test'] = new PHPUnit_Framework_TestSuite; $this->arguments['test']->addTest($test); } // *** BEGIN ezp custom code BEGIN *** // Commented out this stuff /* if (!isset($this->arguments['test']) || (isset($this->arguments['testDatabaseLogRevision']) && !isset($this->arguments['testDatabaseDSN']))) { $this->showHelp(); exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); }*/ // *** END ezp custom code END *** if (!isset($this->arguments['syntaxCheck'])) { $this->arguments['syntaxCheck'] = FALSE; } if ($skeletonClass || $skeletonTest) { if (isset($this->arguments['test']) && $this->arguments['test'] !== FALSE) { PHPUnit_TextUI_TestRunner::printVersionString(); if ($skeletonClass) { $class = 'PHPUnit_Util_Skeleton_Class'; } else { $class = 'PHPUnit_Util_Skeleton_Test'; } try { $args = array(); $reflector = new ReflectionClass($class); for ($i = 0; $i <= 3; $i++) { if (isset($this->options[1][$i])) { $args[] = $this->options[1][$i]; } } $skeleton = $reflector->newInstanceArgs($args); $skeleton->write(); } catch (Exception $e) { print $e->getMessage() . "\n"; 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 { $this->showHelp(); exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); } } }
/** * @param array $arguments * @since Method available since Release 3.2.1 */ protected function handleConfiguration(array &$arguments) { if (isset($arguments['configuration'])) { $arguments['configuration'] = new PHPUnit_Util_Configuration($arguments['configuration']); $arguments['pmd'] = $arguments['configuration']->getPMDConfiguration(); } else { $arguments['pmd'] = array(); } $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']); } 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']); } 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']); } 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']); } foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) { PHPUnit_Util_Filter::removeFileFromWhitelist($file); } $phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration(); if (isset($phpunitConfiguration['ansi']) && !isset($arguments['ansi'])) { $arguments['ansi'] = $phpunitConfiguration['ansi']; } 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['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']; } $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['test-xml']) && !isset($arguments['xmlLogfile'])) { $arguments['xmlLogfile'] = $loggingConfiguration['test-xml']; 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']; } $browsers = $arguments['configuration']->getSeleniumBrowserConfiguration(); if (!empty($browsers)) { require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers; } } $arguments['cpdMinLines'] = isset($arguments['cpdMinLines']) ? $arguments['cpdMinLines'] : 5; $arguments['cpdMinMatches'] = isset($arguments['cpdMinMatches']) ? $arguments['cpdMinMatches'] : 70; $arguments['ansi'] = isset($arguments['ansi']) ? $arguments['ansi'] : 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['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; }
/** * 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() * { * // my-switch won't accept a value, it's an on/off * $this->longOptions['my-switch'] = 'myHandler'; * // my-secondswitch will accept a value - note the equals sign * $this->longOptions['my-secondswitch='] = 'myOtherHandler'; * } * * // --my-switch -> myHandler() * protected function myHandler() * { * } * * // --my-secondswitch foo -> myOtherHandler('foo') * protected function myOtherHandler ($value) * { * } * * // You will also need this - the static keyword in the * // PHPUnit_TextUI_Command will mean that it'll be * // PHPUnit_TextUI_Command that gets instantiated, * // not MyCommand * public static function main($exit = true) * { * $command = new static; * * return $command->run($_SERVER['argv'], $exit); * } * * } * </code> * * @param array $argv */ protected function handleArguments(array $argv) { if (defined('__PHPUNIT_PHAR__')) { $this->longOptions['selfupdate'] = null; $this->longOptions['self-update'] = null; } try { $this->options = PHPUnit_Util_Getopt::getopt($argv, 'd:c:hv', array_keys($this->longOptions)); } catch (PHPUnit_Framework_Exception $e) { $this->showError($e->getMessage()); } 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 '--columns': if (is_numeric($option[1])) { $this->arguments['columns'] = (int) $option[1]; } elseif ($option[1] == 'max') { $this->arguments['columns'] = 'max'; } break; case 'c': case '--configuration': $this->arguments['configuration'] = $option[1]; break; case '--coverage-clover': $this->arguments['coverageClover'] = $option[1]; break; case '--coverage-crap4j': $this->arguments['coverageCrap4J'] = $option[1]; break; case '--coverage-html': $this->arguments['coverageHtml'] = $option[1]; break; case '--coverage-php': $this->arguments['coveragePHP'] = $option[1]; break; case '--coverage-text': if ($option[1] === null) { $option[1] = 'php://stdout'; } $this->arguments['coverageText'] = $option[1]; $this->arguments['coverageTextShowUncoveredFiles'] = false; $this->arguments['coverageTextShowOnlySummary'] = false; break; case '--coverage-xml': $this->arguments['coverageXml'] = $option[1]; 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 'h': case '--help': $this->showHelp(); exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); break; case '--filter': $this->arguments['filter'] = $option[1]; break; case '--testsuite': $this->arguments['testsuite'] = $option[1]; break; case '--group': $this->arguments['groups'] = explode(',', $option[1]); break; case '--exclude-group': $this->arguments['excludeGroups'] = explode(',', $option[1]); break; case '--test-suffix': $this->arguments['testSuffixes'] = explode(',', $option[1]); break; case '--include-path': $includePath = $option[1]; break; case '--list-groups': $this->arguments['listGroups'] = true; break; case '--printer': $this->arguments['printer'] = $option[1]; break; case '--loader': $this->arguments['loader'] = $option[1]; break; case '--log-json': $this->arguments['jsonLogfile'] = $option[1]; break; case '--log-junit': $this->arguments['junitLogfile'] = $option[1]; break; case '--log-tap': $this->arguments['tapLogfile'] = $option[1]; break; case '--process-isolation': $this->arguments['processIsolation'] = true; break; case '--repeat': $this->arguments['repeat'] = (int) $option[1]; break; case '--stderr': $this->arguments['stderr'] = true; break; case '--stop-on-error': $this->arguments['stopOnError'] = true; break; case '--stop-on-failure': $this->arguments['stopOnFailure'] = true; break; case '--stop-on-incomplete': $this->arguments['stopOnIncomplete'] = true; break; case '--stop-on-risky': $this->arguments['stopOnRisky'] = true; break; case '--stop-on-skipped': $this->arguments['stopOnSkipped'] = true; break; case '--tap': $this->arguments['printer'] = 'PHPUnit_Util_Log_TAP'; break; case '--testdox': $this->arguments['printer'] = 'PHPUnit_Util_TestDox_ResultPrinter_Text'; break; case '--testdox-html': $this->arguments['testdoxHTMLFile'] = $option[1]; break; case '--testdox-text': $this->arguments['testdoxTextFile'] = $option[1]; break; case '--no-configuration': $this->arguments['useDefaultConfiguration'] = false; break; case '--no-globals-backup': $this->arguments['backupGlobals'] = false; break; case '--static-backup': $this->arguments['backupStaticAttributes'] = true; break; case 'v': case '--verbose': $this->arguments['verbose'] = true; break; case '--version': $this->printVersionString(); exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); break; case '--report-useless-tests': $this->arguments['reportUselessTests'] = true; break; case '--strict-coverage': $this->arguments['strictCoverage'] = true; break; case '--disallow-test-output': $this->arguments['disallowTestOutput'] = true; break; case '--enforce-time-limit': $this->arguments['enforceTimeLimit'] = true; break; case '--disallow-todo-tests': $this->arguments['disallowTodoAnnotatedTests'] = true; break; case '--strict': $this->arguments['reportUselessTests'] = true; $this->arguments['strictCoverage'] = true; $this->arguments['disallowTestOutput'] = true; $this->arguments['enforceTimeLimit'] = true; $this->arguments['disallowTodoAnnotatedTests'] = true; $this->arguments['deprecatedStrictModeOption'] = true; break; case '--selfupdate': case '--self-update': $this->handleSelfUpdate(); break; default: $optionName = str_replace('--', '', $option[0]); if (isset($this->longOptions[$optionName])) { $handler = $this->longOptions[$optionName]; } elseif (isset($this->longOptions[$optionName . '='])) { $handler = $this->longOptions[$optionName . '=']; } if (isset($handler) && is_callable(array($this, $handler))) { $this->{$handler}($option[1]); } } } $this->handleCustomTestSuite(); if (!isset($this->arguments['test'])) { if (isset($this->options[1][0])) { $this->arguments['test'] = $this->options[1][0]; } if (isset($this->options[1][1])) { $this->arguments['testFile'] = realpath($this->options[1][1]); } else { $this->arguments['testFile'] = ''; } if (isset($this->arguments['test']) && is_file($this->arguments['test']) && substr($this->arguments['test'], -5, 5) != '.phpt') { $this->arguments['testFile'] = realpath($this->arguments['test']); $this->arguments['test'] = substr($this->arguments['test'], 0, strrpos($this->arguments['test'], '.')); } } if (!isset($this->arguments['testSuffixes'])) { $this->arguments['testSuffixes'] = array('Test.php', '.phpt'); } if (isset($includePath)) { ini_set('include_path', $includePath . PATH_SEPARATOR . ini_get('include_path')); } if ($this->arguments['loader'] !== null) { $this->arguments['loader'] = $this->handleLoader($this->arguments['loader']); } if (isset($this->arguments['configuration']) && is_dir($this->arguments['configuration'])) { $configurationFile = $this->arguments['configuration'] . '/phpunit.xml'; if (file_exists($configurationFile)) { $this->arguments['configuration'] = realpath($configurationFile); } elseif (file_exists($configurationFile . '.dist')) { $this->arguments['configuration'] = realpath($configurationFile . '.dist'); } } elseif (!isset($this->arguments['configuration']) && $this->arguments['useDefaultConfiguration']) { if (file_exists('phpunit.xml')) { $this->arguments['configuration'] = realpath('phpunit.xml'); } elseif (file_exists('phpunit.xml.dist')) { $this->arguments['configuration'] = realpath('phpunit.xml.dist'); } } if (isset($this->arguments['configuration'])) { try { $configuration = PHPUnit_Util_Configuration::getInstance($this->arguments['configuration']); } catch (Exception $e) { print $e->getMessage() . "\n"; exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } $phpunit = $configuration->getPHPUnitConfiguration(); $configuration->handlePHPConfiguration(); /** * Issue #1216 */ if (isset($this->arguments['bootstrap'])) { $this->handleBootstrap($this->arguments['bootstrap']); } elseif (isset($phpunit['bootstrap'])) { $this->handleBootstrap($phpunit['bootstrap']); } /** * Issue #657 */ if (isset($phpunit['stderr']) && !isset($this->arguments['stderr'])) { $this->arguments['stderr'] = $phpunit['stderr']; } if (isset($phpunit['printerClass'])) { if (isset($phpunit['printerFile'])) { $file = $phpunit['printerFile']; } else { $file = ''; } $this->arguments['printer'] = $this->handlePrinter($phpunit['printerClass'], $file); } if (isset($phpunit['testSuiteLoaderClass'])) { if (isset($phpunit['testSuiteLoaderFile'])) { $file = $phpunit['testSuiteLoaderFile']; } else { $file = ''; } $this->arguments['loader'] = $this->handleLoader($phpunit['testSuiteLoaderClass'], $file); } $browsers = $configuration->getSeleniumBrowserConfiguration(); if (!empty($browsers) && class_exists('PHPUnit_Extensions_SeleniumTestCase')) { PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers; } if (!isset($this->arguments['test'])) { $testSuite = $configuration->getTestSuiteConfiguration(isset($this->arguments['testsuite']) ? $this->arguments['testsuite'] : null); if ($testSuite !== null) { $this->arguments['test'] = $testSuite; } } } elseif (isset($this->arguments['bootstrap'])) { $this->handleBootstrap($this->arguments['bootstrap']); } if (isset($this->arguments['printer']) && is_string($this->arguments['printer'])) { $this->arguments['printer'] = $this->handlePrinter($this->arguments['printer']); } if (isset($this->arguments['test']) && is_string($this->arguments['test']) && substr($this->arguments['test'], -5, 5) == '.phpt') { $test = new PHPUnit_Extensions_PhptTestCase($this->arguments['test']); $this->arguments['test'] = new PHPUnit_Framework_TestSuite(); $this->arguments['test']->addTest($test); } if (!isset($this->arguments['test']) || isset($this->arguments['testDatabaseLogRevision']) && !isset($this->arguments['testDatabaseDSN'])) { $this->showHelp(); exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); } }
/** * Load and processes the PHPUnit configuration * @param $configuration * @throws BuildException * @return array */ protected function handlePHPUnitConfiguration($configuration) { if (!$configuration->exists()) { throw new BuildException("Unable to find PHPUnit configuration file '" . (string) $configuration . "'"); } $config = PHPUnit_Util_Configuration::getInstance($configuration->getAbsolutePath()); if (empty($config)) { return; } $phpunit = $config->getPHPUnitConfiguration(); if (empty($phpunit)) { return; } $config->handlePHPConfiguration(); if (isset($phpunit['bootstrap'])) { $this->setBootstrap($phpunit['bootstrap']); } if (isset($phpunit['stopOnFailure'])) { $this->setHaltonfailure($phpunit['stopOnFailure']); } if (isset($phpunit['stopOnError'])) { $this->setHaltonerror($phpunit['stopOnError']); } if (isset($phpunit['stopOnSkipped'])) { $this->setHaltonskipped($phpunit['stopOnSkipped']); } if (isset($phpunit['stopOnIncomplete'])) { $this->setHaltonincomplete($phpunit['stopOnIncomplete']); } if (isset($phpunit['processIsolation'])) { $this->setProcessIsolation($phpunit['processIsolation']); } $browsers = $config->getSeleniumBrowserConfiguration(); if (!empty($browsers) && class_exists('PHPUnit_Extensions_SeleniumTestCase')) { PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers; } return $phpunit; }
/** */ 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; 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['test']) && $arguments['test'] !== FALSE) { PHPUnit_TextUI_TestRunner::printVersionString(); 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'; } 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['configuration']) && file_exists('phpunit.xml')) { $arguments['configuration'] = realpath('phpunit.xml'); } if (isset($arguments['configuration'])) { $configuration = new PHPUnit_Util_Configuration($arguments['configuration']); $browsers = $configuration->getSeleniumBrowserConfiguration(); if (!empty($browsers)) { require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers; } if (!isset($arguments['test'])) { $configuration->handlePHPConfiguration(); if (!isset($arguments['bootstrap'])) { $phpunitConfiguration = $configuration->getPHPUnitConfiguration(); if (isset($phpunitConfiguration['bootstrap'])) { PHPUnit_Util_Fileloader::load($phpunitConfiguration['bootstrap']); } } $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; }
<?php define('SELENIUM_ENABLE', true); require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; PHPUnit_Extensions_SeleniumTestCase::$browsers = array(array('name' => 'Firefox', 'browser' => '*firefox', 'host' => 'localhost', 'port' => 4444, 'timeout' => 30000));
/** * 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:u:h:p:b:v::', 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': case '--coverage-html': case '--coverage-php': case '--coverage-text': if (!extension_loaded('tokenizer')) { $this->showExtensionNotLoadedMessage('tokenizer', 'No code coverage will be generated.'); continue; } if (!extension_loaded('xdebug')) { $this->showExtensionNotLoadedMessage('Xdebug', 'No code coverage will be generated.'); continue; } switch ($option[0]) { case '--coverage-clover': $this->arguments['coverageClover'] = $option[1]; break; case '--coverage-html': $this->arguments['reportDirectory'] = $option[1]; break; case '--coverage-php': $this->arguments['coveragePHP'] = $option[1]; break; case '--coverage-text': if ($option[1] === NULL) { $option[1] = 'php://stdout'; } $this->arguments['coverageText'] = $option[1]; $this->arguments['coverageTextShowUncoveredFiles'] = FALSE; break; } 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; case '--printer': $this->arguments['printer'] = $option[1]; break; case '--loader': $this->arguments['loader'] = $option[1]; break; case '--log-json': $this->arguments['jsonLogfile'] = $option[1]; break; case '--log-junit': $this->arguments['junitLogfile'] = $option[1]; break; case '--log-tap': $this->arguments['tapLogfile'] = $option[1]; break; case '--process-isolation': $this->arguments['processIsolation'] = TRUE; break; case '--repeat': $this->arguments['repeat'] = (int) $option[1]; break; case '--stderr': $this->arguments['printer'] = new PHPUnit_TextUI_ResultPrinter('php://stderr', isset($this->arguments['verbose']) ? $this->arguments['verbose'] : FALSE); break; case '--stop-on-error': $this->arguments['stopOnError'] = TRUE; break; case '--stop-on-failure': $this->arguments['stopOnFailure'] = TRUE; break; case '--stop-on-incomplete': $this->arguments['stopOnIncomplete'] = TRUE; break; case '--stop-on-skipped': $this->arguments['stopOnSkipped'] = TRUE; break; case '--skeleton-test': $skeletonTest = TRUE; $skeletonClass = FALSE; break; case '--skeleton-class': $skeletonClass = TRUE; $skeletonTest = FALSE; break; case '--tap': $this->arguments['printer'] = new PHPUnit_Util_Log_TAP(); break; case '--testdox': $this->arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text(); break; case '--testdox-html': $this->arguments['testdoxHTMLFile'] = $option[1]; break; case '--testdox-text': $this->arguments['testdoxTextFile'] = $option[1]; break; case '--no-configuration': $this->arguments['useDefaultConfiguration'] = FALSE; break; case '--no-globals-backup': $this->arguments['backupGlobals'] = FALSE; break; case '--static-backup': $this->arguments['backupStaticAttributes'] = TRUE; break; case 'v': case '--verbose': $this->arguments['verbose'] = TRUE; break; case '--version': PHPUnit_TextUI_TestRunner::printVersionString(); exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); break; case '--strict': $this->arguments['strict'] = TRUE; break; // MySQL user name // MySQL user name case 'u': $GLOBALS['mysql_user'] = $option[1]; break; // MySQL password // MySQL password case 'p': if (!empty($option[1])) { $GLOBALS['mysql_pass'] = $option[1]; } break; // MySQL hostname // MySQL hostname case 'h': $GLOBALS['mysql_host'] = $option[1]; break; // MySQL db name // MySQL db name case 'b': $GLOBALS['mysql_db'] = $option[1]; break; default: $optionName = str_replace('--', '', $option[0]); if (isset($this->longOptions[$optionName])) { $handler = $this->longOptions[$optionName]; } else { if (isset($this->longOptions[$optionName . '='])) { $handler = $this->longOptions[$optionName . '=']; } } if (isset($handler) && is_callable(array($this, $handler))) { $this->{$handler}($option[1]); } } } $this->handleCustomTestSuite(); if (!isset($this->arguments['test'])) { if (isset($this->options[1][0])) { $this->arguments['test'] = $this->options[1][0]; } if (isset($this->options[1][1])) { $this->arguments['testFile'] = $this->options[1][1]; } else { $this->arguments['testFile'] = ''; } if (isset($this->arguments['test']) && is_file($this->arguments['test']) && substr($this->arguments['test'], -5, 5) != '.phpt') { $this->arguments['testFile'] = realpath($this->arguments['test']); $this->arguments['test'] = substr($this->arguments['test'], 0, strrpos($this->arguments['test'], '.')); } } if (isset($includePath)) { ini_set('include_path', $includePath . PATH_SEPARATOR . ini_get('include_path')); } if (isset($this->arguments['bootstrap'])) { $this->handleBootstrap($this->arguments['bootstrap']); } if (isset($this->arguments['printer']) && is_string($this->arguments['printer'])) { $this->arguments['printer'] = $this->handlePrinter($this->arguments['printer']); } if ($this->arguments['loader'] !== NULL) { $this->arguments['loader'] = $this->handleLoader($this->arguments['loader']); } if (isset($this->arguments['configuration']) && is_dir($this->arguments['configuration'])) { $configurationFile = $GLOBALS['base_dir'] . '/tools/scripts/phpunit.xml'; if (file_exists($configurationFile)) { $this->arguments['configuration'] = realpath($configurationFile); } else { if (file_exists($configurationFile . '.dist')) { $this->arguments['configuration'] = realpath($configurationFile . '.dist'); } } } else { if (!isset($this->arguments['configuration']) && $this->arguments['useDefaultConfiguration']) { if (file_exists('phpunit.xml')) { $this->arguments['configuration'] = realpath('phpunit.xml'); } else { if (file_exists('phpunit.xml.dist')) { $this->arguments['configuration'] = realpath('phpunit.xml.dist'); } } } } if (isset($this->arguments['configuration'])) { try { $configuration = PHPUnit_Util_Configuration::getInstance($this->arguments['configuration']); } catch (Exception $e) { print $e->getMessage() . "\n"; exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } $phpunit = $configuration->getPHPUnitConfiguration(); $configuration->handlePHPConfiguration(); if (!isset($this->arguments['bootstrap']) && isset($phpunit['bootstrap'])) { $this->handleBootstrap($phpunit['bootstrap']); } if (isset($phpunit['printerClass'])) { if (isset($phpunit['printerFile'])) { $file = $phpunit['printerFile']; } else { $file = ''; } $this->arguments['printer'] = $this->handlePrinter($phpunit['printerClass'], $file); } if (isset($phpunit['testSuiteLoaderClass'])) { if (isset($phpunit['testSuiteLoaderFile'])) { $file = $phpunit['testSuiteLoaderFile']; } else { $file = ''; } $this->arguments['loader'] = $this->handleLoader($phpunit['testSuiteLoaderClass'], $file); } $logging = $configuration->getLoggingConfiguration(); if (isset($logging['coverage-html']) || isset($logging['coverage-clover']) || isset($logging['coverage-text'])) { if (!extension_loaded('tokenizer')) { $this->showExtensionNotLoadedMessage('tokenizer', 'No code coverage will be generated.'); } else { if (!extension_loaded('Xdebug')) { $this->showExtensionNotLoadedMessage('Xdebug', 'No code coverage will be generated.'); } } } $browsers = $configuration->getSeleniumBrowserConfiguration(); if (!empty($browsers) && class_exists('PHPUnit_Extensions_SeleniumTestCase')) { PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers; } if (!isset($this->arguments['test'])) { $testSuite = $configuration->getTestSuiteConfiguration(); if ($testSuite !== NULL) { $this->arguments['test'] = $testSuite; } } } if (isset($this->arguments['test']) && is_string($this->arguments['test']) && substr($this->arguments['test'], -5, 5) == '.phpt') { $test = new PHPUnit_Extensions_PhptTestCase($this->arguments['test']); $this->arguments['test'] = new PHPUnit_Framework_TestSuite(); $this->arguments['test']->addTest($test); } if (!isset($this->arguments['test']) || isset($this->arguments['testDatabaseLogRevision']) && !isset($this->arguments['testDatabaseDSN'])) { $this->showHelp(); exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); } /* $GLOBALS['mysql_pass_need_password'] allows us to get password if * needed later, after including civicrm.settings.php. */ $GLOBALS['mysql_pass_need_password'] = FALSE; if (empty($GLOBALS['mysql_pass']) && substr($this->arguments['test'], 0, 8) != 'WebTest_') { $GLOBALS['mysql_pass_need_password'] = TRUE; } if ($skeletonClass || $skeletonTest) { if (isset($this->arguments['test']) && $this->arguments['test'] !== FALSE) { PHPUnit_TextUI_TestRunner::printVersionString(); print <<<EOT The functionality of phpunit --skeleton-class and phpunit --skeleton-test will be removed in PHPUnit 3.7. Please pear install phpunit/PHPUnit_SkeletonGenerator and use phpunit-skelgen --class and phpunit-skelgen --test instead. Sorry for any inconvenience caused by this change. EOT; if ($skeletonClass) { $class = 'PHPUnit_Util_Skeleton_Class'; } else { $class = 'PHPUnit_Util_Skeleton_Test'; } try { $args = array(); $reflector = new ReflectionClass($class); for ($i = 0; $i <= 3; $i++) { if (isset($this->options[1][$i])) { $args[] = $this->options[1][$i]; } } $skeleton = $reflector->newInstanceArgs($args); $skeleton->write(); } catch (Exception $e) { print $e->getMessage() . "\n"; 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 { $this->showHelp(); exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); } } }
<?php error_reporting(E_ALL); ini_set('error_log', __DIR__ . '/../build/error.log'); define('TESTING', true); /** @var \Nano\Application $application */ require_once __DIR__ . '/../application-example/bootstrap.php'; if ($application->config->exists('selenium')) { define('SELENIUM_ENABLE', $application->config->get('selenium')->enabled); if (SELENIUM_ENABLE) { PHPUnit_Extensions_SeleniumTestCase::$browsers = array((array) $application->config->get('selenium')->browser); } } $GLOBALS['application'] = $application;
/** * @since Method available since Release 2.16.0 */ protected function earlyConfigure() { require_once 'PHPUnit/Util/Configuration.php'; $phpunitConfiguration = PHPUnit_Util_Configuration::getInstance($this->config->phpunitConfigFile)->getPHPUnitConfiguration(); if (array_key_exists('bootstrap', $phpunitConfiguration)) { if (array_key_exists('syntaxCheck', $phpunitConfiguration)) { $this->handleBootstrap($phpunitConfiguration['bootstrap'], $phpunitConfiguration['syntaxCheck']); } else { $this->handleBootstrap($phpunitConfiguration['bootstrap']); } } $browsers = PHPUnit_Util_Configuration::getInstance($this->config->phpunitConfigFile)->getSeleniumBrowserConfiguration(); if (count($browsers)) { require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers; } }
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); foreach ($tests as $currenttest) { $number += sizeof($currenttest); $alltests[] = $currenttest; $alltests[] = $filename; } } if ($canCountTest) { print traceCommand("testCount", "count", (string) $number); } for ($i = 0; $i < count($alltests); $i += 2) { self::runTest($alltests[$i], $alltests[$i + 1], $arguments); } return; } } else { if ($check == 'f') { // if run all in file $filename = $isLocal ? $_SERVER['argv'][$startPos + 1] : $_GET["file"]; $tests = self::collectTestsFromFile($filename); $test = new PHPUnit_Framework_TestSuite(); $number = 0; foreach ($tests as $currenttest) { if ($tests) { $test->addTest($currenttest); $number += sizeof($currenttest); } } if ($canCountTest) { print traceCommand("testCount", "count", $number); } foreach ($tests as $currentTest) { self::runTest($currentTest, $filename, $arguments); } return; } else { if ($check == 'm') { $suiteMethodName = $isLocal ? $_SERVER['argv'][$startPos + 1] : $_GET["method"]; $suiteClassName = $isLocal ? $_SERVER['argv'][$startPos + 2] : $_GET["class"]; $suiteClassFile = $isLocal ? $_SERVER['argv'][$startPos + 3] : $_GET["file"]; try { $testClass = new PHPUnit_Runner_StandardTestSuiteLoader(); $testClass = $testClass->load($suiteClassName, $suiteClassFile, FALSE); } catch (Exception $e) { myExceptionHandler($e); return; } try { // if class is a suite $suiteMethod = $testClass->getMethod($suiteMethodName); if ($suiteMethodName == 'suite') { if ($suiteMethod->isAbstract() || !$suiteMethod->isPublic() || !$suiteMethod->isStatic()) { return; } try { $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; } } else { $test = PHPUnit_Framework_TestSuite::createTest($testClass, $suiteMethodName); $testSuite = new PHPUnit_Framework_TestSuite(); $testSuite->addTest($test); $testSuite->setName($suiteClassName); if ($canCountTest) { print traceCommand("testCount", "count", (string) sizeof($test)); } self::runTest($testSuite, $suiteClassFile, $arguments); } } catch (ReflectionException $e) { myExceptionHandler($e); return; } } else { if ($check == 'x') { $testSuite = $configuration->getTestSuiteConfiguration(); self::runTest($testSuite, "", $arguments); } } } } } }
/** * @since Method available since Release 2.16.0 */ protected function earlyConfigure() { $this->phpunitXMLConfiguration->handlePHPConfiguration(); if ($this->phpunitXMLConfiguration->hasPHPUnitConfiguration('bootstrap')) { if ($this->phpunitXMLConfiguration->hasPHPUnitConfiguration('syntaxCheck')) { $this->handleBootstrap($this->phpunitXMLConfiguration->getPHPUnitConfiguration('bootstrap'), $this->phpunitXMLConfiguration->getPHPUnitConfiguration('syntaxCheck')); } else { $this->handleBootstrap($this->phpunitXMLConfiguration->getPHPUnitConfiguration('bootstrap')); } } if ($this->phpunitXMLConfiguration->hasPHPUnitConfiguration('colors')) { $this->terminal->setColor($this->phpunitXMLConfiguration->getPHPUnitConfiguration('colors')); } if ($this->phpunitXMLConfiguration->hasSeleniumBrowserConfiguration()) { \PHPUnit_Extensions_SeleniumTestCase::$browsers = $this->phpunitXMLConfiguration->getSeleniumBrowserConfiguration(); } }
/** * @param \PHPUnit_Util_Configuration $configuration $configuration * * @since Method available since Release 2.16.0 */ protected function earlyConfigure(\PHPUnit_Util_Configuration $configuration) { $configuration->handlePHPConfiguration(); $phpunitConfiguration = $configuration->getPHPUnitConfiguration(); if (array_key_exists('bootstrap', $phpunitConfiguration)) { if (array_key_exists('syntaxCheck', $phpunitConfiguration)) { $this->handleBootstrap($phpunitConfiguration['bootstrap'], $phpunitConfiguration['syntaxCheck']); } else { $this->handleBootstrap($phpunitConfiguration['bootstrap']); } } if (array_key_exists('colors', $phpunitConfiguration)) { $this->terminal->setColor($phpunitConfiguration['colors']); } if (method_exists($configuration, 'getSeleniumBrowserConfiguration') && class_exists('PHPUnit_Extensions_SeleniumTestCase')) { $seleniumBrowserConfiguration = $configuration->getSeleniumBrowserConfiguration(); if (count($seleniumBrowserConfiguration) > 0) { \PHPUnit_Extensions_SeleniumTestCase::$browsers = $seleniumBrowserConfiguration; } } }