Example XML configuration file: /path/to/files /path/to/MyTest.php /path/to/files/exclude name name name name /path/to/files /path/to/file /path/to/files /path/to/file Sebastian 22 April 19.78 MyRelativeFile.php MyRelativeDir .
 private function bootstrap(InputInterface $input, \PHPUnit_Util_Configuration $config)
 {
     $bootstrap = $input->getOption('bootstrap');
     if (!$bootstrap && isset($config->getPHPUnitConfiguration()['bootstrap'])) {
         $bootstrap = $config->getPHPUnitConfiguration()['bootstrap'];
     }
     if ($bootstrap) {
         putenv('PHPUNIT_PARALLEL=master');
         dont_leak_env_and_include($bootstrap);
     }
 }
 /**
  * @param ReflectionClass $theClass
  * @param Stagehand_TestRunner_Config $config
  * @return boolean
  */
 protected function shouldExclude(ReflectionClass $class, ReflectionMethod $method)
 {
     if (is_null($this->config->phpunitConfigFile)) {
         return false;
     }
     $groups = PHPUnit_Util_Test::getGroups($class->getName(), $method->getName());
     $shouldExclude = false;
     $groupConfiguration = PHPUnit_Util_Configuration::getInstance($this->config->phpunitConfigFile)->getGroupConfiguration();
     if (array_key_exists('include', $groupConfiguration) && count($groupConfiguration['include'])) {
         $shouldExclude = true;
         foreach ($groups as $group) {
             if (in_array($group, $groupConfiguration['include'])) {
                 $shouldExclude = false;
                 break;
             }
         }
     }
     if (array_key_exists('exclude', $groupConfiguration) && count($groupConfiguration['exclude'])) {
         foreach ($groups as $group) {
             if (in_array($group, $groupConfiguration['exclude'])) {
                 $shouldExclude = true;
                 break;
             }
         }
     }
     return $shouldExclude;
 }
Example #3
0
 /**
  * {@inheritDoc}
  * @see \Guide42\CliUnit\Strategy\StrategyInterface::findTests()
  */
 public function findTests($directory)
 {
     $config = \PHPUnit_Util_Configuration::getInstance($this->findConfigFile($directory));
     foreach ($config->getTestSuiteConfiguration() as $suite) {
         $command = 'ls';
         (yield new TestCase($suite->getName(), $command));
     }
 }
 /**
  * @return \PHPUnit_Util_Configuration
  */
 public function create()
 {
     if (is_null($this->phpunitConfigurationFile)) {
         return null;
     } else {
         return \PHPUnit_Util_Configuration::getInstance($this->phpunitConfigurationFile);
     }
 }
Example #5
0
 public function __construct($theClass = '', $name = '')
 {
     $this->setName(get_class($this));
     $zendPath = getCwd();
     chdir(realpath(dirname(__FILE__)));
     require_once 'PHPUnit/Util/Configuration.php';
     // test phpUnit version
     if (version_compare(PHPUnit_Runner_Version::id(), '3.4', '>=')) {
         $configuration = PHPUnit_Util_Configuration::getInstance('phpunit.xml');
     } else {
         $configuration = new PHPUnit_Util_Configuration('phpunit.xml');
     }
     $testSuite = $configuration->getTestSuiteConfiguration(false);
     chdir($zendPath);
     foreach ($testSuite->tests() as $test) {
         if (!$test instanceof PHPUnit_Framework_Warning) {
             $this->addTestSuite($test);
         }
     }
 }
 public static function execute($xmlFile)
 {
     $configuration = \PHPUnit_Util_Configuration::getInstance($xmlFile);
     $testSuites = new TestsQueue();
     /** @var \PHPUnit_Framework_TestSuite $bla */
     foreach ($configuration->getTestSuiteConfiguration()->getIterator() as $testSuite) {
         $class = new \ReflectionClass($testSuite->getName());
         $testSuites->add($class->getFileName());
     }
     return $testSuites;
 }
Example #7
0
File: run.php Project: jo-m/ecamp3
 public static function main($configFile)
 {
     $arguments = array('listGroups' => FALSE, 'loader' => NULL, 'useDefaultConfiguration' => TRUE, 'configuration' => $configFile);
     $configuration = PHPUnit_Util_Configuration::getInstance($configFile);
     $configuration->handlePHPConfiguration();
     $phpunit = $configuration->getPHPUnitConfiguration();
     if (isset($phpunit['bootstrap'])) {
         PHPUnit_Util_Fileloader::load($phpunit['bootstrap']);
     }
     $testSuite = $configuration->getTestSuiteConfiguration();
     return self::runTest($testSuite, $arguments);
 }
Example #8
0
 /**
  * Asserts that the values in $actualConfiguration equal $expectedConfiguration.
  *
  * @param PHPUnit_Util_Configuration $expectedConfiguration
  * @param PHPUnit_Util_Configuration $actualConfiguration
  */
 protected function assertConfigurationEquals(PHPUnit_Util_Configuration $expectedConfiguration, PHPUnit_Util_Configuration $actualConfiguration)
 {
     $this->assertEquals($expectedConfiguration->getFilterConfiguration(), $actualConfiguration->getFilterConfiguration());
     $this->assertEquals($expectedConfiguration->getGroupConfiguration(), $actualConfiguration->getGroupConfiguration());
     $this->assertEquals($expectedConfiguration->getListenerConfiguration(), $actualConfiguration->getListenerConfiguration());
     $this->assertEquals($expectedConfiguration->getLoggingConfiguration(), $actualConfiguration->getLoggingConfiguration());
     $this->assertEquals($expectedConfiguration->getPHPConfiguration(), $actualConfiguration->getPHPConfiguration());
     $this->assertEquals($expectedConfiguration->getPHPUnitConfiguration(), $actualConfiguration->getPHPUnitConfiguration());
     $this->assertEquals($expectedConfiguration->getTestSuiteConfiguration(), $actualConfiguration->getTestSuiteConfiguration());
 }
Example #9
0
 public static function get_settings_hackery(PHPUnit_TextUI_Command $toread)
 {
     $arguments = $toread->arguments;
     $config = PHPUnit_Util_Configuration::getInstance($arguments['configuration'])->getPHPUnitConfiguration();
     $verbose = isset($config['verbose']) ? $config['verbose'] : false;
     $verbose = isset($arguments['verbose']) ? $arguments['verbose'] : $verbose;
     $colors = isset($config['colors']) ? $config['colors'] : Hint_ResultPrinter::COLOR_DEFAULT;
     $colors = isset($arguments['colors']) ? $arguments['colors'] : $colors;
     $debug = isset($config['debug']) ? $config['debug'] : false;
     $debug = isset($arguments['debug']) ? $arguments['debug'] : $debug;
     return array($verbose, $colors, $debug);
 }
 /**
  * @param  array $arguments
  * @since  Method available since Release 3.2.1
  */
 protected function handleConfiguration(array &$arguments)
 {
     if (isset($arguments['configuration']) && !$arguments['configuration'] instanceof PHPUnit_Util_Configuration) {
         $arguments['configuration'] = PHPUnit_Util_Configuration::getInstance($arguments['configuration']);
     }
     $arguments['debug'] = isset($arguments['debug']) ? $arguments['debug'] : FALSE;
     $arguments['filter'] = isset($arguments['filter']) ? $arguments['filter'] : FALSE;
     $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
     if (isset($arguments['configuration'])) {
         $arguments['configuration']->handlePHPConfiguration();
         $phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration();
         if (isset($phpunitConfiguration['backupGlobals']) && !isset($arguments['backupGlobals'])) {
             $arguments['backupGlobals'] = $phpunitConfiguration['backupGlobals'];
         }
         if (isset($phpunitConfiguration['backupStaticAttributes']) && !isset($arguments['backupStaticAttributes'])) {
             $arguments['backupStaticAttributes'] = $phpunitConfiguration['backupStaticAttributes'];
         }
         if (isset($phpunitConfiguration['bootstrap']) && !isset($arguments['bootstrap'])) {
             $arguments['bootstrap'] = $phpunitConfiguration['bootstrap'];
         }
         if (isset($phpunitConfiguration['cacheTokens']) && !isset($arguments['cacheTokens'])) {
             $arguments['cacheTokens'] = $phpunitConfiguration['cacheTokens'];
         }
         if (isset($phpunitConfiguration['colors']) && !isset($arguments['colors'])) {
             $arguments['colors'] = $phpunitConfiguration['colors'];
         }
         if (isset($phpunitConfiguration['convertErrorsToExceptions']) && !isset($arguments['convertErrorsToExceptions'])) {
             $arguments['convertErrorsToExceptions'] = $phpunitConfiguration['convertErrorsToExceptions'];
         }
         if (isset($phpunitConfiguration['convertNoticesToExceptions']) && !isset($arguments['convertNoticesToExceptions'])) {
             $arguments['convertNoticesToExceptions'] = $phpunitConfiguration['convertNoticesToExceptions'];
         }
         if (isset($phpunitConfiguration['convertWarningsToExceptions']) && !isset($arguments['convertWarningsToExceptions'])) {
             $arguments['convertWarningsToExceptions'] = $phpunitConfiguration['convertWarningsToExceptions'];
         }
         if (isset($phpunitConfiguration['processIsolation']) && !isset($arguments['processIsolation'])) {
             $arguments['processIsolation'] = $phpunitConfiguration['processIsolation'];
         }
         if (isset($phpunitConfiguration['stopOnFailure']) && !isset($arguments['stopOnFailure'])) {
             $arguments['stopOnFailure'] = $phpunitConfiguration['stopOnFailure'];
         }
         if (isset($phpunitConfiguration['timeoutForSmallTests']) && !isset($arguments['timeoutForSmallTests'])) {
             $arguments['timeoutForSmallTests'] = $phpunitConfiguration['timeoutForSmallTests'];
         }
         if (isset($phpunitConfiguration['timeoutForMediumTests']) && !isset($arguments['timeoutForMediumTests'])) {
             $arguments['timeoutForMediumTests'] = $phpunitConfiguration['timeoutForMediumTests'];
         }
         if (isset($phpunitConfiguration['timeoutForLargeTests']) && !isset($arguments['timeoutForLargeTests'])) {
             $arguments['timeoutForLargeTests'] = $phpunitConfiguration['timeoutForLargeTests'];
         }
         if (isset($phpunitConfiguration['strict']) && !isset($arguments['strict'])) {
             $arguments['strict'] = $phpunitConfiguration['strict'];
         }
         if (isset($phpunitConfiguration['verbose']) && !isset($arguments['verbose'])) {
             $arguments['verbose'] = $phpunitConfiguration['verbose'];
         }
         if (isset($phpunitConfiguration['forceCoversAnnotation']) && !isset($arguments['forceCoversAnnotation'])) {
             $arguments['forceCoversAnnotation'] = $phpunitConfiguration['forceCoversAnnotation'];
         }
         if (isset($phpunitConfiguration['mapTestClassNameToCoveredClassName']) && !isset($arguments['mapTestClassNameToCoveredClassName'])) {
             $arguments['mapTestClassNameToCoveredClassName'] = $phpunitConfiguration['mapTestClassNameToCoveredClassName'];
         }
         $groupConfiguration = $arguments['configuration']->getGroupConfiguration();
         if (!empty($groupConfiguration['include']) && !isset($arguments['groups'])) {
             $arguments['groups'] = $groupConfiguration['include'];
         }
         if (!empty($groupConfiguration['exclude']) && !isset($arguments['excludeGroups'])) {
             $arguments['excludeGroups'] = $groupConfiguration['exclude'];
         }
         foreach ($arguments['configuration']->getListenerConfiguration() as $listener) {
             if (!class_exists($listener['class'], FALSE) && $listener['file'] !== '') {
                 require_once $listener['file'];
             }
             if (class_exists($listener['class'], FALSE)) {
                 if (count($listener['arguments']) == 0) {
                     $listener = new $listener['class']();
                 } else {
                     $listenerClass = new ReflectionClass($listener['class']);
                     $listener = $listenerClass->newInstanceArgs($listener['arguments']);
                 }
                 if ($listener instanceof PHPUnit_Framework_TestListener) {
                     $arguments['listeners'][] = $listener;
                 }
             }
         }
         $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration();
         if (isset($loggingConfiguration['coverage-html']) && !isset($arguments['reportDirectory'])) {
             if (isset($loggingConfiguration['charset']) && !isset($arguments['reportCharset'])) {
                 $arguments['reportCharset'] = $loggingConfiguration['charset'];
             }
             if (isset($loggingConfiguration['yui']) && !isset($arguments['reportYUI'])) {
                 $arguments['reportYUI'] = $loggingConfiguration['yui'];
             }
             if (isset($loggingConfiguration['highlight']) && !isset($arguments['reportHighlight'])) {
                 $arguments['reportHighlight'] = $loggingConfiguration['highlight'];
             }
             if (isset($loggingConfiguration['lowUpperBound']) && !isset($arguments['reportLowUpperBound'])) {
                 $arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound'];
             }
             if (isset($loggingConfiguration['highLowerBound']) && !isset($arguments['reportHighLowerBound'])) {
                 $arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound'];
             }
             $arguments['reportDirectory'] = $loggingConfiguration['coverage-html'];
         }
         if (isset($loggingConfiguration['coverage-clover']) && !isset($arguments['coverageClover'])) {
             $arguments['coverageClover'] = $loggingConfiguration['coverage-clover'];
         }
         if (isset($loggingConfiguration['coverage-php']) && !isset($arguments['coveragePHP'])) {
             $arguments['coveragePHP'] = $loggingConfiguration['coverage-php'];
         }
         if (isset($loggingConfiguration['coverage-text']) && !isset($arguments['coverageText'])) {
             $arguments['coverageText'] = $loggingConfiguration['coverage-text'];
             if (isset($loggingConfiguration['coverageTextShowUncoveredFiles'])) {
                 $arguments['coverageTextShowUncoveredFiles'] = $loggingConfiguration['coverageTextShowUncoveredFiles'];
             } else {
                 $arguments['coverageTextShowUncoveredFiles'] = FALSE;
             }
         }
         if (isset($loggingConfiguration['json']) && !isset($arguments['jsonLogfile'])) {
             $arguments['jsonLogfile'] = $loggingConfiguration['json'];
         }
         if (isset($loggingConfiguration['plain'])) {
             $arguments['listeners'][] = new PHPUnit_TextUI_ResultPrinter($loggingConfiguration['plain'], TRUE);
         }
         if (isset($loggingConfiguration['tap']) && !isset($arguments['tapLogfile'])) {
             $arguments['tapLogfile'] = $loggingConfiguration['tap'];
         }
         if (isset($loggingConfiguration['junit']) && !isset($arguments['junitLogfile'])) {
             $arguments['junitLogfile'] = $loggingConfiguration['junit'];
             if (isset($loggingConfiguration['logIncompleteSkipped']) && !isset($arguments['logIncompleteSkipped'])) {
                 $arguments['logIncompleteSkipped'] = $loggingConfiguration['logIncompleteSkipped'];
             }
         }
         if (isset($loggingConfiguration['testdox-html']) && !isset($arguments['testdoxHTMLFile'])) {
             $arguments['testdoxHTMLFile'] = $loggingConfiguration['testdox-html'];
         }
         if (isset($loggingConfiguration['testdox-text']) && !isset($arguments['testdoxTextFile'])) {
             $arguments['testdoxTextFile'] = $loggingConfiguration['testdox-text'];
         }
         if ((isset($arguments['coverageClover']) || isset($arguments['reportDirectory']) || isset($arguments['coveragePHP']) || isset($arguments['coverageText'])) && extension_loaded('xdebug')) {
             $filterConfiguration = $arguments['configuration']->getFilterConfiguration();
             $arguments['addUncoveredFilesFromWhitelist'] = $filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist'];
             foreach ($filterConfiguration['blacklist']['include']['directory'] as $dir) {
                 $this->codeCoverageFilter->addDirectoryToBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']);
             }
             foreach ($filterConfiguration['blacklist']['include']['file'] as $file) {
                 $this->codeCoverageFilter->addFileToBlacklist($file);
             }
             foreach ($filterConfiguration['blacklist']['exclude']['directory'] as $dir) {
                 $this->codeCoverageFilter->removeDirectoryFromBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']);
             }
             foreach ($filterConfiguration['blacklist']['exclude']['file'] as $file) {
                 $this->codeCoverageFilter->removeFileFromBlacklist($file);
             }
             foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) {
                 $this->codeCoverageFilter->addDirectoryToWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
             }
             foreach ($filterConfiguration['whitelist']['include']['file'] as $file) {
                 $this->codeCoverageFilter->addFileToWhitelist($file);
             }
             foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) {
                 $this->codeCoverageFilter->removeDirectoryFromWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
             }
             foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) {
                 $this->codeCoverageFilter->removeFileFromWhitelist($file);
             }
         }
     }
     $arguments['addUncoveredFilesFromWhitelist'] = isset($arguments['addUncoveredFilesFromWhitelist']) ? $arguments['addUncoveredFilesFromWhitelist'] : TRUE;
     $arguments['backupGlobals'] = isset($arguments['backupGlobals']) ? $arguments['backupGlobals'] : NULL;
     $arguments['backupStaticAttributes'] = isset($arguments['backupStaticAttributes']) ? $arguments['backupStaticAttributes'] : NULL;
     $arguments['cacheTokens'] = isset($arguments['cacheTokens']) ? $arguments['cacheTokens'] : TRUE;
     $arguments['colors'] = isset($arguments['colors']) ? $arguments['colors'] : FALSE;
     $arguments['convertErrorsToExceptions'] = isset($arguments['convertErrorsToExceptions']) ? $arguments['convertErrorsToExceptions'] : TRUE;
     $arguments['convertNoticesToExceptions'] = isset($arguments['convertNoticesToExceptions']) ? $arguments['convertNoticesToExceptions'] : TRUE;
     $arguments['convertWarningsToExceptions'] = isset($arguments['convertWarningsToExceptions']) ? $arguments['convertWarningsToExceptions'] : TRUE;
     $arguments['excludeGroups'] = isset($arguments['excludeGroups']) ? $arguments['excludeGroups'] : array();
     $arguments['groups'] = isset($arguments['groups']) ? $arguments['groups'] : array();
     $arguments['logIncompleteSkipped'] = isset($arguments['logIncompleteSkipped']) ? $arguments['logIncompleteSkipped'] : FALSE;
     $arguments['processIsolation'] = isset($arguments['processIsolation']) ? $arguments['processIsolation'] : FALSE;
     $arguments['repeat'] = isset($arguments['repeat']) ? $arguments['repeat'] : FALSE;
     $arguments['reportCharset'] = isset($arguments['reportCharset']) ? $arguments['reportCharset'] : 'UTF-8';
     $arguments['reportHighlight'] = isset($arguments['reportHighlight']) ? $arguments['reportHighlight'] : FALSE;
     $arguments['reportHighLowerBound'] = isset($arguments['reportHighLowerBound']) ? $arguments['reportHighLowerBound'] : 70;
     $arguments['reportLowUpperBound'] = isset($arguments['reportLowUpperBound']) ? $arguments['reportLowUpperBound'] : 35;
     $arguments['reportYUI'] = isset($arguments['reportYUI']) ? $arguments['reportYUI'] : TRUE;
     $arguments['stopOnError'] = isset($arguments['stopOnError']) ? $arguments['stopOnError'] : FALSE;
     $arguments['stopOnFailure'] = isset($arguments['stopOnFailure']) ? $arguments['stopOnFailure'] : FALSE;
     $arguments['stopOnIncomplete'] = isset($arguments['stopOnIncomplete']) ? $arguments['stopOnIncomplete'] : FALSE;
     $arguments['stopOnSkipped'] = isset($arguments['stopOnSkipped']) ? $arguments['stopOnSkipped'] : FALSE;
     $arguments['timeoutForSmallTests'] = isset($arguments['timeoutForSmallTests']) ? $arguments['timeoutForSmallTests'] : 1;
     $arguments['timeoutForMediumTests'] = isset($arguments['timeoutForMediumTests']) ? $arguments['timeoutForMediumTests'] : 10;
     $arguments['timeoutForLargeTests'] = isset($arguments['timeoutForLargeTests']) ? $arguments['timeoutForLargeTests'] : 60;
     $arguments['strict'] = isset($arguments['strict']) ? $arguments['strict'] : FALSE;
     $arguments['verbose'] = isset($arguments['verbose']) ? $arguments['verbose'] : FALSE;
     if ($arguments['filter'] !== FALSE && preg_match('/^[a-zA-Z0-9_]/', $arguments['filter'])) {
         // Escape delimiters in regular expression. Do NOT use preg_quote,
         // to keep magic characters.
         $arguments['filter'] = '/' . str_replace('/', '\\/', $arguments['filter']) . '/';
     }
 }
Example #11
0
    /**
     * 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 #12
0
 /**
  * @param string           $filename
  * @param PHP_CodeCoverage $coverage
  */
 protected function handleConfiguration($filename, \PHP_CodeCoverage $coverage)
 {
     $filter = $coverage->filter();
     $configuration = \PHPUnit_Util_Configuration::getInstance($filename);
     $filterConfiguration = $configuration->getFilterConfiguration();
     $coverage->setAddUncoveredFilesFromWhitelist($filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist']);
     $coverage->setProcessUncoveredFilesFromWhitelist($filterConfiguration['whitelist']['processUncoveredFilesFromWhitelist']);
     foreach ($filterConfiguration['blacklist']['include']['directory'] as $dir) {
         $filter->addDirectoryToBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']);
     }
     foreach ($filterConfiguration['blacklist']['include']['file'] as $file) {
         $filter->addFileToBlacklist($file);
     }
     foreach ($filterConfiguration['blacklist']['exclude']['directory'] as $dir) {
         $filter->removeDirectoryFromBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']);
     }
     foreach ($filterConfiguration['blacklist']['exclude']['file'] as $file) {
         $filter->removeFileFromBlacklist($file);
     }
     foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) {
         $filter->addDirectoryToWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
     }
     foreach ($filterConfiguration['whitelist']['include']['file'] as $file) {
         $filter->addFileToWhitelist($file);
     }
     foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) {
         $filter->removeDirectoryFromWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
     }
     foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) {
         $filter->removeFileFromWhitelist($file);
     }
 }
Example #13
0
 /**
  * @param  array $arguments
  * @since  Method available since Release 3.2.1
  */
 protected function handleConfiguration(array &$arguments)
 {
     if (isset($arguments['configuration']) && !$arguments['configuration'] instanceof PHPUnit_Util_Configuration) {
         $arguments['configuration'] = PHPUnit_Util_Configuration::getInstance($arguments['configuration']);
     }
     $arguments['debug'] = isset($arguments['debug']) ? $arguments['debug'] : FALSE;
     $arguments['filter'] = isset($arguments['filter']) ? $arguments['filter'] : FALSE;
     $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
     $arguments['wait'] = isset($arguments['wait']) ? $arguments['wait'] : FALSE;
     if (isset($arguments['configuration'])) {
         $arguments['configuration']->handlePHPConfiguration();
         $phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration();
         if (isset($phpunitConfiguration['backupGlobals']) && !isset($arguments['backupGlobals'])) {
             $arguments['backupGlobals'] = $phpunitConfiguration['backupGlobals'];
         }
         if (isset($phpunitConfiguration['backupStaticAttributes']) && !isset($arguments['backupStaticAttributes'])) {
             $arguments['backupStaticAttributes'] = $phpunitConfiguration['backupStaticAttributes'];
         }
         if (isset($phpunitConfiguration['bootstrap']) && !isset($arguments['bootstrap'])) {
             $arguments['bootstrap'] = $phpunitConfiguration['bootstrap'];
         }
         if (isset($phpunitConfiguration['colors']) && !isset($arguments['colors'])) {
             $arguments['colors'] = $phpunitConfiguration['colors'];
         }
         if (isset($phpunitConfiguration['convertErrorsToExceptions']) && !isset($arguments['convertErrorsToExceptions'])) {
             $arguments['convertErrorsToExceptions'] = $phpunitConfiguration['convertErrorsToExceptions'];
         }
         if (isset($phpunitConfiguration['convertNoticesToExceptions']) && !isset($arguments['convertNoticesToExceptions'])) {
             $arguments['convertNoticesToExceptions'] = $phpunitConfiguration['convertNoticesToExceptions'];
         }
         if (isset($phpunitConfiguration['convertWarningsToExceptions']) && !isset($arguments['convertWarningsToExceptions'])) {
             $arguments['convertWarningsToExceptions'] = $phpunitConfiguration['convertWarningsToExceptions'];
         }
         if (isset($phpunitConfiguration['processIsolation']) && !isset($arguments['processIsolation'])) {
             $arguments['processIsolation'] = $phpunitConfiguration['processIsolation'];
         }
         if (isset($phpunitConfiguration['stopOnFailure']) && !isset($arguments['stopOnFailure'])) {
             $arguments['stopOnFailure'] = $phpunitConfiguration['stopOnFailure'];
         }
         if (isset($phpunitConfiguration['verbose']) && !isset($arguments['verbose'])) {
             $arguments['verbose'] = $phpunitConfiguration['verbose'];
         }
         $groupConfiguration = $arguments['configuration']->getGroupConfiguration();
         if (!empty($groupConfiguration['include']) && !isset($arguments['groups'])) {
             $arguments['groups'] = $groupConfiguration['include'];
         }
         if (!empty($groupConfiguration['exclude']) && !isset($arguments['excludeGroups'])) {
             $arguments['excludeGroups'] = $groupConfiguration['exclude'];
         }
         foreach ($arguments['configuration']->getListenerConfiguration() as $listener) {
             if (!class_exists($listener['class'], FALSE) && $listener['file'] !== '') {
                 $file = PHPUnit_Util_Filesystem::fileExistsInIncludePath($listener['file']);
                 if ($file !== FALSE) {
                     require $file;
                 }
             }
             if (class_exists($listener['class'], FALSE)) {
                 if (count($listener['arguments']) == 0) {
                     $listener = new $listener['class']();
                 } else {
                     $listenerClass = new ReflectionClass($listener['class']);
                     $listener = $listenerClass->newInstanceArgs($listener['arguments']);
                 }
                 if ($listener instanceof PHPUnit_Framework_TestListener) {
                     $arguments['listeners'][] = $listener;
                 }
             }
         }
         $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration();
         if (isset($loggingConfiguration['coverage-html']) && !isset($arguments['reportDirectory'])) {
             if (isset($loggingConfiguration['charset']) && !isset($arguments['reportCharset'])) {
                 $arguments['reportCharset'] = $loggingConfiguration['charset'];
             }
             if (isset($loggingConfiguration['yui']) && !isset($arguments['reportYUI'])) {
                 $arguments['reportYUI'] = $loggingConfiguration['yui'];
             }
             if (isset($loggingConfiguration['highlight']) && !isset($arguments['reportHighlight'])) {
                 $arguments['reportHighlight'] = $loggingConfiguration['highlight'];
             }
             if (isset($loggingConfiguration['lowUpperBound']) && !isset($arguments['reportLowUpperBound'])) {
                 $arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound'];
             }
             if (isset($loggingConfiguration['highLowerBound']) && !isset($arguments['reportHighLowerBound'])) {
                 $arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound'];
             }
             $arguments['reportDirectory'] = $loggingConfiguration['coverage-html'];
         }
         if (isset($loggingConfiguration['coverage-clover']) && !isset($arguments['coverageClover'])) {
             $arguments['coverageClover'] = $loggingConfiguration['coverage-clover'];
         }
         if (isset($loggingConfiguration['json']) && !isset($arguments['jsonLogfile'])) {
             $arguments['jsonLogfile'] = $loggingConfiguration['json'];
         }
         if (isset($loggingConfiguration['plain'])) {
             $arguments['listeners'][] = new PHPUnit_TextUI_ResultPrinter($loggingConfiguration['plain'], TRUE);
         }
         if (isset($loggingConfiguration['tap']) && !isset($arguments['tapLogfile'])) {
             $arguments['tapLogfile'] = $loggingConfiguration['tap'];
         }
         if (isset($loggingConfiguration['junit']) && !isset($arguments['junitLogfile'])) {
             $arguments['junitLogfile'] = $loggingConfiguration['junit'];
             if (isset($loggingConfiguration['logIncompleteSkipped']) && !isset($arguments['logIncompleteSkipped'])) {
                 $arguments['logIncompleteSkipped'] = $loggingConfiguration['logIncompleteSkipped'];
             }
         }
         if (isset($loggingConfiguration['story-html']) && !isset($arguments['storyHTMLFile'])) {
             $arguments['storyHTMLFile'] = $loggingConfiguration['story-html'];
         }
         if (isset($loggingConfiguration['story-text']) && !isset($arguments['storyTextFile'])) {
             $arguments['storsTextFile'] = $loggingConfiguration['story-text'];
         }
         if (isset($loggingConfiguration['testdox-html']) && !isset($arguments['testdoxHTMLFile'])) {
             $arguments['testdoxHTMLFile'] = $loggingConfiguration['testdox-html'];
         }
         if (isset($loggingConfiguration['testdox-text']) && !isset($arguments['testdoxTextFile'])) {
             $arguments['testdoxTextFile'] = $loggingConfiguration['testdox-text'];
         }
     }
     if (isset($arguments['configuration'])) {
         $filterConfiguration = $arguments['configuration']->getFilterConfiguration();
         $filter = PHP_CodeCoverage_Filter::getInstance();
         foreach ($filterConfiguration['blacklist']['include']['directory'] as $dir) {
             $filter->addDirectoryToBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']);
         }
         foreach ($filterConfiguration['blacklist']['include']['file'] as $file) {
             $filter->addFileToBlacklist($file);
         }
         foreach ($filterConfiguration['blacklist']['exclude']['directory'] as $dir) {
             $filter->removeDirectoryFromBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']);
         }
         foreach ($filterConfiguration['blacklist']['exclude']['file'] as $file) {
             $filter->removeFileFromBlacklist($file);
         }
         if ((isset($arguments['coverageClover']) || isset($arguments['reportDirectory'])) && extension_loaded('xdebug')) {
             PHP_CodeCoverage::getInstance()->setProcessUncoveredFilesFromWhitelist($filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist']);
             foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) {
                 $filter->addDirectoryToWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
             }
             foreach ($filterConfiguration['whitelist']['include']['file'] as $file) {
                 $filter->addFileToWhitelist($file);
             }
             foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) {
                 $filter->removeDirectoryFromWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
             }
             foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) {
                 $filter->removeFileFromWhitelist($file);
             }
         }
     }
     $arguments['backupGlobals'] = isset($arguments['backupGlobals']) ? $arguments['backupGlobals'] : NULL;
     $arguments['backupStaticAttributes'] = isset($arguments['backupStaticAttributes']) ? $arguments['backupStaticAttributes'] : NULL;
     $arguments['colors'] = isset($arguments['colors']) ? $arguments['colors'] : FALSE;
     $arguments['convertErrorsToExceptions'] = isset($arguments['convertErrorsToExceptions']) ? $arguments['convertErrorsToExceptions'] : TRUE;
     $arguments['convertNoticesToExceptions'] = isset($arguments['convertNoticesToExceptions']) ? $arguments['convertNoticesToExceptions'] : TRUE;
     $arguments['convertWarningsToExceptions'] = isset($arguments['convertWarningsToExceptions']) ? $arguments['convertWarningsToExceptions'] : TRUE;
     $arguments['excludeGroups'] = isset($arguments['excludeGroups']) ? $arguments['excludeGroups'] : array();
     $arguments['groups'] = isset($arguments['groups']) ? $arguments['groups'] : array();
     $arguments['logIncompleteSkipped'] = isset($arguments['logIncompleteSkipped']) ? $arguments['logIncompleteSkipped'] : FALSE;
     $arguments['processIsolation'] = isset($arguments['processIsolation']) ? $arguments['processIsolation'] : FALSE;
     $arguments['reportCharset'] = isset($arguments['reportCharset']) ? $arguments['reportCharset'] : 'ISO-8859-1';
     $arguments['reportHighlight'] = isset($arguments['reportHighlight']) ? $arguments['reportHighlight'] : FALSE;
     $arguments['reportHighLowerBound'] = isset($arguments['reportHighLowerBound']) ? $arguments['reportHighLowerBound'] : 70;
     $arguments['reportLowUpperBound'] = isset($arguments['reportLowUpperBound']) ? $arguments['reportLowUpperBound'] : 35;
     $arguments['reportYUI'] = isset($arguments['reportYUI']) ? $arguments['reportYUI'] : TRUE;
     $arguments['stopOnFailure'] = isset($arguments['stopOnFailure']) ? $arguments['stopOnFailure'] : FALSE;
     $arguments['verbose'] = isset($arguments['verbose']) ? $arguments['verbose'] : FALSE;
     if ($arguments['filter'] !== FALSE && preg_match('/^[a-zA-Z0-9_]/', $arguments['filter'])) {
         $arguments['filter'] = '/' . $arguments['filter'] . '/';
     }
 }
Example #14
0
 /**
  * Run Both Unit-test and Code-coverage analysist
  *
  * @param  string Path to Test (Juriya idiomatic style directory structure is required)
  * @return stream
  */
 public static function runTest($target = '')
 {
     $paths = explode(PATH_SEPARATOR, get_include_path());
     $pwd = $_SERVER['PWD'];
     if (!$target) {
         self::out('--test command missed target folder');
     } else {
         // Find configuration definition
         $configuration = '';
         $configurationExists = FALSE;
         if (file_exists($pwd . DIRECTORY_SEPARATOR . 'phpunit.xml')) {
             $configuration = $pwd . DIRECTORY_SEPARATOR . 'phpunit.xml';
             $configurationExists = TRUE;
         } elseif (($path = $pwd . DIRECTORY_SEPARATOR . $target) && is_dir($path)) {
             if (($testSrc = $path . DIRECTORY_SEPARATOR . 'Tests') && is_dir($testSrc)) {
                 $configuration = $testSrc . DIRECTORY_SEPARATOR . 'phpunit.xml';
             }
         } else {
             foreach ($paths as $path) {
                 if (($testSrc = $path . DIRECTORY_SEPARATOR . $target . DIRECTORY_SEPARATOR . 'Tests') && is_dir($testSrc)) {
                     $configuration = $testSrc . DIRECTORY_SEPARATOR . 'phpunit.xml';
                     break 1;
                 }
             }
         }
         // Garbage collection
         $coveragePhp = '/tmp/coverage.php';
         file_exists($coveragePhp) and File::delete($coveragePhp);
         // Try to read the configuration
         try {
             $configurationInstance = \PHPUnit_Util_Configuration::getInstance($configuration);
         } catch (\Exception $e) {
             print $e->getMessage() . "\n";
             exit(\PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
         }
         $configurationArray = $configurationInstance->getPHPUnitConfiguration();
         // Validate test suites before start processing furthermore
         $testDirectory = new \DirectoryIterator(str_replace('phpunit.xml', '', $configuration));
         $validTestSuite = FALSE;
         while ($testDirectory->valid()) {
             if ($testDirectory->isFile() && strpos($testDirectory->getFilename(), 'Test.php') !== FALSE) {
                 $validTestSuite = TRUE;
             }
             $testDirectory->next();
         }
         if (!$validTestSuite) {
             $errorText = 'ERROR: ' . I18n::translate('command_testsuite_not_found');
             if ($configurationArray['colors'] === TRUE) {
                 $errorText = Utility::getColoredString($errorText, 'black', 'red');
             }
             self::out($errorText);
             exit(\PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
         }
         // Reset server arguments
         $_SERVER['argv'] = array('--configuration', $configuration, '--coverage-php', $coveragePhp);
         // Preparing reports
         $strippedText = 'Generating code coverage report in PHP format ... done';
         $reportTestTitle = 'PHPUnit Report : ';
         self::out($configurationArray['colors'] ? Utility::getColoredString($reportTestTitle, 'yellow') : $reportTestTitle);
         $reportCcTitle = 'CodeCoverage Report : ';
         $reportCcTitle = $configurationArray['colors'] ? Utility::getColoredString($reportCcTitle, 'yellow') : $reportCcTitle;
         // Get phpunit report
         ob_start();
         $exitCode = \PHPUnit_TextUI_Command::main(FALSE);
         $out = ob_get_clean();
         $report = substr($out, strpos($out, "\n\n") + 1);
         $unitTestReport = str_replace($strippedText, $reportCcTitle, $report);
         $codeCoverage = @unserialize(File::read($coveragePhp));
         $codeCoverageData = $codeCoverage->getData();
         $codeCoverageRoot = $codeCoverage->getReport();
         $codeCoverageNodes = $codeCoverageRoot->getChildNodes();
         // Generate code coverage report
         $classCoverage = array();
         $overallCoverage = array('totalClasses' => 0, 'totalCoveredClasses' => 0, 'totalMethods' => 0, 'totalCoveredMethods' => 0, 'totalLines' => 0, 'totalCoveredLines' => 0);
         // Closure for calculate the level
         $calculate = function ($percentages) {
             $level = 'gray';
             if ($percentages >= 75) {
                 $level = 'green';
             } elseif ($percentages < 75 && $percentages >= 50) {
                 $level = 'yellow';
             } elseif ($percentages < 50 && $percentages >= 25) {
                 $level = 'magenta';
             } else {
                 $level = 'red';
             }
             return $level;
         };
         $collectFromNode = function ($node) {
             $classes = array_merge($node->getClasses(), $node->getTraits());
             $coverage = $node->getCoverageData();
             $lines = array();
             $ignoredLines = $node->getIgnoredLines();
             foreach ($classes as $className => $class) {
                 $classStatements = 0;
                 $coveredClassStatements = 0;
                 $coveredMethods = 0;
                 foreach ($class['methods'] as $methodName => $method) {
                     $methodCount = 0;
                     $methodLines = 0;
                     $methodLinesCovered = 0;
                     for ($z = $method['startLine']; $z <= $method['endLine']; $z++) {
                         if (isset($ignoredLines[$z])) {
                             continue;
                         }
                         $add = TRUE;
                         $count = 0;
                         if (isset($coverage[$z])) {
                             if ($coverage[$z] !== NULL) {
                                 $classStatements++;
                                 $methodLines++;
                             } else {
                                 $add = FALSE;
                             }
                             $count = count($coverage[$z]);
                             if ($count > 0) {
                                 $coveredClassStatements++;
                                 $methodLinesCovered++;
                             }
                         } else {
                             $add = FALSE;
                         }
                         $methodCount = max($methodCount, $count);
                         if ($add) {
                             $lines[$z] = array('count' => $count, 'type' => 'stmt');
                         }
                     }
                     if ($methodCount > 0) {
                         $coveredMethods++;
                     }
                 }
                 if (!empty($class['package']['namespace'])) {
                     $namespace = '\\' . $class['package']['namespace'] . '\\';
                 } elseif (!empty($class['package']['fullPackage'])) {
                     $namespace = '@' . $class['package']['fullPackage'] . '\\';
                 } else {
                     $namespace = '';
                 }
                 return array('namespace' => $namespace, 'className' => $className, 'methodsCovered' => $coveredMethods, 'methodCount' => count($class['methods']), 'statementsCovered' => $coveredClassStatements, 'statementCount' => $classStatements);
             }
         };
         for ($i = 0, $max = count($codeCoverageNodes); $i < $max; $i++) {
             $item = $codeCoverageNodes[$i];
             if ($item instanceof \PHP_CodeCoverage_Report_Node_File) {
                 array_push($classCoverage, $collectFromNode($item));
             } elseif ($item instanceof \PHP_CodeCoverage_Report_Node_Directory) {
                 foreach ($item->getChildNodes() as $itemNode) {
                     array_push($classCoverage, $collectFromNode($itemNode));
                 }
             } else {
                 continue;
             }
         }
         ksort($classCoverage);
         $codeCoverageReport = '';
         for ($x = 0, $max = count($classCoverage); $x < $max; $x++) {
             $classInfo = $classCoverage[$x];
             $fullQualifiedPath = $classInfo['namespace'] . $classInfo['className'];
             if ($classInfo['statementsCovered'] != 0) {
                 // Increase overallCoverage
                 $overallCoverage['totalClasses']++;
                 $overallCoverage['totalMethods'] = $overallCoverage['totalMethods'] + $classInfo['methodCount'];
                 $overallCoverage['totalCoveredMethods'] = $overallCoverage['totalCoveredMethods'] + $classInfo['methodsCovered'];
                 $overallCoverage['totalLines'] = $overallCoverage['totalLines'] + $classInfo['statementCount'];
                 $overallCoverage['totalCoveredLines'] = $overallCoverage['totalCoveredLines'] + $classInfo['statementsCovered'];
                 // Build item Code-coverage main report
                 $ccPath = $fullQualifiedPath;
                 $ccMethods = str_pad(' Methods(' . $classInfo['methodsCovered'] . '/' . $classInfo['methodCount'] . ')', 18, ' ');
                 $ccLines = str_pad(' Lines(' . $classInfo['statementsCovered'] . '/' . $classInfo['statementCount'] . ')', 18, ' ');
                 // Calculate the percentage
                 $ccMethodsPercentages = round((int) $classInfo['methodsCovered'] / (int) $classInfo['methodCount'] * 100, 2);
                 $ccLinesPercentages = round((int) $classInfo['statementsCovered'] / (int) $classInfo['statementCount'] * 100, 2);
                 // Normalize the pad
                 $ccMethodsPercentagesText = $ccMethods . ': ' . str_pad($ccMethodsPercentages . '% ', 8, ' ', STR_PAD_LEFT);
                 $ccLinesPercentagesText = $ccLines . ': ' . str_pad($ccLinesPercentages . '% ', 8, ' ', STR_PAD_LEFT);
                 // Increase classed covered for 100% classes
                 if ($ccMethodsPercentages == 100 && $ccLinesPercentages == 100) {
                     $overallCoverage['totalCoveredClasses']++;
                 }
                 // Colorize if necessary
                 if ($configurationArray['colors'] === TRUE) {
                     $ccPath = Utility::getColoredString($ccPath, 'light_cyan');
                     $ccMethodsLevel = $calculate($ccMethodsPercentages);
                     $ccLinesLevel = $calculate($ccLinesPercentages);
                     $ccMethodsPercentagesText = Utility::getColoredString($ccMethodsPercentagesText, 'black', $ccMethodsLevel);
                     $ccLinesPercentagesText = Utility::getColoredString($ccLinesPercentagesText, 'black', $ccLinesLevel);
                 }
                 $codeCoverageReport .= PHP_EOL . $ccPath . PHP_EOL . $ccMethodsPercentagesText . PHP_EOL . $ccLinesPercentagesText . PHP_EOL;
             }
         }
         // Finalize Code-coverage report
         if ($overallCoverage['totalCoveredClasses'] > 0) {
             $overallPercentage = round((int) $overallCoverage['totalCoveredClasses'] / (int) $overallCoverage['totalClasses'] * 100, 2);
         } else {
             $overallPercentage = 0;
         }
         if ($overallPercentage >= 75) {
             $overallPercentageText = 'OK';
         } elseif ($overallPercentage < 75 && $overallPercentage >= 50) {
             $overallPercentageText = 'MEDIUM';
         } else {
             $overallPercentageText = 'LOW';
         }
         $overallCoverageReport = $overallPercentageText . ' (';
         $overallCoverageReport .= $overallPercentage;
         $overallCoverageReport .= '% classes, ';
         if ($overallCoverage['totalCoveredMethods'] > 0) {
             $overallCoverageReport .= round((int) $overallCoverage['totalCoveredMethods'] / (int) $overallCoverage['totalMethods'] * 100, 2);
         } else {
             $overallCoverageReport .= 0;
         }
         $overallCoverageReport .= '% methods, ';
         if ($overallCoverage['totalCoveredLines'] > 0) {
             $overallCoverageReport .= round((int) $overallCoverage['totalCoveredLines'] / (int) $overallCoverage['totalLines'] * 100, 2);
         } else {
             $overallCoverageReport .= 0;
         }
         $overallCoverageReport .= '% lines were covered)';
         // Colorize if necessary
         if ($configurationArray['colors'] === TRUE) {
             $coverageStatus = $calculate($overallPercentage);
             $overallCoverageReport = Utility::getColoredString($overallCoverageReport, 'black', $coverageStatus);
         }
         $codeCoverageReport .= PHP_EOL . $overallCoverageReport . PHP_EOL;
         // Output all tests reports
         self::out($unitTestReport . $codeCoverageReport);
         exit($exitCode);
     }
 }
 /**
  * (non-PHPdoc)
  *
  * @see \SK\ITCBundle\Controller\FilesystemController::getModel()
  */
 protected function getModel()
 {
     $model = parent::getModel();
     $model = $model['model'];
     $bundlesPhpunit = array();
     foreach ($model['bundles'] as $id => $bundle) {
         $bundlePhpUnitFile = sprintf("%s/%s", $bundle->getPath(), "phpunit.xml");
         $bundlePhpUnitInfo = new \SplFileInfo($bundlePhpUnitFile);
         $bundlesPhpunit[$bundle->getName()] = $bundlePhpUnitInfo;
     }
     $model['bundlesPhpunit'] = $bundlesPhpunit;
     $phpunit = sprintf("%s/%s", $model['path'], "phpunit.xml");
     $bundle = $model['bundle'];
     if (NULL != $bundle) {
         $phpunit = sprintf("%s/%s", $bundle->getPath(), "phpunit.xml");
     }
     if (is_file($phpunit)) {
         $configuration = \PHPUnit_Util_Configuration::getInstance($phpunit);
         $configuration->handlePHPConfiguration();
         $groups = $configuration->getTestSuiteConfiguration()->getGroupDetails();
         $model['configuration'] = $configuration;
         $model['groups'] = $groups;
         $model['group'] = $this->getRequest()->get('group', NULL);
         $model['suite'] = $this->getRequest()->get('suite', NULL);
         $model['test'] = $this->getRequest()->get('test', NULL);
         $model['case'] = $this->getRequest()->get('case', NULL);
         $model['phpunit'] = $phpunit;
         // $geshi = new \GeSHi(file_get_contents($phpunit), 'xml');
         // $geshi->parse_code();
     }
     return array('model' => $model);
 }
Example #16
0
 /**
  * Load and processes the PHPUnit configuration
  * @param $configuration
  * @throws BuildException
  * @return array
  */
 protected function handlePHPUnitConfiguration($configuration)
 {
     if (!$configuration->exists()) {
         throw new BuildException("Unable to find PHPUnit configuration file '" . (string) $configuration . "'");
     }
     $config = PHPUnit_Util_Configuration::getInstance($configuration->getAbsolutePath());
     if (empty($config)) {
         return;
     }
     $phpunit = $config->getPHPUnitConfiguration();
     if (empty($phpunit)) {
         return;
     }
     $config->handlePHPConfiguration();
     if (isset($phpunit['bootstrap'])) {
         $this->setBootstrap($phpunit['bootstrap']);
     }
     if (isset($phpunit['stopOnFailure'])) {
         $this->setHaltonfailure($phpunit['stopOnFailure']);
     }
     if (isset($phpunit['stopOnError'])) {
         $this->setHaltonerror($phpunit['stopOnError']);
     }
     if (isset($phpunit['stopOnSkipped'])) {
         $this->setHaltonskipped($phpunit['stopOnSkipped']);
     }
     if (isset($phpunit['stopOnIncomplete'])) {
         $this->setHaltonincomplete($phpunit['stopOnIncomplete']);
     }
     if (isset($phpunit['processIsolation'])) {
         $this->setProcessIsolation($phpunit['processIsolation']);
     }
     $browsers = $config->getSeleniumBrowserConfiguration();
     if (!empty($browsers) && class_exists('PHPUnit_Extensions_SeleniumTestCase')) {
         PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers;
     }
     return $phpunit;
 }
Example #17
0
 public function getTestsFromConfig(\PHPUnit_Util_Configuration $config)
 {
     return $this->enumerateTests($config->getTestSuiteConfiguration());
 }
Example #18
0
#!/usr/bin/env php
<?php 
chdir(__DIR__);
$returnStatus = null;
passthru('composer install', $returnStatus);
if ($returnStatus !== 0) {
    exit(1);
}
require 'vendor/autoload.php';
$phpcsCLI = new PHP_CodeSniffer_CLI();
$phpcsArguments = ['standard' => ['PSR1'], 'files' => ['src', 'tests', 'build.php'], 'warningSeverity' => 0];
$phpcsViolations = $phpcsCLI->process($phpcsArguments);
if ($phpcsViolations > 0) {
    exit(1);
}
$phpunitConfiguration = PHPUnit_Util_Configuration::getInstance(__DIR__ . '/phpunit.xml');
$phpunitArguments = ['coverageHtml' => __DIR__ . '/coverage', 'configuration' => $phpunitConfiguration];
$testRunner = new PHPUnit_TextUI_TestRunner();
$result = $testRunner->doRun($phpunitConfiguration->getTestSuiteConfiguration(), $phpunitArguments);
if (!$result->wasSuccessful()) {
    exit(1);
}
$cloverCoverage = new PHP_CodeCoverage_Report_Clover();
file_put_contents('clover.xml', $cloverCoverage->process($result->getCodeCoverage()));
$coverageFactory = new PHP_CodeCoverage_Report_Factory();
$coverageReport = $coverageFactory->create($result->getCodeCoverage());
if ($coverageReport->getNumExecutedLines() !== $coverageReport->getNumExecutableLines()) {
    file_put_contents('php://stderr', "Code coverage was NOT 100%\n");
    exit(1);
}
echo "Code coverage was 100%\n";
Example #19
0
 /**
  * Load configuration from file
  *
  * @param string $fileName
  * @return Configuration
  */
 public static function loadConfig($fileName)
 {
     return Configuration::getInstance($fileName);
 }
Example #20
0
 /**
  * @expectedException PHPUnit_Framework_Exception
  */
 public function testExceptionIsThrownForNotExistingConfigurationFile()
 {
     PHPUnit_Util_Configuration::getInstance('not_existing_file.xml');
 }
Example #21
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);
     }
 }
 /**
  * @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;
 }
Example #23
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);
     }
 }
 /**
  * @param array $arguments
  * @since  Method available since Release 3.2.1
  */
 protected function handleConfiguration(array &$arguments)
 {
     if (isset($arguments['configuration']) && !$arguments['configuration'] instanceof PHPUnit_Util_Configuration) {
         $arguments['configuration'] = PHPUnit_Util_Configuration::getInstance($arguments['configuration']);
     }
     $arguments['debug'] = isset($arguments['debug']) ? $arguments['debug'] : false;
     $arguments['filter'] = isset($arguments['filter']) ? $arguments['filter'] : false;
     $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
     if (isset($arguments['configuration'])) {
         $arguments['configuration']->handlePHPConfiguration();
         $phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration();
         if (isset($phpunitConfiguration['deprecatedStrictModeSetting'])) {
             $arguments['deprecatedStrictModeSetting'] = true;
         }
         if (isset($phpunitConfiguration['backupGlobals']) && !isset($arguments['backupGlobals'])) {
             $arguments['backupGlobals'] = $phpunitConfiguration['backupGlobals'];
         }
         if (isset($phpunitConfiguration['backupStaticAttributes']) && !isset($arguments['backupStaticAttributes'])) {
             $arguments['backupStaticAttributes'] = $phpunitConfiguration['backupStaticAttributes'];
         }
         if (isset($phpunitConfiguration['disallowChangesToGlobalState']) && !isset($arguments['disallowChangesToGlobalState'])) {
             $arguments['disallowChangesToGlobalState'] = $phpunitConfiguration['disallowChangesToGlobalState'];
         }
         if (isset($phpunitConfiguration['bootstrap']) && !isset($arguments['bootstrap'])) {
             $arguments['bootstrap'] = $phpunitConfiguration['bootstrap'];
         }
         if (isset($phpunitConfiguration['cacheTokens']) && !isset($arguments['cacheTokens'])) {
             $arguments['cacheTokens'] = $phpunitConfiguration['cacheTokens'];
         }
         if (isset($phpunitConfiguration['colors']) && !isset($arguments['colors'])) {
             $arguments['colors'] = $phpunitConfiguration['colors'];
         }
         if (isset($phpunitConfiguration['convertErrorsToExceptions']) && !isset($arguments['convertErrorsToExceptions'])) {
             $arguments['convertErrorsToExceptions'] = $phpunitConfiguration['convertErrorsToExceptions'];
         }
         if (isset($phpunitConfiguration['convertNoticesToExceptions']) && !isset($arguments['convertNoticesToExceptions'])) {
             $arguments['convertNoticesToExceptions'] = $phpunitConfiguration['convertNoticesToExceptions'];
         }
         if (isset($phpunitConfiguration['convertWarningsToExceptions']) && !isset($arguments['convertWarningsToExceptions'])) {
             $arguments['convertWarningsToExceptions'] = $phpunitConfiguration['convertWarningsToExceptions'];
         }
         if (isset($phpunitConfiguration['processIsolation']) && !isset($arguments['processIsolation'])) {
             $arguments['processIsolation'] = $phpunitConfiguration['processIsolation'];
         }
         if (isset($phpunitConfiguration['stopOnFailure']) && !isset($arguments['stopOnFailure'])) {
             $arguments['stopOnFailure'] = $phpunitConfiguration['stopOnFailure'];
         }
         if (isset($phpunitConfiguration['timeoutForSmallTests']) && !isset($arguments['timeoutForSmallTests'])) {
             $arguments['timeoutForSmallTests'] = $phpunitConfiguration['timeoutForSmallTests'];
         }
         if (isset($phpunitConfiguration['timeoutForMediumTests']) && !isset($arguments['timeoutForMediumTests'])) {
             $arguments['timeoutForMediumTests'] = $phpunitConfiguration['timeoutForMediumTests'];
         }
         if (isset($phpunitConfiguration['timeoutForLargeTests']) && !isset($arguments['timeoutForLargeTests'])) {
             $arguments['timeoutForLargeTests'] = $phpunitConfiguration['timeoutForLargeTests'];
         }
         if (isset($phpunitConfiguration['reportUselessTests']) && !isset($arguments['reportUselessTests'])) {
             $arguments['reportUselessTests'] = $phpunitConfiguration['reportUselessTests'];
         }
         if (isset($phpunitConfiguration['strictCoverage']) && !isset($arguments['strictCoverage'])) {
             $arguments['strictCoverage'] = $phpunitConfiguration['strictCoverage'];
         }
         if (isset($phpunitConfiguration['disallowTestOutput']) && !isset($arguments['disallowTestOutput'])) {
             $arguments['disallowTestOutput'] = $phpunitConfiguration['disallowTestOutput'];
         }
         if (isset($phpunitConfiguration['enforceTimeLimit']) && !isset($arguments['enforceTimeLimit'])) {
             $arguments['enforceTimeLimit'] = $phpunitConfiguration['enforceTimeLimit'];
         }
         if (isset($phpunitConfiguration['disallowTodoAnnotatedTests']) && !isset($arguments['disallowTodoAnnotatedTests'])) {
             $arguments['disallowTodoAnnotatedTests'] = $phpunitConfiguration['disallowTodoAnnotatedTests'];
         }
         if (isset($phpunitConfiguration['verbose']) && !isset($arguments['verbose'])) {
             $arguments['verbose'] = $phpunitConfiguration['verbose'];
         }
         if (isset($phpunitConfiguration['forceCoversAnnotation']) && !isset($arguments['forceCoversAnnotation'])) {
             $arguments['forceCoversAnnotation'] = $phpunitConfiguration['forceCoversAnnotation'];
         }
         if (isset($phpunitConfiguration['mapTestClassNameToCoveredClassName']) && !isset($arguments['mapTestClassNameToCoveredClassName'])) {
             $arguments['mapTestClassNameToCoveredClassName'] = $phpunitConfiguration['mapTestClassNameToCoveredClassName'];
         }
         $groupCliArgs = array();
         if (!empty($arguments['groups'])) {
             $groupCliArgs = $arguments['groups'];
         }
         $groupConfiguration = $arguments['configuration']->getGroupConfiguration();
         if (!empty($groupConfiguration['include']) && !isset($arguments['groups'])) {
             $arguments['groups'] = $groupConfiguration['include'];
         }
         if (!empty($groupConfiguration['exclude']) && !isset($arguments['excludeGroups'])) {
             $arguments['excludeGroups'] = array_diff($groupConfiguration['exclude'], $groupCliArgs);
         }
         foreach ($arguments['configuration']->getListenerConfiguration() as $listener) {
             if (!class_exists($listener['class'], false) && $listener['file'] !== '') {
                 require_once $listener['file'];
             }
             if (class_exists($listener['class'])) {
                 if (count($listener['arguments']) == 0) {
                     $listener = new $listener['class']();
                 } else {
                     $listenerClass = new ReflectionClass($listener['class']);
                     $listener = $listenerClass->newInstanceArgs($listener['arguments']);
                 }
                 if ($listener instanceof PHPUnit_Framework_TestListener) {
                     $arguments['listeners'][] = $listener;
                 }
             }
         }
         $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration();
         if (isset($loggingConfiguration['coverage-clover']) && !isset($arguments['coverageClover'])) {
             $arguments['coverageClover'] = $loggingConfiguration['coverage-clover'];
         }
         if (isset($loggingConfiguration['coverage-crap4j']) && !isset($arguments['coverageCrap4J'])) {
             $arguments['coverageCrap4J'] = $loggingConfiguration['coverage-crap4j'];
         }
         if (isset($loggingConfiguration['coverage-html']) && !isset($arguments['coverageHtml'])) {
             if (isset($loggingConfiguration['lowUpperBound']) && !isset($arguments['reportLowUpperBound'])) {
                 $arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound'];
             }
             if (isset($loggingConfiguration['highLowerBound']) && !isset($arguments['reportHighLowerBound'])) {
                 $arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound'];
             }
             $arguments['coverageHtml'] = $loggingConfiguration['coverage-html'];
         }
         if (isset($loggingConfiguration['coverage-php']) && !isset($arguments['coveragePHP'])) {
             $arguments['coveragePHP'] = $loggingConfiguration['coverage-php'];
         }
         if (isset($loggingConfiguration['coverage-text']) && !isset($arguments['coverageText'])) {
             $arguments['coverageText'] = $loggingConfiguration['coverage-text'];
             if (isset($loggingConfiguration['coverageTextShowUncoveredFiles'])) {
                 $arguments['coverageTextShowUncoveredFiles'] = $loggingConfiguration['coverageTextShowUncoveredFiles'];
             } else {
                 $arguments['coverageTextShowUncoveredFiles'] = false;
             }
             if (isset($loggingConfiguration['coverageTextShowOnlySummary'])) {
                 $arguments['coverageTextShowOnlySummary'] = $loggingConfiguration['coverageTextShowOnlySummary'];
             } else {
                 $arguments['coverageTextShowOnlySummary'] = false;
             }
         }
         if (isset($loggingConfiguration['coverage-xml']) && !isset($arguments['coverageXml'])) {
             $arguments['coverageXml'] = $loggingConfiguration['coverage-xml'];
         }
         if (isset($loggingConfiguration['json']) && !isset($arguments['jsonLogfile'])) {
             $arguments['jsonLogfile'] = $loggingConfiguration['json'];
         }
         if (isset($loggingConfiguration['plain'])) {
             $arguments['listeners'][] = new PHPUnit_TextUI_ResultPrinter($loggingConfiguration['plain'], true);
         }
         if (isset($loggingConfiguration['tap']) && !isset($arguments['tapLogfile'])) {
             $arguments['tapLogfile'] = $loggingConfiguration['tap'];
         }
         if (isset($loggingConfiguration['junit']) && !isset($arguments['junitLogfile'])) {
             $arguments['junitLogfile'] = $loggingConfiguration['junit'];
             if (isset($loggingConfiguration['logIncompleteSkipped']) && !isset($arguments['logIncompleteSkipped'])) {
                 $arguments['logIncompleteSkipped'] = $loggingConfiguration['logIncompleteSkipped'];
             }
         }
         if (isset($loggingConfiguration['testdox-html']) && !isset($arguments['testdoxHTMLFile'])) {
             $arguments['testdoxHTMLFile'] = $loggingConfiguration['testdox-html'];
         }
         if (isset($loggingConfiguration['testdox-text']) && !isset($arguments['testdoxTextFile'])) {
             $arguments['testdoxTextFile'] = $loggingConfiguration['testdox-text'];
         }
         if ((isset($arguments['coverageClover']) || isset($arguments['coverageCrap4J']) || isset($arguments['coverageHtml']) || isset($arguments['coveragePHP']) || isset($arguments['coverageText']) || isset($arguments['coverageXml'])) && $this->runtime->canCollectCodeCoverage()) {
             $filterConfiguration = $arguments['configuration']->getFilterConfiguration();
             $arguments['addUncoveredFilesFromWhitelist'] = $filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist'];
             $arguments['processUncoveredFilesFromWhitelist'] = $filterConfiguration['whitelist']['processUncoveredFilesFromWhitelist'];
             if (empty($filterConfiguration['whitelist']['include']['directory']) && empty($filterConfiguration['whitelist']['include']['file'])) {
                 foreach ($filterConfiguration['blacklist']['include']['directory'] as $dir) {
                     $this->codeCoverageFilter->addDirectoryToBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']);
                 }
                 foreach ($filterConfiguration['blacklist']['include']['file'] as $file) {
                     $this->codeCoverageFilter->addFileToBlacklist($file);
                 }
                 foreach ($filterConfiguration['blacklist']['exclude']['directory'] as $dir) {
                     $this->codeCoverageFilter->removeDirectoryFromBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']);
                 }
                 foreach ($filterConfiguration['blacklist']['exclude']['file'] as $file) {
                     $this->codeCoverageFilter->removeFileFromBlacklist($file);
                 }
             }
             foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) {
                 $this->codeCoverageFilter->addDirectoryToWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
             }
             foreach ($filterConfiguration['whitelist']['include']['file'] as $file) {
                 $this->codeCoverageFilter->addFileToWhitelist($file);
             }
             foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) {
                 $this->codeCoverageFilter->removeDirectoryFromWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
             }
             foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) {
                 $this->codeCoverageFilter->removeFileFromWhitelist($file);
             }
         }
     }
     $arguments['addUncoveredFilesFromWhitelist'] = isset($arguments['addUncoveredFilesFromWhitelist']) ? $arguments['addUncoveredFilesFromWhitelist'] : true;
     $arguments['processUncoveredFilesFromWhitelist'] = isset($arguments['processUncoveredFilesFromWhitelist']) ? $arguments['processUncoveredFilesFromWhitelist'] : false;
     $arguments['backupGlobals'] = isset($arguments['backupGlobals']) ? $arguments['backupGlobals'] : null;
     $arguments['backupStaticAttributes'] = isset($arguments['backupStaticAttributes']) ? $arguments['backupStaticAttributes'] : null;
     $arguments['disallowChangesToGlobalState'] = isset($arguments['disallowChangesToGlobalState']) ? $arguments['disallowChangesToGlobalState'] : null;
     $arguments['cacheTokens'] = isset($arguments['cacheTokens']) ? $arguments['cacheTokens'] : false;
     $arguments['columns'] = isset($arguments['columns']) ? $arguments['columns'] : 80;
     $arguments['colors'] = isset($arguments['colors']) ? $arguments['colors'] : PHPUnit_TextUI_ResultPrinter::COLOR_DEFAULT;
     $arguments['convertErrorsToExceptions'] = isset($arguments['convertErrorsToExceptions']) ? $arguments['convertErrorsToExceptions'] : true;
     $arguments['convertNoticesToExceptions'] = isset($arguments['convertNoticesToExceptions']) ? $arguments['convertNoticesToExceptions'] : true;
     $arguments['convertWarningsToExceptions'] = isset($arguments['convertWarningsToExceptions']) ? $arguments['convertWarningsToExceptions'] : true;
     $arguments['excludeGroups'] = isset($arguments['excludeGroups']) ? $arguments['excludeGroups'] : array();
     $arguments['groups'] = isset($arguments['groups']) ? $arguments['groups'] : array();
     $arguments['logIncompleteSkipped'] = isset($arguments['logIncompleteSkipped']) ? $arguments['logIncompleteSkipped'] : false;
     $arguments['processIsolation'] = isset($arguments['processIsolation']) ? $arguments['processIsolation'] : false;
     $arguments['repeat'] = isset($arguments['repeat']) ? $arguments['repeat'] : false;
     $arguments['reportHighLowerBound'] = isset($arguments['reportHighLowerBound']) ? $arguments['reportHighLowerBound'] : 90;
     $arguments['reportLowUpperBound'] = isset($arguments['reportLowUpperBound']) ? $arguments['reportLowUpperBound'] : 50;
     $arguments['stopOnError'] = isset($arguments['stopOnError']) ? $arguments['stopOnError'] : false;
     $arguments['stopOnFailure'] = isset($arguments['stopOnFailure']) ? $arguments['stopOnFailure'] : false;
     $arguments['stopOnIncomplete'] = isset($arguments['stopOnIncomplete']) ? $arguments['stopOnIncomplete'] : false;
     $arguments['stopOnRisky'] = isset($arguments['stopOnRisky']) ? $arguments['stopOnRisky'] : false;
     $arguments['stopOnSkipped'] = isset($arguments['stopOnSkipped']) ? $arguments['stopOnSkipped'] : false;
     $arguments['timeoutForSmallTests'] = isset($arguments['timeoutForSmallTests']) ? $arguments['timeoutForSmallTests'] : 1;
     $arguments['timeoutForMediumTests'] = isset($arguments['timeoutForMediumTests']) ? $arguments['timeoutForMediumTests'] : 10;
     $arguments['timeoutForLargeTests'] = isset($arguments['timeoutForLargeTests']) ? $arguments['timeoutForLargeTests'] : 60;
     $arguments['reportUselessTests'] = isset($arguments['reportUselessTests']) ? $arguments['reportUselessTests'] : false;
     $arguments['strictCoverage'] = isset($arguments['strictCoverage']) ? $arguments['strictCoverage'] : false;
     $arguments['disallowTestOutput'] = isset($arguments['disallowTestOutput']) ? $arguments['disallowTestOutput'] : false;
     $arguments['enforceTimeLimit'] = isset($arguments['enforceTimeLimit']) ? $arguments['enforceTimeLimit'] : false;
     $arguments['disallowTodoAnnotatedTests'] = isset($arguments['disallowTodoAnnotatedTests']) ? $arguments['disallowTodoAnnotatedTests'] : false;
     $arguments['verbose'] = isset($arguments['verbose']) ? $arguments['verbose'] : false;
 }
 /**
  * Load and processes the PHPUnit configuration
  *
  * @param $configuration
  *
  * @throws BuildException
  * @return array
  */
 protected function handlePHPUnitConfiguration($configuration)
 {
     if (!$configuration->exists()) {
         throw new BuildException("Unable to find PHPUnit configuration file '" . (string) $configuration . "'");
     }
     $config = PHPUnit_Util_Configuration::getInstance($configuration->getAbsolutePath());
     if (empty($config)) {
         return;
     }
     $phpunit = $config->getPHPUnitConfiguration();
     if (empty($phpunit)) {
         return;
     }
     $config->handlePHPConfiguration();
     if (isset($phpunit['bootstrap'])) {
         $this->setBootstrap($phpunit['bootstrap']);
     }
     if (isset($phpunit['stopOnFailure'])) {
         $this->setHaltonfailure($phpunit['stopOnFailure']);
     }
     if (isset($phpunit['stopOnError'])) {
         $this->setHaltonerror($phpunit['stopOnError']);
     }
     if (isset($phpunit['stopOnSkipped'])) {
         $this->setHaltonskipped($phpunit['stopOnSkipped']);
     }
     if (isset($phpunit['stopOnIncomplete'])) {
         $this->setHaltonincomplete($phpunit['stopOnIncomplete']);
     }
     if (isset($phpunit['processIsolation'])) {
         $this->setProcessIsolation($phpunit['processIsolation']);
     }
     foreach ($config->getListenerConfiguration() as $listener) {
         if (!class_exists($listener['class'], false) && $listener['file'] !== '') {
             require_once $listener['file'];
         }
         if (class_exists($listener['class'])) {
             if (count($listener['arguments']) == 0) {
                 $listener = new $listener['class']();
             } else {
                 $listenerClass = new ReflectionClass($listener['class']);
                 $listener = $listenerClass->newInstanceArgs($listener['arguments']);
             }
             if ($listener instanceof PHPUnit_Framework_TestListener) {
                 $this->addListener($listener);
             }
         }
     }
     $browsers = $config->getSeleniumBrowserConfiguration();
     if (!empty($browsers) && class_exists('PHPUnit_Extensions_SeleniumTestCase')) {
         PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers;
     }
     return $phpunit;
 }
 protected function setUp()
 {
     $this->configuration = PHPUnit_Util_Configuration::getInstance(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'configuration.xml');
 }
Example #27
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);
     }
 }
Example #28
0
 /**
  * @param  array $arguments
  * @since  Method available since Release 3.2.1
  */
 protected function handleConfiguration(array &$arguments)
 {
     if (isset($arguments['configuration']) && !$arguments['configuration'] instanceof PHPUnit_Util_Configuration) {
         $arguments['configuration'] = PHPUnit_Util_Configuration::getInstance($arguments['configuration']);
         $arguments['pmd'] = $arguments['configuration']->getPMDConfiguration();
     } else {
         $arguments['pmd'] = array();
     }
     $arguments['debug'] = isset($arguments['debug']) ? $arguments['debug'] : FALSE;
     $arguments['filter'] = isset($arguments['filter']) ? $arguments['filter'] : FALSE;
     $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
     $arguments['repeat'] = isset($arguments['repeat']) ? $arguments['repeat'] : FALSE;
     $arguments['testDatabasePrefix'] = isset($arguments['testDatabasePrefix']) ? $arguments['testDatabasePrefix'] : '';
     $arguments['verbose'] = isset($arguments['verbose']) ? $arguments['verbose'] : FALSE;
     $arguments['wait'] = isset($arguments['wait']) ? $arguments['wait'] : FALSE;
     if (isset($arguments['configuration'])) {
         $arguments['configuration']->handlePHPConfiguration();
         $filterConfiguration = $arguments['configuration']->getFilterConfiguration();
         PHPUnit_Util_Filter::$addUncoveredFilesFromWhitelist = $filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist'];
         foreach ($filterConfiguration['blacklist']['include']['directory'] as $dir) {
             PHPUnit_Util_Filter::addDirectoryToFilter($dir['path'], $dir['suffix'], $dir['group'], $dir['prefix']);
         }
         foreach ($filterConfiguration['blacklist']['include']['file'] as $file) {
             PHPUnit_Util_Filter::addFileToFilter($file);
         }
         foreach ($filterConfiguration['blacklist']['exclude']['directory'] as $dir) {
             PHPUnit_Util_Filter::removeDirectoryFromFilter($dir['path'], $dir['suffix'], $dir['group'], $dir['prefix']);
         }
         foreach ($filterConfiguration['blacklist']['exclude']['file'] as $file) {
             PHPUnit_Util_Filter::removeFileFromFilter($file);
         }
         foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) {
             PHPUnit_Util_Filter::addDirectoryToWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
         }
         foreach ($filterConfiguration['whitelist']['include']['file'] as $file) {
             PHPUnit_Util_Filter::addFileToWhitelist($file);
         }
         foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) {
             PHPUnit_Util_Filter::removeDirectoryFromWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
         }
         foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) {
             PHPUnit_Util_Filter::removeFileFromWhitelist($file);
         }
         $phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration();
         if (isset($phpunitConfiguration['backupGlobals']) && !isset($arguments['backupGlobals'])) {
             $arguments['backupGlobals'] = $phpunitConfiguration['backupGlobals'];
         }
         if (isset($phpunitConfiguration['backupStaticAttributes']) && !isset($arguments['backupStaticAttributes'])) {
             $arguments['backupStaticAttributes'] = $phpunitConfiguration['backupStaticAttributes'];
         }
         if (isset($phpunitConfiguration['bootstrap']) && !isset($arguments['bootstrap'])) {
             $arguments['bootstrap'] = $phpunitConfiguration['bootstrap'];
         }
         if (isset($phpunitConfiguration['colors']) && !isset($arguments['colors'])) {
             $arguments['colors'] = $phpunitConfiguration['colors'];
         }
         if (isset($phpunitConfiguration['convertErrorsToExceptions']) && !isset($arguments['convertErrorsToExceptions'])) {
             $arguments['convertErrorsToExceptions'] = $phpunitConfiguration['convertErrorsToExceptions'];
         }
         if (isset($phpunitConfiguration['convertNoticesToExceptions']) && !isset($arguments['convertNoticesToExceptions'])) {
             $arguments['convertNoticesToExceptions'] = $phpunitConfiguration['convertNoticesToExceptions'];
         }
         if (isset($phpunitConfiguration['convertWarningsToExceptions']) && !isset($arguments['convertWarningsToExceptions'])) {
             $arguments['convertWarningsToExceptions'] = $phpunitConfiguration['convertWarningsToExceptions'];
         }
         if (isset($phpunitConfiguration['processIsolation']) && !isset($arguments['processIsolation'])) {
             $arguments['processIsolation'] = $phpunitConfiguration['processIsolation'];
         }
         if (isset($phpunitConfiguration['stopOnFailure']) && !isset($arguments['stopOnFailure'])) {
             $arguments['stopOnFailure'] = $phpunitConfiguration['stopOnFailure'];
         }
         $groupConfiguration = $arguments['configuration']->getGroupConfiguration();
         if (!empty($groupConfiguration['include']) && !isset($arguments['groups'])) {
             $arguments['groups'] = $groupConfiguration['include'];
         }
         if (!empty($groupConfiguration['exclude']) && !isset($arguments['excludeGroups'])) {
             $arguments['excludeGroups'] = $groupConfiguration['exclude'];
         }
         foreach ($arguments['configuration']->getListenerConfiguration() as $listener) {
             if (!class_exists($listener['class'], FALSE) && $listener['file'] !== '') {
                 $file = PHPUnit_Util_Filesystem::fileExistsInIncludePath($listener['file']);
                 if ($file !== FALSE) {
                     require $file;
                 }
             }
             if (class_exists($listener['class'], FALSE)) {
                 if (count($listener['arguments']) == 0) {
                     $listener = new $listener['class']();
                 } else {
                     $listenerClass = new ReflectionClass($listener['class']);
                     $listener = $listenerClass->newInstanceArgs($listener['arguments']);
                 }
                 if ($listener instanceof PHPUnit_Framework_TestListener) {
                     $arguments['listeners'][] = $listener;
                 }
             }
         }
         $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration();
         if (isset($loggingConfiguration['coverage-html']) && !isset($arguments['reportDirectory'])) {
             if (isset($loggingConfiguration['charset']) && !isset($arguments['reportCharset'])) {
                 $arguments['reportCharset'] = $loggingConfiguration['charset'];
             }
             if (isset($loggingConfiguration['yui']) && !isset($arguments['reportYUI'])) {
                 $arguments['reportYUI'] = $loggingConfiguration['yui'];
             }
             if (isset($loggingConfiguration['highlight']) && !isset($arguments['reportHighlight'])) {
                 $arguments['reportHighlight'] = $loggingConfiguration['highlight'];
             }
             if (isset($loggingConfiguration['lowUpperBound']) && !isset($arguments['reportLowUpperBound'])) {
                 $arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound'];
             }
             if (isset($loggingConfiguration['highLowerBound']) && !isset($arguments['reportHighLowerBound'])) {
                 $arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound'];
             }
             $arguments['reportDirectory'] = $loggingConfiguration['coverage-html'];
         }
         if (isset($loggingConfiguration['coverage-clover']) && !isset($arguments['coverageClover'])) {
             $arguments['coverageClover'] = $loggingConfiguration['coverage-clover'];
         }
         if (isset($loggingConfiguration['coverage-xml']) && !isset($arguments['coverageClover'])) {
             $arguments['coverageClover'] = $loggingConfiguration['coverage-xml'];
         }
         if (isset($loggingConfiguration['coverage-source']) && !isset($arguments['coverageSource'])) {
             $arguments['coverageSource'] = $loggingConfiguration['coverage-source'];
         }
         if (isset($loggingConfiguration['graphviz']) && !isset($arguments['graphvizLogfile'])) {
             $arguments['graphvizLogfile'] = $loggingConfiguration['graphviz'];
         }
         if (isset($loggingConfiguration['json']) && !isset($arguments['jsonLogfile'])) {
             $arguments['jsonLogfile'] = $loggingConfiguration['json'];
         }
         if (isset($loggingConfiguration['metrics-xml']) && !isset($arguments['metricsXML'])) {
             $arguments['metricsXML'] = $loggingConfiguration['metrics-xml'];
         }
         if (isset($loggingConfiguration['plain'])) {
             $arguments['listeners'][] = new PHPUnit_TextUI_ResultPrinter($loggingConfiguration['plain'], TRUE);
         }
         if (isset($loggingConfiguration['pmd-xml']) && !isset($arguments['pmdXML'])) {
             if (isset($loggingConfiguration['cpdMinLines']) && !isset($arguments['cpdMinLines'])) {
                 $arguments['cpdMinLines'] = $loggingConfiguration['cpdMinLines'];
             }
             if (isset($loggingConfiguration['cpdMinMatches']) && !isset($arguments['cpdMinMatches'])) {
                 $arguments['cpdMinMatches'] = $loggingConfiguration['cpdMinMatches'];
             }
             $arguments['pmdXML'] = $loggingConfiguration['pmd-xml'];
         }
         if (isset($loggingConfiguration['tap']) && !isset($arguments['tapLogfile'])) {
             $arguments['tapLogfile'] = $loggingConfiguration['tap'];
         }
         if (isset($loggingConfiguration['junit']) && !isset($arguments['junitLogfile'])) {
             $arguments['junitLogfile'] = $loggingConfiguration['junit'];
             if (isset($loggingConfiguration['logIncompleteSkipped']) && !isset($arguments['logIncompleteSkipped'])) {
                 $arguments['logIncompleteSkipped'] = $loggingConfiguration['logIncompleteSkipped'];
             }
         }
         if (isset($loggingConfiguration['story-html']) && !isset($arguments['storyHTMLFile'])) {
             $arguments['storyHTMLFile'] = $loggingConfiguration['story-html'];
         }
         if (isset($loggingConfiguration['story-text']) && !isset($arguments['storyTextFile'])) {
             $arguments['storsTextFile'] = $loggingConfiguration['story-text'];
         }
         if (isset($loggingConfiguration['testdox-html']) && !isset($arguments['testdoxHTMLFile'])) {
             $arguments['testdoxHTMLFile'] = $loggingConfiguration['testdox-html'];
         }
         if (isset($loggingConfiguration['testdox-text']) && !isset($arguments['testdoxTextFile'])) {
             $arguments['testdoxTextFile'] = $loggingConfiguration['testdox-text'];
         }
     }
     $arguments['backupGlobals'] = isset($arguments['backupGlobals']) ? $arguments['backupGlobals'] : NULL;
     $arguments['backupStaticAttributes'] = isset($arguments['backupStaticAttributes']) ? $arguments['backupStaticAttributes'] : NULL;
     $arguments['cpdMinLines'] = isset($arguments['cpdMinLines']) ? $arguments['cpdMinLines'] : 5;
     $arguments['cpdMinMatches'] = isset($arguments['cpdMinMatches']) ? $arguments['cpdMinMatches'] : 70;
     $arguments['colors'] = isset($arguments['colors']) ? $arguments['colors'] : FALSE;
     $arguments['convertErrorsToExceptions'] = isset($arguments['convertErrorsToExceptions']) ? $arguments['convertErrorsToExceptions'] : TRUE;
     $arguments['convertNoticesToExceptions'] = isset($arguments['convertNoticesToExceptions']) ? $arguments['convertNoticesToExceptions'] : TRUE;
     $arguments['convertWarningsToExceptions'] = isset($arguments['convertWarningsToExceptions']) ? $arguments['convertWarningsToExceptions'] : TRUE;
     $arguments['excludeGroups'] = isset($arguments['excludeGroups']) ? $arguments['excludeGroups'] : array();
     $arguments['groups'] = isset($arguments['groups']) ? $arguments['groups'] : array();
     $arguments['logIncompleteSkipped'] = isset($arguments['logIncompleteSkipped']) ? $arguments['logIncompleteSkipped'] : FALSE;
     $arguments['processIsolation'] = isset($arguments['processIsolation']) ? $arguments['processIsolation'] : FALSE;
     $arguments['reportCharset'] = isset($arguments['reportCharset']) ? $arguments['reportCharset'] : 'ISO-8859-1';
     $arguments['reportHighlight'] = isset($arguments['reportHighlight']) ? $arguments['reportHighlight'] : TRUE;
     $arguments['reportHighLowerBound'] = isset($arguments['reportHighLowerBound']) ? $arguments['reportHighLowerBound'] : 70;
     $arguments['reportLowUpperBound'] = isset($arguments['reportLowUpperBound']) ? $arguments['reportLowUpperBound'] : 35;
     $arguments['reportYUI'] = FALSE;
     $arguments['stopOnFailure'] = isset($arguments['stopOnFailure']) ? $arguments['stopOnFailure'] : FALSE;
     if ($arguments['filter'] !== FALSE && preg_match('/^[a-zA-Z0-9_]/', $arguments['filter'])) {
         // Escape delimiters in regular expression. Do NOT use preg_quote,
         // to keep magic characters.
         $arguments['filter'] = '/' . str_replace('/', '\\/', $arguments['filter']) . '/';
     }
 }
Example #29
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 #30
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;
 }