4 * This file is part of the Behat Testwork.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Testwork\Suite\Cli;
13 use Behat\Testwork\Cli\Controller;
14 use Behat\Testwork\Suite\Exception\SuiteNotFoundException;
15 use Behat\Testwork\Suite\SuiteRegistry;
16 use Symfony\Component\Console\Command\Command;
17 use Symfony\Component\Console\Input\InputInterface;
18 use Symfony\Component\Console\Input\InputOption;
19 use Symfony\Component\Console\Output\OutputInterface;
22 * Sets up registered test suites.
24 * @author Konstantin Kudryashov <ever.zet@gmail.com>
26 final class SuiteController implements Controller
35 private $suiteConfigurations = array();
38 * Initializes controller.
40 * @param SuiteRegistry $registry
41 * @param array $suiteConfigurations
43 public function __construct(SuiteRegistry $registry, array $suiteConfigurations)
45 $this->registry = $registry;
46 $this->suiteConfigurations = $suiteConfigurations;
52 public function configure(Command $command)
54 $command->addOption('--suite', '-s', InputOption::VALUE_REQUIRED,
55 'Only execute a specific suite.'
62 public function execute(InputInterface $input, OutputInterface $output)
64 $exerciseSuiteName = $input->getOption('suite');
66 if (null !== $exerciseSuiteName && !isset($this->suiteConfigurations[$exerciseSuiteName])) {
67 throw new SuiteNotFoundException(sprintf(
68 '`%s` suite is not found or has not been properly registered.',
70 ), $exerciseSuiteName);
73 foreach ($this->suiteConfigurations as $name => $config) {
74 if (null !== $exerciseSuiteName && $exerciseSuiteName !== $name) {
78 $this->registry->registerSuiteConfiguration(
79 $name, $config['type'], $config['settings']