Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Gherkin / Cli / FilterController.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
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\Behat\Gherkin\Cli;
12
13 use Behat\Gherkin\Filter\NameFilter;
14 use Behat\Gherkin\Filter\RoleFilter;
15 use Behat\Gherkin\Filter\TagFilter;
16 use Behat\Gherkin\Gherkin;
17 use Behat\Testwork\Cli\Controller;
18 use Symfony\Component\Console\Command\Command;
19 use Symfony\Component\Console\Input\InputInterface;
20 use Symfony\Component\Console\Input\InputOption;
21 use Symfony\Component\Console\Output\OutputInterface;
22
23 /**
24  * Configures default Gherkin filters.
25  *
26  * @author Konstantin Kudryashov <ever.zet@gmail.com>
27  */
28 final class FilterController implements Controller
29 {
30     /**
31      * @var Gherkin
32      */
33     private $gherkin;
34
35     /**
36      * Initializes controller.
37      *
38      * @param Gherkin $gherkin
39      */
40     public function __construct(Gherkin $gherkin)
41     {
42         $this->gherkin = $gherkin;
43     }
44
45     /**
46      * Configures command to be executable by the controller.
47      *
48      * @param Command $command
49      */
50     public function configure(Command $command)
51     {
52         $command
53             ->addOption(
54                 '--name', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
55                 "Only executeCall the feature elements which match part" . PHP_EOL .
56                 "of the given name or regex."
57             )
58             ->addOption(
59                 '--tags', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
60                 "Only executeCall the features or scenarios with tags" . PHP_EOL .
61                 "matching tag filter expression."
62             )
63             ->addOption(
64                 '--role', null, InputOption::VALUE_REQUIRED,
65                 "Only executeCall the features with actor role matching" . PHP_EOL .
66                 "a wildcard."
67             );
68     }
69
70     /**
71      * Executes controller.
72      *
73      * @param InputInterface  $input
74      * @param OutputInterface $output
75      *
76      * @return null|integer
77      */
78     public function execute(InputInterface $input, OutputInterface $output)
79     {
80         $filters = array();
81
82         foreach ($input->getOption('name') as $name) {
83             $filters[] = new NameFilter($name);
84         }
85
86         foreach ($input->getOption('tags') as $tags) {
87             $filters[] = new TagFilter($tags);
88         }
89
90         if ($role = $input->getOption('role')) {
91             $filters[] = new RoleFilter($role);
92         }
93
94         if (count($filters)) {
95             $this->gherkin->setFilters($filters);
96         }
97     }
98 }