Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Output / Node / Printer / Pretty / PrettyFeaturePrinter.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\FeaturePrinter;
14 use Behat\Gherkin\Node\FeatureNode;
15 use Behat\Gherkin\Node\TaggedNodeInterface;
16 use Behat\Testwork\Output\Formatter;
17 use Behat\Testwork\Output\Printer\OutputPrinter;
18 use Behat\Testwork\Tester\Result\TestResult;
19
20 /**
21  * Prints feature header and footer.
22  *
23  * @author Konstantin Kudryashov <ever.zet@gmail.com>
24  */
25 final class PrettyFeaturePrinter implements FeaturePrinter
26 {
27     /**
28      * @var string
29      */
30     private $indentText;
31     /**
32      * @var string
33      */
34     private $subIndentText;
35
36     /**
37      * Initializes printer.
38      *
39      * @param integer $indentation
40      * @param integer $subIndentation
41      */
42     public function __construct($indentation = 0, $subIndentation = 2)
43     {
44         $this->indentText = str_repeat(' ', intval($indentation));
45         $this->subIndentText = $this->indentText . str_repeat(' ', intval($subIndentation));
46     }
47
48     /**
49      * {@inheritdoc}
50      */
51     public function printHeader(Formatter $formatter, FeatureNode $feature)
52     {
53         if ($feature instanceof TaggedNodeInterface) {
54             $this->printTags($formatter->getOutputPrinter(), $feature->getTags());
55         }
56
57         $this->printTitle($formatter->getOutputPrinter(), $feature);
58         $this->printDescription($formatter->getOutputPrinter(), $feature);
59     }
60
61     /**
62      * {@inheritdoc}
63      */
64     public function printFooter(Formatter $formatter, TestResult $result)
65     {
66     }
67
68     /**
69      * Prints feature tags.
70      *
71      * @param OutputPrinter $printer
72      * @param string[]      $tags
73      */
74     private function printTags(OutputPrinter $printer, array $tags)
75     {
76         if (!count($tags)) {
77             return;
78         }
79
80         $tags = array_map(array($this, 'prependTagWithTagSign'), $tags);
81         $printer->writeln(sprintf('%s{+tag}%s{-tag}', $this->indentText, implode(' ', $tags)));
82     }
83
84     /**
85      * Prints feature title using provided printer.
86      *
87      * @param OutputPrinter $printer
88      * @param FeatureNode   $feature
89      */
90     private function printTitle(OutputPrinter $printer, FeatureNode $feature)
91     {
92         $printer->write(sprintf('%s{+keyword}%s:{-keyword}', $this->indentText, $feature->getKeyword()));
93
94         if ($title = $feature->getTitle()) {
95             $printer->write(sprintf(' %s', $title));
96         }
97
98         $printer->writeln();
99     }
100
101     /**
102      * Prints feature description using provided printer.
103      *
104      * @param OutputPrinter $printer
105      * @param FeatureNode   $feature
106      */
107     private function printDescription(OutputPrinter $printer, FeatureNode $feature)
108     {
109         if (!$feature->getDescription()) {
110             $printer->writeln();
111
112             return;
113         }
114
115         foreach (explode("\n", $feature->getDescription()) as $descriptionLine) {
116             $printer->writeln(sprintf('%s%s', $this->subIndentText, $descriptionLine));
117         }
118
119         $printer->writeln();
120     }
121
122     /**
123      * Prepends tags string with tag-sign.
124      *
125      * @param string $tag
126      *
127      * @return string
128      */
129     private function prependTagWithTagSign($tag)
130     {
131         return '@' . $tag;
132     }
133 }