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\Snippet\Printer;
13 use Behat\Behat\Snippet\AggregateSnippet;
14 use Behat\Gherkin\Node\StepNode;
15 use Symfony\Component\Console\Formatter\OutputFormatterStyle;
16 use Symfony\Component\Console\Output\OutputInterface;
17 use Symfony\Component\Translation\TranslatorInterface;
20 * Behat console-based snippet printer.
22 * Extends default printer with default styles.
24 * @author Konstantin Kudryashov <ever.zet@gmail.com>
26 class ConsoleSnippetPrinter implements SnippetPrinter
29 * @var OutputInterface
33 * @var TranslatorInterface
38 * Initializes printer.
40 * @param OutputInterface $output
41 * @param TranslatorInterface $translator
43 public function __construct(OutputInterface $output, TranslatorInterface $translator)
45 $this->output = $output;
46 $this->translator = $translator;
48 $output->getFormatter()->setStyle('snippet_keyword', new OutputFormatterStyle(null, null, array('bold')));
49 $output->getFormatter()->setStyle('snippet_undefined', new OutputFormatterStyle('yellow'));
53 * Prints snippets of specific target.
55 * @param string $targetName
56 * @param AggregateSnippet[] $snippets
58 public function printSnippets($targetName, array $snippets)
60 $message = $this->translator->trans('snippet_proposal_title', array('%1%' => $targetName), 'output');
62 $this->output->writeln('--- ' . $message . PHP_EOL);
64 foreach ($snippets as $snippet) {
65 $this->output->writeln(sprintf('<snippet_undefined>%s</snippet_undefined>', $snippet->getSnippet()) . PHP_EOL);
70 * Prints undefined steps of specific suite.
72 * @param string $suiteName
73 * @param StepNode[] $steps
75 public function printUndefinedSteps($suiteName, array $steps)
77 $message = $this->translator->trans('snippet_missing_title', array('%1%' => $suiteName), 'output');
79 $this->output->writeln('--- ' . $message . PHP_EOL);
81 foreach ($steps as $step) {
82 $this->output->writeln(sprintf(' <snippet_undefined>%s %s</snippet_undefined>', $step->getKeyword(), $step->getText()));
85 $this->output->writeln('');