4 * This file is part of the Behat.
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\Behat\Gherkin\Cli;
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;
24 * Configures default Gherkin filters.
26 * @author Konstantin Kudryashov <ever.zet@gmail.com>
28 final class FilterController implements Controller
36 * Initializes controller.
38 * @param Gherkin $gherkin
40 public function __construct(Gherkin $gherkin)
42 $this->gherkin = $gherkin;
46 * Configures command to be executable by the controller.
48 * @param Command $command
50 public function configure(Command $command)
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."
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."
64 '--role', null, InputOption::VALUE_REQUIRED,
65 "Only executeCall the features with actor role matching" . PHP_EOL .
71 * Executes controller.
73 * @param InputInterface $input
74 * @param OutputInterface $output
76 * @return null|integer
78 public function execute(InputInterface $input, OutputInterface $output)
82 foreach ($input->getOption('name') as $name) {
83 $filters[] = new NameFilter($name);
86 foreach ($input->getOption('tags') as $tags) {
87 $filters[] = new TagFilter($tags);
90 if ($role = $input->getOption('role')) {
91 $filters[] = new RoleFilter($role);
94 if (count($filters)) {
95 $this->gherkin->setFilters($filters);