Skip to content
This repository has been archived by the owner on Mar 24, 2020. It is now read-only.

add bootstrap option #68

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/PHPSpec2/Console/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use PHPSpec2\Console;
use PHPSpec2\Formatter;

use InvalidArgumentException;

class RunCommand extends Command
{
/**
Expand All @@ -25,6 +27,7 @@ public function __construct()
$this->setDefinition(array(
new InputArgument('spec', InputArgument::OPTIONAL, 'Specs to run', 'spec'),
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Formatter', 'progress'),
new InputOption('bootstrap', null, InputOption::VALUE_REQUIRED, 'Run a bootstrap file before start', false)
));
}

Expand All @@ -33,6 +36,20 @@ public function __construct()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($bootstrap = $input->getOption("bootstrap") ) {
if (null === $bootstrap) {
throw new InvalidArgumentException('The --bootstrap option needs a value');
}

if (!is_file($bootstrap)) {
throw new InvalidArgumentException("The bootstrap file ({$bootstrap}) doesn't exist");
} else if (pathinfo($bootstrap, PATHINFO_EXTENSION) !== "php") {
throw new InvalidArgumentException("The bootstrap file ({$bootstrap}) isn't a valid php file");
}

require $bootstrap;
}

$output->setFormatter(new Console\Formatter($output->isDecorated()));
$c = $this->getApplication()->getContainer();

Expand Down