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\Context\Cli;
13 use Behat\Behat\Context\Snippet\Generator\AggregatePatternIdentifier;
14 use Behat\Behat\Context\Snippet\Generator\ContextInterfaceBasedContextIdentifier;
15 use Behat\Behat\Context\Snippet\Generator\ContextInterfaceBasedPatternIdentifier;
16 use Behat\Behat\Context\Snippet\Generator\ContextSnippetGenerator;
17 use Behat\Behat\Context\Snippet\Generator\FixedContextIdentifier;
18 use Behat\Behat\Context\Snippet\Generator\FixedPatternIdentifier;
19 use Behat\Behat\Context\Snippet\Generator\AggregateContextIdentifier;
20 use Behat\Testwork\Cli\Controller;
21 use Symfony\Component\Console\Command\Command as SymfonyCommand;
22 use Symfony\Component\Console\Input\InputInterface;
23 use Symfony\Component\Console\Input\InputOption;
24 use Symfony\Component\Console\Output\OutputInterface;
25 use Symfony\Component\Translation\TranslatorInterface;
28 * Configures which context snippets are generated for.
30 * @author Konstantin Kudryashov <ever.zet@gmail.com>
32 final class ContextSnippetsController implements Controller
35 * @var ContextSnippetGenerator
39 * @var TranslatorInterface
44 * Initialises controller.
46 * @param ContextSnippetGenerator $generator
47 * @param TranslatorInterface $translator
49 public function __construct(ContextSnippetGenerator $generator, TranslatorInterface $translator)
51 $this->generator = $generator;
52 $this->translator = $translator;
58 public function configure(SymfonyCommand $command)
62 '--snippets-for', null, InputOption::VALUE_OPTIONAL,
63 "Specifies which context class to generate snippets for."
66 '--snippets-type', null, InputOption::VALUE_REQUIRED,
67 "Specifies which type of snippets (turnip, regex) to generate."
74 public function execute(InputInterface $input, OutputInterface $output)
76 $this->generator->setContextIdentifier(
77 new AggregateContextIdentifier(array(
78 new ContextInterfaceBasedContextIdentifier(),
79 new FixedContextIdentifier($input->getOption('snippets-for')),
80 new InteractiveContextIdentifier($this->translator, $input, $output)
84 $this->generator->setPatternIdentifier(
85 new AggregatePatternIdentifier(array(
86 new ContextInterfaceBasedPatternIdentifier(),
87 new FixedPatternIdentifier($input->getOption('snippets-type'))