Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Output / Node / Printer / Pretty / PrettyOutlineTablePrinter.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\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;
25
26 /**
27  * Prints outline table header and footer.
28  *
29  * @author Konstantin Kudryashov <ever.zet@gmail.com>
30  */
31 final class PrettyOutlineTablePrinter implements OutlineTablePrinter
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      * Initializes printer.
56      *
57      * @param ScenarioPrinter         $scenarioPrinter
58      * @param StepPrinter             $stepPrinter
59      * @param ResultToStringConverter $resultConverter
60      * @param integer                 $indentation
61      * @param integer                 $subIndentation
62      */
63     public function __construct(
64         ScenarioPrinter $scenarioPrinter,
65         StepPrinter $stepPrinter,
66         ResultToStringConverter $resultConverter,
67         $indentation = 4,
68         $subIndentation = 2
69     ) {
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));
75     }
76
77     /**
78      * {@inheritdoc}
79      */
80     public function printHeader(Formatter $formatter, FeatureNode $feature, OutlineNode $outline, array $results)
81     {
82         $this->scenarioPrinter->printHeader($formatter, $feature, $outline);
83
84         $this->printExamplesSteps($formatter, $outline, $outline->getSteps(), $results);
85         $this->printExamplesTableHeader($formatter->getOutputPrinter(), $outline->getExampleTable());
86     }
87
88     /**
89      * {@inheritdoc}
90      */
91     public function printFooter(Formatter $formatter, TestResult $result)
92     {
93         $formatter->getOutputPrinter()->writeln();
94     }
95
96     /**
97      * Prints example steps with definition paths (if has some), but without exceptions or state (skipped).
98      *
99      * @param Formatter    $formatter
100      * @param OutlineNode  $outline
101      * @param StepNode[]   $steps
102      * @param StepResult[] $results
103      */
104     private function printExamplesSteps(Formatter $formatter, OutlineNode $outline, array $steps, array $results)
105     {
106         foreach ($steps as $step) {
107             $result = $results[$step->getLine()];
108
109             $this->stepPrinter->printStep($formatter, $outline, $step, $result);
110         }
111
112         $formatter->getOutputPrinter()->writeln();
113     }
114
115     /**
116      * Prints examples table header.
117      *
118      * @param OutputPrinter    $printer
119      * @param ExampleTableNode $table
120      */
121     private function printExamplesTableHeader(OutputPrinter $printer, ExampleTableNode $table)
122     {
123         $printer->writeln(sprintf('%s{+keyword}%s:{-keyword}', $this->indentText, $table->getKeyword()));
124
125         $rowNum = 0;
126         $wrapper = $this->getWrapperClosure();
127         $row = $table->getRowAsStringWithWrappedValues($rowNum, $wrapper);
128
129         $printer->writeln(sprintf('%s%s', $this->subIndentText, $row));
130     }
131
132     /**
133      * Creates wrapper-closure for the example header.
134      *
135      * @return callable
136      */
137     private function getWrapperClosure()
138     {
139         $style = $this->resultConverter->convertResultCodeToString(TestResult::SKIPPED);
140
141         return function ($col) use ($style) {
142             return sprintf('{+%s_param}%s{-%s_param}', $style, $col, $style);
143         };
144     }
145 }