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\Definition\Printer;
13 use Behat\Behat\Definition\Definition;
14 use Behat\Behat\Definition\Pattern\PatternTransformer;
15 use Behat\Behat\Definition\Translator\DefinitionTranslator;
16 use Behat\Gherkin\Keywords\KeywordsInterface;
17 use Behat\Testwork\Suite\Suite;
18 use Symfony\Component\Console\Formatter\OutputFormatterStyle;
19 use Symfony\Component\Console\Output\OutputInterface;
22 * Represents console-based definition printer.
24 * @author Konstantin Kudryashov <ever.zet@gmail.com>
26 abstract class ConsoleDefinitionPrinter implements DefinitionPrinter
29 * @var OutputInterface
33 * @var PatternTransformer
35 private $patternTransformer;
37 * @var DefinitionTranslator
41 * @var KeywordsInterface
46 * Initializes printer.
48 * @param OutputInterface $output
49 * @param PatternTransformer $patternTransformer
50 * @param DefinitionTranslator $translator
51 * @param KeywordsInterface $keywords
53 public function __construct(
54 OutputInterface $output,
55 PatternTransformer $patternTransformer,
56 DefinitionTranslator $translator,
57 KeywordsInterface $keywords
59 $this->output = $output;
60 $this->patternTransformer = $patternTransformer;
61 $this->translator = $translator;
62 $this->keywords = $keywords;
64 $output->getFormatter()->setStyle('def_regex', new OutputFormatterStyle('yellow'));
65 $output->getFormatter()->setStyle(
67 new OutputFormatterStyle('yellow', null, array('bold'))
69 $output->getFormatter()->setStyle(
71 new OutputFormatterStyle('black', null, array('bold'))
76 * Writes text to the console.
80 final protected function write($text)
82 $this->output->writeln($text);
83 $this->output->writeln('');
86 final protected function getDefinitionType(Definition $definition, $onlyOne = false)
88 $this->keywords->setLanguage($this->translator->getLocale());
90 $method = 'get'.ucfirst($definition->getType()).'Keywords';
92 $keywords = explode('|', $this->keywords->$method());
95 return current($keywords);
98 return 1 < count($keywords) ? '['.implode('|', $keywords).']' : implode('|', $keywords);
102 * Translates definition using translator.
104 * @param Suite $suite
105 * @param Definition $definition
109 final protected function translateDefinition(Suite $suite, Definition $definition)
111 return $this->translator->translateDefinition($suite, $definition);
115 * Returns whether verbosity is verbose (-v).
117 * @return bool true if verbosity is set to VERBOSITY_VERBOSE, false otherwise
119 final protected function isVerbose()
121 return $this->output->isVerbose();