implemented --bootstrap option

This commit is contained in:
tmont 2009-06-22 09:29:26 +00:00
parent 718be2d381
commit 97400f9e87
2 changed files with 26 additions and 12 deletions

View File

@ -203,7 +203,7 @@
*/ */
protected final function parseOptions(array $unparsed) { protected final function parseOptions(array $unparsed) {
$allowedOptions = $this->getAllowableOptions(); $allowedOptions = $this->getAllowableOptions();
$options = array_fill_keys(array_key($allowedOptions), null); $options = array_fill_keys(array_keys($allowedOptions), null);
foreach ($unparsed as $option => $value) { foreach ($unparsed as $option => $value) {
if (!isset($allowedOptions[$option])) { if (!isset($allowedOptions[$option])) {
throw new InvalidOptionException($option); throw new InvalidOptionException($option);

View File

@ -43,37 +43,51 @@
global $switches; global $switches;
$switches = new CliSwitchCollection(); $switches = new CliSwitchCollection();
$switches->addSwitch(new CliSwitch(null, null, true, '<files>', 'Files and/or directories to parse for test cases')) $switches->addSwitch(new CliSwitch(null, null, true, '<files>', 'Files and/or directories to parse for test cases'))
->addSwitch(new CliSwitch('help', 'h', false, null, 'Display this help message (also --usage)')) ->addSwitch(new CliSwitch('help', 'h', false, null, 'Display this help message (also --usage)'))
->addSwitch(new CliSwitch('recursive', null, false, null, 'Recurse into subdirectories')) ->addSwitch(new CliSwitch('usage', null, false, null, 'Display this help message'))
->addSwitch(new CliSwitch('bootstrap', 'b', false, 'file', 'File to include before each test')); ->addSwitch(new CliSwitch('recursive', null, false, null, 'Recurse into subdirectories'))
->addSwitch(new CliSwitch('bootstrap', 'b', false, 'file', 'File to include before tests are run'));
array_shift($argv); array_shift($argv);
$args = Cli::parseArgs($argv, $switches); $args = Cli::parseArgs($argv, $switches);
//print_r($args); exit;
$localSwitches = $args['switches']; $options = $args['switches'];
$localArgs = $args['args']; $args = $args['args'];
if (isset($localSwitches['help'])) { if (isset($options['help']) || isset($options['usage'])) {
usage(); usage();
exit(0); exit(0);
} }
if (empty($localArgs)) { if (empty($args)) {
usage(); usage();
exit(1); exit(1);
} }
//accumulate tests //accumulate tests
$tests = TestAccumulator::getTests($localArgs, isset($localSwitches['recursive'])); $tests = TestAccumulator::getTests($args, isset($options['recursive']));
if (empty($tests)) { if (empty($tests)) {
fwrite(STDERR, 'Found no TestCase subclasses in the given files'); fwrite(STDERR, 'Found no TestCase subclasses in the given files');
exit(1); exit(1);
} }
$runner = new ConsoleTestRunner(array(new TestSuite('Main Test Suite', $tests)), array(new ConsoleListener(/*ConsoleListener::VERBOSITY_HIGH*/)), $localSwitches); if (isset($options['bootstrap'])) {
if (!is_file($options['bootstrap'])) {
fwrite(STDERR, 'Bootstrap file given (' . $options['bootstrap'] . ') is not a file');
exit(1);
}
require_once $options['bootstrap'];
}
$runner = new ConsoleTestRunner(
array(new TestSuite('Main Test Suite', $tests)),
array(new ConsoleListener()),
$options
);
$runner->run(); $runner->run();
exit(0); exit(0);