Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Suite / Cli / SuiteController.php
1 <?php
2
3 /*
4  * This file is part of the Behat Testwork.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Testwork\Suite\Cli;
12
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;
20
21 /**
22  * Sets up registered test suites.
23  *
24  * @author Konstantin Kudryashov <ever.zet@gmail.com>
25  */
26 final class SuiteController implements Controller
27 {
28     /**
29      * @var SuiteRegistry
30      */
31     private $registry;
32     /**
33      * @var array
34      */
35     private $suiteConfigurations = array();
36
37     /**
38      * Initializes controller.
39      *
40      * @param SuiteRegistry $registry
41      * @param array         $suiteConfigurations
42      */
43     public function __construct(SuiteRegistry $registry, array $suiteConfigurations)
44     {
45         $this->registry = $registry;
46         $this->suiteConfigurations = $suiteConfigurations;
47     }
48
49     /**
50      * {@inheritdoc}
51      */
52     public function configure(Command $command)
53     {
54         $command->addOption('--suite', '-s', InputOption::VALUE_REQUIRED,
55             'Only execute a specific suite.'
56         );
57     }
58
59     /**
60      * {@inheritdoc}
61      */
62     public function execute(InputInterface $input, OutputInterface $output)
63     {
64         $exerciseSuiteName = $input->getOption('suite');
65
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.',
69                 $exerciseSuiteName
70             ), $exerciseSuiteName);
71         }
72
73         foreach ($this->suiteConfigurations as $name => $config) {
74             if (null !== $exerciseSuiteName && $exerciseSuiteName !== $name) {
75                 continue;
76             }
77
78             $this->registry->registerSuiteConfiguration(
79                 $name, $config['type'], $config['settings']
80             );
81         }
82     }
83 }