Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Output / Node / Printer / Pretty / PrettyOutlinePrinter.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Output\Node\Printer\Pretty;
12
13 use Behat\Behat\Output\Node\Printer\Helper\ResultToStringConverter;
14 use Behat\Behat\Output\Node\Printer\OutlinePrinter;
15 use Behat\Behat\Output\Node\Printer\ScenarioPrinter;
16 use Behat\Behat\Output\Node\Printer\StepPrinter;
17 use Behat\Behat\Tester\Result\UndefinedStepResult;
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;
25
26 /**
27  * Prints outline header with outline steps and table header.
28  *
29  * @author Konstantin Kudryashov <ever.zet@gmail.com>
30  */
31 final class PrettyOutlinePrinter implements OutlinePrinter
32 {
33     /**
34      * @var ScenarioPrinter
35      */
36     private $scenarioPrinter;
37     /**
38      * @var StepPrinter
39      */
40     private $stepPrinter;
41     /**
42      * @var ResultToStringConverter
43      */
44     private $resultConverter;
45     /**
46      * @var string
47      */
48     private $indentText;
49     /**
50      * @var string
51      */
52     private $subIndentText;
53
54     /**
55      * @param ScenarioPrinter         $scenarioPrinter
56      * @param StepPrinter             $stepPrinter
57      * @param ResultToStringConverter $resultConverter
58      * @param integer                 $indentation
59      * @param integer                 $subIndentation
60      */
61     public function __construct(
62         ScenarioPrinter $scenarioPrinter,
63         StepPrinter $stepPrinter,
64         ResultToStringConverter $resultConverter,
65         $indentation = 4,
66         $subIndentation = 2
67     ) {
68         $this->scenarioPrinter = $scenarioPrinter;
69         $this->stepPrinter = $stepPrinter;
70         $this->resultConverter = $resultConverter;
71         $this->indentText = str_repeat(' ', intval($indentation));
72         $this->subIndentText = $this->indentText . str_repeat(' ', intval($subIndentation));
73     }
74
75     /**
76      * {@inheritdoc}
77      */
78     public function printHeader(Formatter $formatter, FeatureNode $feature, OutlineNode $outline)
79     {
80         $this->scenarioPrinter->printHeader($formatter, $feature, $outline);
81
82         $this->printExamplesSteps($formatter, $outline, $outline->getSteps());
83         $this->printExamplesTableHeader($formatter->getOutputPrinter(), $outline->getExampleTable());
84     }
85
86     /**
87      * {@inheritdoc}
88      */
89     public function printFooter(Formatter $formatter, TestResult $result)
90     {
91         $formatter->getOutputPrinter()->writeln();
92     }
93
94     /**
95      * Prints outline steps.
96      *
97      * @param Formatter   $formatter
98      * @param OutlineNode $outline
99      * @param StepNode[]  $steps
100      */
101     private function printExamplesSteps(Formatter $formatter, OutlineNode $outline, array $steps)
102     {
103         foreach ($steps as $step) {
104             $this->stepPrinter->printStep($formatter, $outline, $step, new UndefinedStepResult());
105         }
106
107         $formatter->getOutputPrinter()->writeln();
108     }
109
110     /**
111      * Prints examples table header.
112      *
113      * @param OutputPrinter    $printer
114      * @param ExampleTableNode $table
115      */
116     private function printExamplesTableHeader(OutputPrinter $printer, ExampleTableNode $table)
117     {
118         $printer->writeln(sprintf('%s{+keyword}%s:{-keyword}', $this->indentText, $table->getKeyword()));
119
120         $rowNum = 0;
121         $wrapper = $this->getWrapperClosure();
122         $row = $table->getRowAsStringWithWrappedValues($rowNum, $wrapper);
123
124         $printer->writeln(sprintf('%s%s', $this->subIndentText, $row));
125     }
126
127     /**
128      * Creates wrapper-closure for the example header.
129      *
130      * @return callable
131      */
132     private function getWrapperClosure()
133     {
134         $style = $this->resultConverter->convertResultCodeToString(TestResult::SKIPPED);
135
136         return function ($col) use ($style) {
137             return sprintf('{+%s_param}%s{-%s_param}', $style, $col, $style);
138         };
139     }
140 }