getopt() public static method

public static getopt ( array $args, $short_options, $long_options = NULL )
$args array
 public function testItIncludeTheShortOptionsAfterTheArgument()
 {
     $args = array('command', 'myArgument', '-v');
     $actual = PHPUnit_Util_Getopt::getopt($args, 'v');
     $expected = array(array(array('v', null)), array('myArgument'));
     $this->assertEquals($expected, $actual);
 }
Example #2
0
 public function testItIncludeTheShortOptionsAfterTheArgument()
 {
     $args = ['command', 'myArgument', '-v'];
     $actual = PHPUnit_Util_Getopt::getopt($args, 'v');
     $expected = [[['v', null]], ['myArgument']];
     $this->assertEquals($expected, $actual);
 }
Example #3
0
function _get_test_suite()
{
    $suite = '';
    $opts = PHPUnit_Util_Getopt::getopt($GLOBALS['argv'], 'd:c:hv', array('filter=', 'testsuite='));
    foreach ($opts[0] as $opt) {
        if ('--testsuite' === $opt[0]) {
            $suite = $opt[1];
            break;
        }
        if ('--filter' === $opt[0] && false !== stripos($opt[1], 'unit')) {
            $suite = 'unit';
            break;
        }
    }
    return strtolower($suite);
}
Example #4
0
 function __construct($argv)
 {
     $options = PHPUnit_Util_Getopt::getopt($argv, 'd:c:hv', array_keys($this->longOptions));
     $ajax_message = true;
     foreach ($options[0] as $option) {
         switch ($option[0]) {
             case '--exclude-group':
                 $ajax_message = false;
                 continue 2;
             case '--group':
                 $groups = explode(',', $option[1]);
                 foreach ($groups as $group) {
                     if (is_numeric($group) || preg_match('/^(UT|Plugin)\\d+$/', $group)) {
                         WP_UnitTestCase::forceTicket($group);
                     }
                 }
                 $ajax_message = !in_array('ajax', $groups);
                 continue 2;
         }
     }
     if ($ajax_message) {
         echo "Not running ajax tests... To execute these, use --group ajax." . PHP_EOL;
     }
 }
Example #5
0
 /**
  * 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);
         }
     }
 }
Example #6
0
 /**
  * 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);
     }
 }
    /**
     * 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);
            }
        }
    }
Example #8
0
 /**
  * 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['check-version'] = null;
         $this->longOptions['selfupdate'] = null;
         $this->longOptions['self-update'] = null;
         $this->longOptions['selfupgrade'] = null;
         $this->longOptions['self-upgrade'] = 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'] = $option[1] ?: PHPUnit_TextUI_ResultPrinter::COLOR_AUTO;
                 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 '--generate-configuration':
                 $this->printVersionString();
                 printf("Generating phpunit.xml in %s\n\n", getcwd());
                 print "Bootstrap script (relative to path shown above; default: vendor/autoload.php): ";
                 $bootstrapScript = trim(fgets(STDIN));
                 print "Tests directory (relative to path shown above; default: tests): ";
                 $testsDirectory = trim(fgets(STDIN));
                 print "Source directory (relative to path shown above; default: src): ";
                 $src = trim(fgets(STDIN));
                 if ($bootstrapScript == '') {
                     $bootstrapScript = 'vendor/autoload.php';
                 }
                 if ($testsDirectory == '') {
                     $testsDirectory = 'tests';
                 }
                 if ($src == '') {
                     $src = 'src';
                 }
                 $generator = new ConfigurationGenerator();
                 file_put_contents('phpunit.xml', $generator->generateDefaultConfiguration(PHPUnit_Runner_Version::series(), $bootstrapScript, $testsDirectory, $src));
                 printf("\nGenerated phpunit.xml in %s\n", getcwd());
                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 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 '--log-teamcity':
                 $this->arguments['teamcityLogfile'] = $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-warning':
                 $this->arguments['stopOnWarning'] = 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 '--fail-on-warning':
                 $this->arguments['failOnWarning'] = true;
                 break;
             case '--fail-on-risky':
                 $this->arguments['failOnRisky'] = true;
                 break;
             case '--tap':
                 $this->arguments['printer'] = 'PHPUnit_Util_Log_TAP';
                 break;
             case '--teamcity':
                 $this->arguments['printer'] = 'PHPUnit_Util_Log_TeamCity';
                 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-coverage':
                 $this->arguments['noCoverage'] = true;
                 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 '--atleast-version':
                 exit(version_compare(PHPUnit_Runner_Version::id(), $option[1], '>=') ? PHPUnit_TextUI_TestRunner::SUCCESS_EXIT : PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
                 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 '--disable-coverage-ignore':
                 $this->arguments['disableCodeCoverageIgnore'] = true;
                 break;
             case '--strict-global-state':
                 $this->arguments['beStrictAboutChangesToGlobalState'] = true;
                 break;
             case '--disallow-test-output':
                 $this->arguments['disallowTestOutput'] = true;
                 break;
             case '--disallow-resource-usage':
                 $this->arguments['beStrictAboutResourceUsageDuringSmallTests'] = true;
                 break;
             case '--enforce-time-limit':
                 $this->arguments['enforceTimeLimit'] = true;
                 break;
             case '--disallow-todo-tests':
                 $this->arguments['disallowTodoAnnotatedTests'] = true;
                 break;
             case '--reverse-list':
                 $this->arguments['reverseList'] = true;
                 break;
             case '--check-version':
                 $this->handleVersionCheck();
                 break;
             case '--selfupdate':
             case '--self-update':
                 $this->handleSelfUpdate();
                 break;
             case '--selfupgrade':
             case '--self-upgrade':
                 $this->handleSelfUpdate(true);
                 break;
             case '--whitelist':
                 $this->arguments['whitelist'] = $option[1];
                 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([$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'] = ['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 (Throwable $e) {
             print $e->getMessage() . "\n";
             exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
         } catch (Exception $e) {
             print $e->getMessage() . "\n";
             exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
         }
         $phpunitConfiguration = $configuration->getPHPUnitConfiguration();
         $configuration->handlePHPConfiguration();
         /*
          * Issue #1216
          */
         if (isset($this->arguments['bootstrap'])) {
             $this->handleBootstrap($this->arguments['bootstrap']);
         } elseif (isset($phpunitConfiguration['bootstrap'])) {
             $this->handleBootstrap($phpunitConfiguration['bootstrap']);
         }
         /*
          * Issue #657
          */
         if (isset($phpunitConfiguration['stderr']) && !isset($this->arguments['stderr'])) {
             $this->arguments['stderr'] = $phpunitConfiguration['stderr'];
         }
         if (isset($phpunitConfiguration['columns']) && !isset($this->arguments['columns'])) {
             $this->arguments['columns'] = $phpunitConfiguration['columns'];
         }
         if (!isset($this->arguments['printer']) && isset($phpunitConfiguration['printerClass'])) {
             if (isset($phpunitConfiguration['printerFile'])) {
                 $file = $phpunitConfiguration['printerFile'];
             } else {
                 $file = '';
             }
             $this->arguments['printer'] = $this->handlePrinter($phpunitConfiguration['printerClass'], $file);
         }
         if (isset($phpunitConfiguration['testSuiteLoaderClass'])) {
             if (isset($phpunitConfiguration['testSuiteLoaderFile'])) {
                 $file = $phpunitConfiguration['testSuiteLoaderFile'];
             } else {
                 $file = '';
             }
             $this->arguments['loader'] = $this->handleLoader($phpunitConfiguration['testSuiteLoaderClass'], $file);
         }
         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);
     }
 }
Example #9
0
 /**
  * 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);
     }
 }
Example #10
0
 /**
  */
 protected static function handleArguments()
 {
     $arguments = array('listGroups' => FALSE, 'syntaxCheck' => TRUE);
     $longOptions = array('ansi', 'bootstrap=', 'configuration=', 'coverage-html=', 'coverage-clover=', 'coverage-source=', 'coverage-xml=', 'exclude-group=', 'filter=', 'group=', 'help', 'list-groups', 'loader=', 'log-graphviz=', 'log-json=', 'log-metrics=', 'log-pmd=', 'log-tap=', 'log-xml=', 'repeat=', 'report=', 'skeleton', 'skeleton-class', 'skeleton-test', 'stop-on-failure', 'story', 'story-html=', 'story-text=', 'tap', 'test-db-dsn=', 'test-db-log-rev=', 'test-db-log-prefix=', 'test-db-log-info=', 'testdox', 'testdox-html=', 'testdox-text=', 'no-syntax-check', 'verbose', 'version', 'wait');
     try {
         $options = PHPUnit_Util_Getopt::getopt($_SERVER['argv'], 'd:', $longOptions);
     } catch (RuntimeException $e) {
         PHPUnit_TextUI_TestRunner::showError($e->getMessage());
     }
     if (isset($options[1][0])) {
         $arguments['test'] = $options[1][0];
     }
     if (isset($options[1][1])) {
         $arguments['testFile'] = $options[1][1];
     } else {
         $arguments['testFile'] = '';
     }
     foreach ($options[0] as $option) {
         switch ($option[0]) {
             case '--ansi':
                 $arguments['ansi'] = TRUE;
                 break;
             case '--bootstrap':
                 $arguments['bootstrap'] = $option[1];
                 break;
             case '--configuration':
                 $arguments['configuration'] = $option[1];
                 break;
             case '--coverage-clover':
             case '--coverage-xml':
                 if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
                     $arguments['coverageClover'] = $option[1];
                 } else {
                     if (!extension_loaded('tokenizer')) {
                         self::showMissingDependency('The tokenizer extension is not loaded.');
                     } else {
                         self::showMissingDependency('The Xdebug extension is not loaded.');
                     }
                 }
                 break;
             case '--coverage-source':
                 if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
                     $arguments['coverageSource'] = $option[1];
                 } else {
                     if (!extension_loaded('tokenizer')) {
                         self::showMissingDependency('The tokenizer extension is not loaded.');
                     } else {
                         self::showMissingDependency('The Xdebug extension is not loaded.');
                     }
                 }
                 break;
             case '--coverage-html':
             case '--report':
                 if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
                     $arguments['reportDirectory'] = $option[1];
                 } else {
                     if (!extension_loaded('tokenizer')) {
                         self::showMissingDependency('The tokenizer extension is not loaded.');
                     } else {
                         self::showMissingDependency('The Xdebug extension is not loaded.');
                     }
                 }
                 break;
             case 'd':
                 $ini = explode('=', $option[1]);
                 if (isset($ini[0])) {
                     if (isset($ini[1])) {
                         ini_set($ini[0], $ini[1]);
                     } else {
                         ini_set($ini[0], TRUE);
                     }
                 }
                 break;
             case '--help':
                 self::showHelp();
                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 break;
             case '--filter':
                 if (preg_match('/^[a-zA-Z0-9_]/', $option[1])) {
                     $arguments['filter'] = '/' . $option[1] . '/';
                 } else {
                     $arguments['filter'] = $option[1];
                 }
                 break;
             case '--group':
                 $arguments['groups'] = explode(',', $option[1]);
                 break;
             case '--exclude-group':
                 $arguments['excludeGroups'] = explode(',', $option[1]);
                 break;
             case '--list-groups':
                 $arguments['listGroups'] = TRUE;
                 break;
             case '--loader':
                 self::handleLoader($option[1]);
                 break;
             case '--log-json':
                 $arguments['jsonLogfile'] = $option[1];
                 break;
             case '--log-graphviz':
                 if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) {
                     $arguments['graphvizLogfile'] = $option[1];
                 } else {
                     self::showMissingDependency('The Image_GraphViz package is not installed.');
                 }
                 break;
             case '--log-tap':
                 $arguments['tapLogfile'] = $option[1];
                 break;
             case '--log-xml':
                 $arguments['xmlLogfile'] = $option[1];
                 break;
             case '--log-pmd':
                 if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
                     $arguments['pmdXML'] = $option[1];
                 } else {
                     if (!extension_loaded('tokenizer')) {
                         self::showMissingDependency('The tokenizer extension is not loaded.');
                     } else {
                         self::showMissingDependency('The Xdebug extension is not loaded.');
                     }
                 }
                 break;
             case '--log-metrics':
                 if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
                     $arguments['metricsXML'] = $option[1];
                 } else {
                     if (!extension_loaded('tokenizer')) {
                         self::showMissingDependency('The tokenizer extension is not loaded.');
                     } else {
                         self::showMissingDependency('The Xdebug extension is not loaded.');
                     }
                 }
                 break;
             case '--repeat':
                 $arguments['repeat'] = (int) $option[1];
                 break;
             case '--stop-on-failure':
                 $arguments['stopOnFailure'] = TRUE;
                 break;
             case '--test-db-dsn':
                 if (extension_loaded('pdo')) {
                     $arguments['testDatabaseDSN'] = $option[1];
                 } else {
                     self::showMissingDependency('The PDO extension is not loaded.');
                 }
                 break;
             case '--test-db-log-rev':
                 if (extension_loaded('pdo')) {
                     $arguments['testDatabaseLogRevision'] = $option[1];
                 } else {
                     self::showMissingDependency('The PDO extension is not loaded.');
                 }
                 break;
             case '--test-db-prefix':
                 if (extension_loaded('pdo')) {
                     $arguments['testDatabasePrefix'] = $option[1];
                 } else {
                     self::showMissingDependency('The PDO extension is not loaded.');
                 }
                 break;
             case '--test-db-log-info':
                 if (extension_loaded('pdo')) {
                     $arguments['testDatabaseLogInfo'] = $option[1];
                 } else {
                     self::showMissingDependency('The PDO extension is not loaded.');
                 }
                 break;
             case '--skeleton':
             case '--skeleton-class':
             case '--skeleton-test':
                 if (isset($arguments['bootstrap'])) {
                     require_once $arguments['bootstrap'];
                 }
                 if ($option[0] == '--skeleton-class') {
                     require_once 'PHPUnit/Util/Skeleton/Class.php';
                     $class = 'PHPUnit_Util_Skeleton_Class';
                 } else {
                     require_once 'PHPUnit/Util/Skeleton/Test.php';
                     $class = 'PHPUnit_Util_Skeleton_Test';
                 }
                 if (isset($arguments['test']) && $arguments['test'] !== FALSE && isset($arguments['testFile'])) {
                     PHPUnit_TextUI_TestRunner::printVersionString();
                     try {
                         $skeleton = new $class($arguments['test'], $arguments['testFile']);
                         $skeleton->write();
                     } catch (Exception $e) {
                         print $e->getMessage() . "\n";
                         printf('Could not skeleton for "%s" to "%s".' . "\n", $skeleton->getOutClassName(), $skeleton->getOutSourceFile());
                         exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
                     }
                     printf('Wrote skeleton for "%s" to "%s".' . "\n", $skeleton->getOutClassName(), $skeleton->getOutSourceFile());
                     exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 } else {
                     self::showHelp();
                     exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
                 }
                 break;
             case '--tap':
                 require_once 'PHPUnit/Util/Log/TAP.php';
                 $arguments['printer'] = new PHPUnit_Util_Log_TAP();
                 break;
             case '--story':
                 require_once 'PHPUnit/Extensions/Story/ResultPrinter/Text.php';
                 $arguments['printer'] = new PHPUnit_Extensions_Story_ResultPrinter_Text();
                 break;
             case '--story-html':
                 $arguments['storyHTMLFile'] = $option[1];
                 break;
             case '--story-text':
                 $arguments['storyTextFile'] = $option[1];
                 break;
             case '--testdox':
                 require_once 'PHPUnit/Util/TestDox/ResultPrinter/Text.php';
                 $arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text();
                 break;
             case '--testdox-html':
                 $arguments['testdoxHTMLFile'] = $option[1];
                 break;
             case '--testdox-text':
                 $arguments['testdoxTextFile'] = $option[1];
                 break;
             case '--no-syntax-check':
                 $arguments['syntaxCheck'] = FALSE;
                 break;
             case '--verbose':
                 $arguments['verbose'] = TRUE;
                 break;
             case '--version':
                 PHPUnit_TextUI_TestRunner::printVersionString();
                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 break;
             case '--wait':
                 $arguments['wait'] = TRUE;
                 break;
         }
     }
     if (!isset($arguments['test']) && isset($arguments['configuration'])) {
         $configuration = new PHPUnit_Util_Configuration($arguments['configuration']);
         $configuration->handlePHPConfiguration();
         $testSuite = $configuration->getTestSuiteConfiguration();
         if ($testSuite !== NULL) {
             $arguments['test'] = $testSuite;
         }
     }
     if (isset($arguments['test']) && is_string($arguments['test']) && substr($arguments['test'], -5, 5) == '.phpt') {
         require_once 'PHPUnit/Extensions/PhptTestCase.php';
         $test = new PHPUnit_Extensions_PhptTestCase($arguments['test']);
         $arguments['test'] = new PHPUnit_Framework_TestSuite();
         $arguments['test']->addTest($test);
     }
     if (!isset($arguments['test']) || isset($arguments['testDatabaseLogRevision']) && !isset($arguments['testDatabaseDSN'])) {
         self::showHelp();
         exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
     }
     return $arguments;
 }
 /**
  * @access protected
  * @static
  */
 protected static function handleArguments()
 {
     $arguments = array('syntaxCheck' => TRUE);
     $longOptions = array('configuration=', 'exclude-group=', 'filter=', 'group=', 'help', 'loader=', 'log-json=', 'log-tap=', 'log-xml=', 'repeat=', 'skeleton', 'stop-on-failure', 'tap', 'testdox', 'testdox-html=', 'testdox-text=', 'no-syntax-check', 'verbose', 'version', 'wait');
     if (class_exists('Image_GraphViz', FALSE)) {
         $longOptions[] = 'log-graphviz=';
     }
     if (extension_loaded('pdo')) {
         $longOptions[] = 'test-db-dsn=';
         $longOptions[] = 'test-db-log-rev=';
         $longOptions[] = 'test-db-log-prefix=';
         $longOptions[] = 'test-db-log-info=';
     }
     if (extension_loaded('xdebug')) {
         $longOptions[] = 'coverage-html=';
         $longOptions[] = 'coverage-xml=';
         $longOptions[] = 'log-metrics=';
         $longOptions[] = 'log-pmd=';
         $longOptions[] = 'report=';
     }
     try {
         $options = PHPUnit_Util_Getopt::getopt($_SERVER['argv'], 'd:', $longOptions);
     } catch (RuntimeException $e) {
         PHPUnit_TextUI_TestRunner::showError($e->getMessage());
     }
     if (isset($options[1][0])) {
         $arguments['test'] = $options[1][0];
     }
     if (isset($options[1][1])) {
         $arguments['testFile'] = $options[1][1];
     } else {
         $arguments['testFile'] = '';
     }
     foreach ($options[0] as $option) {
         switch ($option[0]) {
             case '--configuration':
                 $arguments['configuration'] = $option[1];
                 break;
             case '--coverage-xml':
                 $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 '--help':
                 self::showHelp();
                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 break;
             case '--filter':
                 if (preg_match('/^[a-zA-Z0-9_]/', $option[1])) {
                     $arguments['filter'] = '/^' . $option[1] . '$/';
                 } else {
                     $arguments['filter'] = $option[1];
                 }
                 break;
             case '--group':
                 $arguments['groups'] = explode(',', $option[1]);
                 break;
             case '--exclude-group':
                 $arguments['excludeGroups'] = explode(',', $option[1]);
                 break;
             case '--loader':
                 self::handleLoader($option[1]);
                 break;
             case '--log-json':
                 $arguments['jsonLogfile'] = $option[1];
                 break;
             case '--log-graphviz':
                 $arguments['graphvizLogfile'] = $option[1];
                 break;
             case '--log-tap':
                 $arguments['tapLogfile'] = $option[1];
                 break;
             case '--log-xml':
                 $arguments['xmlLogfile'] = $option[1];
                 break;
             case '--log-pmd':
                 $arguments['pmdXML'] = $option[1];
                 break;
             case '--log-metrics':
                 $arguments['metricsXML'] = $option[1];
                 break;
             case '--repeat':
                 $arguments['repeat'] = (int) $option[1];
                 break;
             case '--stop-on-failure':
                 $arguments['stopOnFailure'] = TRUE;
                 break;
             case '--test-db-dsn':
                 $arguments['testDatabaseDSN'] = $option[1];
                 break;
             case '--test-db-log-rev':
                 $arguments['testDatabaseLogRevision'] = $option[1];
                 break;
             case '--test-db-prefix':
                 $arguments['testDatabasePrefix'] = $option[1];
                 break;
             case '--test-db-log-info':
                 $arguments['testDatabaseLogInfo'] = $option[1];
                 break;
             case '--coverage-html':
             case '--report':
                 $arguments['reportDirectory'] = $option[1];
                 break;
             case '--skeleton':
                 if (isset($arguments['test']) && isset($arguments['testFile'])) {
                     self::doSkeleton($arguments['test'], $arguments['testFile']);
                 } else {
                     self::showHelp();
                     exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
                 }
                 break;
             case '--tap':
                 $arguments['printer'] = new PHPUnit_Util_Log_TAP();
                 break;
             case '--testdox':
                 $arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text();
                 break;
             case '--testdox-html':
                 $arguments['testdoxHTMLFile'] = $option[1];
                 break;
             case '--testdox-text':
                 $arguments['testdoxTextFile'] = $option[1];
                 break;
             case '--no-syntax-check':
                 $arguments['syntaxCheck'] = FALSE;
                 break;
             case '--verbose':
                 $arguments['verbose'] = TRUE;
                 break;
             case '--version':
                 PHPUnit_TextUI_TestRunner::printVersionString();
                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 break;
             case '--wait':
                 $arguments['wait'] = TRUE;
                 break;
         }
     }
     if (!isset($arguments['test']) && isset($arguments['configuration'])) {
         $configuration = new PHPUnit_Util_Configuration($arguments['configuration']);
         $testSuite = $configuration->getTestSuiteConfiguration();
         if ($testSuite !== NULL) {
             $arguments['test'] = $testSuite;
         }
     }
     if (!isset($arguments['test']) || isset($arguments['testDatabaseLogRevision']) && !isset($arguments['testDatabaseDSN'])) {
         self::showHelp();
         exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
     }
     return $arguments;
 }
 /**
  * Handles the commandline arguments passed.
  * 
  * @return     array the commandline arguments
  * 
  * @author     Felix Gilcher <*****@*****.**>
  * @since      1.0.0
  */
 public static function processCommandlineOptions()
 {
     $longOptions = array('coverage-html=', 'coverage-clover=', 'coverage-source=', 'coverage-xml=', 'report=', 'environment=', 'help', 'log-graphviz=', 'log-json=', 'log-metrics=', 'log-pmd=', 'log-tap=', 'log-xml=', 'include-suite=', 'exclude-suite=');
     try {
         $options = PHPUnit_Util_Getopt::getopt($_SERVER['argv'], 'd:', $longOptions);
     } catch (RuntimeException $e) {
         PHPUnit_TextUI_TestRunner::showError($e->getMessage());
     }
     $arguments = array();
     foreach ($options[0] as $option) {
         switch ($option[0]) {
             case '--coverage-clover':
             case '--coverage-xml':
                 if (self::checkCodeCoverageDeps()) {
                     $arguments['coverageClover'] = $option[1];
                 }
                 break;
             case '--coverage-source':
                 if (self::checkCodeCoverageDeps()) {
                     $arguments['coverageSource'] = $option[1];
                 }
                 break;
             case '--coverage-html':
             case '--report':
                 if (self::checkCodeCoverageDeps()) {
                     $arguments['reportDirectory'] = $option[1];
                 }
                 break;
             case '--environment':
                 $arguments['environment'] = $option[1];
                 break;
             case '--help':
                 self::showHelp();
                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 break;
             case '--log-json':
                 $arguments['jsonLogfile'] = $option[1];
                 break;
             case '--log-graphviz':
                 if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) {
                     $arguments['graphvizLogfile'] = $option[1];
                 } else {
                     throw new AgaviException('The Image_GraphViz package is not installed.');
                 }
                 break;
             case '--log-tap':
                 $arguments['tapLogfile'] = $option[1];
                 break;
             case '--log-xml':
                 $arguments['xmlLogfile'] = $option[1];
                 break;
             case '--log-pmd':
                 if (self::checkCodeCoverageDeps()) {
                     $arguments['pmdXML'] = $option[1];
                 }
                 break;
             case '--log-metrics':
                 if (self::checkCodeCoverageDeps()) {
                     $arguments['metricsXML'] = $option[1];
                 }
                 break;
             case '--include-suite':
                 $arguments['include-suite'] = $option[1];
                 break;
             case '--exclude-suite':
                 $arguments['exclude-suite'] = $option[1];
                 break;
         }
     }
     return $arguments;
 }
 public function isDebug()
 {
     list($opts, $non_opts) = \PHPUnit_Util_Getopt::getopt($_SERVER['argv'], 'd:c:hv');
     $key = array_search('--debug', $non_opts);
     return is_int($key);
 }
Example #14
0
    /**
     * 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);
            }
        }
    }
Example #15
0
 /**
  * Read PHPUnit options
  */
 protected function readOptions()
 {
     try {
         $reader = new Core_FileReader();
         $options = \PHPUnit_Util_Getopt::getopt($_SERVER['argv'], 'd:c:hv', array_keys($reader->getLongOptions()));
     } catch (\PHPUnit_Framework_Exception $e) {
         \PHPUnit_TextUI_TestRunner::showError($e->getMessage());
     }
     foreach ($options[0] as $option) {
         $this->options[$option[0]] = isset($option[1]) ? $option[1] : true;
     }
 }
 /**
  * @access protected
  * @static
  */
 protected static function _initArguments()
 {
     $arguments['suite_filter'] = array();
     $arguments['runner_parameters'] = array();
     $longOptions = array('list-suites', 'new-suite=', 'suite-filter=', 'test-filter=', 'help', 'verbose', 'version');
     try {
         $options = PHPUnit_Util_Getopt::getopt($_SERVER['argv'], 'd:', $longOptions);
     } catch (RuntimeException $e) {
         PHPUnit_TextUI_TestRunner::showError($e->getMessage());
     }
     foreach ($options[0] as $option) {
         switch ($option[0]) {
             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 '--list-suites':
                 self::_listSuites();
                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 break;
             case '--new-suite':
                 self::_createNewSuite($option[1]);
                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 break;
             case '--suite-filter':
                 $arguments['suite_filter'] = explode(",", $option[1]);
                 break;
             case '--test-filter':
                 $arguments['runner_parameters']['filter'] = "/" . $option[1] . "/i";
                 break;
             case '--help':
                 self::_showHelp();
                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 break;
             case '--verbose':
                 $arguments['runner_parameters']['verbose'] = true;
                 break;
             case '--version':
                 self::_printVersionString();
                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 break;
         }
     }
     self::$_arguments = $arguments;
     return true;
 }