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\Output\Node\Printer\Pretty;
13 use Behat\Behat\Output\Node\Printer\Helper\ResultToStringConverter;
14 use Behat\Behat\Output\Node\Printer\OutlineTablePrinter;
15 use Behat\Behat\Output\Node\Printer\ScenarioPrinter;
16 use Behat\Behat\Output\Node\Printer\StepPrinter;
17 use Behat\Behat\Tester\Result\StepResult;
18 use Behat\Gherkin\Node\ExampleTableNode;
19 use Behat\Gherkin\Node\FeatureNode;
20 use Behat\Gherkin\Node\OutlineNode;
21 use Behat\Gherkin\Node\StepNode;
22 use Behat\Testwork\Output\Formatter;
23 use Behat\Testwork\Output\Printer\OutputPrinter;
24 use Behat\Testwork\Tester\Result\TestResult;
27 * Prints outline table header and footer.
29 * @author Konstantin Kudryashov <ever.zet@gmail.com>
31 final class PrettyOutlineTablePrinter implements OutlineTablePrinter
34 * @var ScenarioPrinter
36 private $scenarioPrinter;
42 * @var ResultToStringConverter
44 private $resultConverter;
52 private $subIndentText;
55 * Initializes printer.
57 * @param ScenarioPrinter $scenarioPrinter
58 * @param StepPrinter $stepPrinter
59 * @param ResultToStringConverter $resultConverter
60 * @param integer $indentation
61 * @param integer $subIndentation
63 public function __construct(
64 ScenarioPrinter $scenarioPrinter,
65 StepPrinter $stepPrinter,
66 ResultToStringConverter $resultConverter,
70 $this->scenarioPrinter = $scenarioPrinter;
71 $this->stepPrinter = $stepPrinter;
72 $this->resultConverter = $resultConverter;
73 $this->indentText = str_repeat(' ', intval($indentation));
74 $this->subIndentText = $this->indentText . str_repeat(' ', intval($subIndentation));
80 public function printHeader(Formatter $formatter, FeatureNode $feature, OutlineNode $outline, array $results)
82 $this->scenarioPrinter->printHeader($formatter, $feature, $outline);
84 $this->printExamplesSteps($formatter, $outline, $outline->getSteps(), $results);
85 $this->printExamplesTableHeader($formatter->getOutputPrinter(), $outline->getExampleTable());
91 public function printFooter(Formatter $formatter, TestResult $result)
93 $formatter->getOutputPrinter()->writeln();
97 * Prints example steps with definition paths (if has some), but without exceptions or state (skipped).
99 * @param Formatter $formatter
100 * @param OutlineNode $outline
101 * @param StepNode[] $steps
102 * @param StepResult[] $results
104 private function printExamplesSteps(Formatter $formatter, OutlineNode $outline, array $steps, array $results)
106 foreach ($steps as $step) {
107 $result = $results[$step->getLine()];
109 $this->stepPrinter->printStep($formatter, $outline, $step, $result);
112 $formatter->getOutputPrinter()->writeln();
116 * Prints examples table header.
118 * @param OutputPrinter $printer
119 * @param ExampleTableNode $table
121 private function printExamplesTableHeader(OutputPrinter $printer, ExampleTableNode $table)
123 $printer->writeln(sprintf('%s{+keyword}%s:{-keyword}', $this->indentText, $table->getKeyword()));
126 $wrapper = $this->getWrapperClosure();
127 $row = $table->getRowAsStringWithWrappedValues($rowNum, $wrapper);
129 $printer->writeln(sprintf('%s%s', $this->subIndentText, $row));
133 * Creates wrapper-closure for the example header.
137 private function getWrapperClosure()
139 $style = $this->resultConverter->convertResultCodeToString(TestResult::SKIPPED);
141 return function ($col) use ($style) {
142 return sprintf('{+%s_param}%s{-%s_param}', $style, $col, $style);