Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Tests\Behat\Controller;
- use Behat\Behat\EventDispatcher\Event\BeforeFeatureTested;
- use Behat\Testwork\Cli\Controller;
- use Symfony\Component\Console\Command\Command as SymfonyCommand;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\EventDispatcher\EventDispatcherInterface;
- use Symfony\Component\Yaml\Yaml;
- /**
- * @author Vincent Chalamon <vincent@les-tilleuls.coop>
- */
- final class ListSuitesController implements Controller
- {
- /**
- * @var EventDispatcherInterface
- */
- private $eventDispatcher;
- /**
- * @var OutputInterface
- */
- private $output;
- /**
- * @param EventDispatcherInterface $eventDispatcher
- */
- public function __construct($eventDispatcher)
- {
- $this->eventDispatcher = $eventDispatcher;
- }
- /**
- * {@inheritdoc}
- */
- public function configure(SymfonyCommand $command)
- {
- $command->addOption('--list-suites', null, InputOption::VALUE_NONE, 'List suites.');
- }
- /**
- * {@inheritdoc}
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- if (!$input->getOption('list-suites')) {
- return null;
- }
- $this->output = $output;
- $this->eventDispatcher->addListener(BeforeFeatureTested::BEFORE, [$this, 'listSuites'], -100);
- }
- public function listSuites(BeforeFeatureTested $event)
- {
- $suites = array_keys(Yaml::parse(file_get_contents(rtrim(getcwd(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'behat.yml'))['default']['suites']);
- $this->output->writeln(implode(PHP_EOL, $suites));
- exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement