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
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);
}
}
protected handleArguments ( array $argv ) | ||
$argv | array |
/** * {@inheritdoc} * * @SuppressWarnings(PHPMD.StaticAccess) */ public function handleArguments(array $argv) { parent::handleArguments($argv); if (Get::value('sugaredDebug', $this->arguments, false)) { $this->logDebug('Parsed arguments', $this->arguments); } $this->addListeners(); }
/** * {@inheritdoc} */ protected function handleArguments(array $argv) { parent::handleArguments($argv); if (array_key_exists('testSuffixes', $this->arguments)) { $fileSystem = new FileSystem(); $filePatterns = array(); foreach ($this->arguments['testSuffixes'] as $testSuffix) { $filePatterns[] = preg_quote($testSuffix) . '$'; } $this->testTargetRepository->setResources(array(empty($this->arguments['testFile']) ? $this->arguments['test'] : $this->arguments['testFile'])); $this->testTargetRepository->setFilePattern(implode('|', $filePatterns)); } }
protected function handleArguments(array $argv) { parent::handleArguments($argv); if (!isset($this->arguments['listeners'])) { $this->arguments['listeners'] = array(); } foreach ($this->options[0] as $option) { switch ($option[0]) { case '--debug-tests': $this->arguments['listeners'][] = new MediaWikiPHPUnitTestListener('PHPUnitCommand'); break; } } }
protected function handleArguments(array $argv) { parent::handleArguments($argv); $verbose = isset($this->arguments['verbose']) ? true : false; $this->arguments['printer'] = new ResultPrinter(null, $verbose, false, false); }
/** * Additionally ensures that the required argument "--dsn" is set * * @inheritdoc * @param array $argv */ protected function handleArguments(array $argv) { parent::handleArguments($argv); if (empty($this->arguments['dsn'])) { PHPUnit_TextUI_TestRunner::showError('The parameter --dsn is required'); } }