Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Tests\Behat\Controller;
  4.  
  5. use Behat\Behat\EventDispatcher\Event\BeforeFeatureTested;
  6. use Behat\Testwork\Cli\Controller;
  7. use Symfony\Component\Console\Command\Command as SymfonyCommand;
  8. use Symfony\Component\Console\Input\InputInterface;
  9. use Symfony\Component\Console\Input\InputOption;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  12. use Symfony\Component\Yaml\Yaml;
  13.  
  14. /**
  15. * @author Vincent Chalamon <vincent@les-tilleuls.coop>
  16. */
  17. final class ListSuitesController implements Controller
  18. {
  19. /**
  20. * @var EventDispatcherInterface
  21. */
  22. private $eventDispatcher;
  23.  
  24. /**
  25. * @var OutputInterface
  26. */
  27. private $output;
  28.  
  29. /**
  30. * @param EventDispatcherInterface $eventDispatcher
  31. */
  32. public function __construct($eventDispatcher)
  33. {
  34. $this->eventDispatcher = $eventDispatcher;
  35. }
  36.  
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function configure(SymfonyCommand $command)
  41. {
  42. $command->addOption('--list-suites', null, InputOption::VALUE_NONE, 'List suites.');
  43. }
  44.  
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function execute(InputInterface $input, OutputInterface $output)
  49. {
  50. if (!$input->getOption('list-suites')) {
  51. return null;
  52. }
  53.  
  54. $this->output = $output;
  55.  
  56. $this->eventDispatcher->addListener(BeforeFeatureTested::BEFORE, [$this, 'listSuites'], -100);
  57. }
  58.  
  59. public function listSuites(BeforeFeatureTested $event)
  60. {
  61. $suites = array_keys(Yaml::parse(file_get_contents(rtrim(getcwd(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'behat.yml'))['default']['suites']);
  62. $this->output->writeln(implode(PHP_EOL, $suites));
  63.  
  64. exit(0);
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement