Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Definition / Printer / ConsoleDefinitionInformationPrinter.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\Definition\Printer;
12
13 use Behat\Behat\Definition\Definition;
14 use Behat\Testwork\Suite\Suite;
15
16 /**
17  * Prints definitions with full information about them.
18  *
19  * @author Konstantin Kudryashov <ever.zet@gmail.com>
20  */
21 final class ConsoleDefinitionInformationPrinter extends ConsoleDefinitionPrinter
22 {
23     /**
24      * @var null|string
25      */
26     private $searchCriterion;
27
28     /**
29      * Sets search criterion.
30      *
31      * @param string $criterion
32      */
33     public function setSearchCriterion($criterion)
34     {
35         $this->searchCriterion = $criterion;
36     }
37
38     /**
39      * {@inheritdoc}
40      */
41     public function printDefinitions(Suite $suite, $definitions)
42     {
43         $search = $this->searchCriterion;
44         $output = array();
45
46         foreach ($definitions as $definition) {
47             $definition = $this->translateDefinition($suite, $definition);
48             $pattern = $definition->getPattern();
49
50             if (null !== $search && false === mb_strpos($pattern, $search, 0, 'utf8')) {
51                 continue;
52             }
53
54             $lines = array_merge(
55                 $this->extractHeader($suite, $definition),
56                 $this->extractDescription($suite, $definition),
57                 $this->extractFooter($suite, $definition)
58             );
59
60             $output[] = implode(PHP_EOL, $lines) . PHP_EOL;
61         }
62
63         $this->write(rtrim(implode(PHP_EOL, $output)));
64     }
65
66     /**
67      * Extracts the formatted header from the definition.
68      *
69      * @param Suite      $suite
70      * @param Definition $definition
71      *
72      * @return string[]
73      */
74     private function extractHeader(Suite $suite, Definition $definition)
75     {
76         $pattern = $definition->getPattern();
77         $lines = array();
78         $lines[] = strtr(
79             '{suite} <def_dimmed>|</def_dimmed> <info>{type}</info> <def_regex>{regex}</def_regex>', array(
80                 '{suite}' => $suite->getName(),
81                 '{type}'  => $this->getDefinitionType($definition),
82                 '{regex}' => $pattern,
83             )
84         );
85
86         return $lines;
87     }
88
89     /**
90      * Extracts the formatted description from the definition.
91      *
92      * @param Suite      $suite
93      * @param Definition $definition
94      *
95      * @return string[]
96      */
97     private function extractDescription(Suite $suite, Definition $definition)
98     {
99         $definition = $this->translateDefinition($suite, $definition);
100
101         $lines = array();
102         if ($description = $definition->getDescription()) {
103             foreach (explode("\n", $description) as $descriptionLine) {
104                 $lines[] = strtr(
105                     '{space}<def_dimmed>|</def_dimmed> {description}', array(
106                         '{space}'       => str_pad('', mb_strlen($suite->getName(), 'utf8') + 1),
107                         '{description}' => $descriptionLine
108                     )
109                 );
110             }
111         }
112
113         return $lines;
114     }
115
116     /**
117      * Extracts the formatted footer from the definition.
118      *
119      * @param Suite      $suite
120      * @param Definition $definition
121      *
122      * @return string[]
123      */
124     private function extractFooter(Suite $suite, Definition $definition)
125     {
126         $lines = array();
127         $lines[] = strtr(
128             '{space}<def_dimmed>|</def_dimmed> at `{path}`', array(
129                 '{space}' => str_pad('', mb_strlen($suite->getName(), 'utf8') + 1),
130                 '{path}'  => $definition->getPath()
131             )
132         );
133
134         if ($this->isVerbose()) {
135             $lines[] = strtr(
136                 '{space}<def_dimmed>|</def_dimmed> on `{filepath}[{start}:{end}]`', array(
137                     '{space}' => str_pad('', mb_strlen($suite->getName(), 'utf8') + 1),
138                     '{filepath}' => $definition->getReflection()->getFileName(),
139                     '{start}' => $definition->getReflection()->getStartLine(),
140                     '{end}' => $definition->getReflection()->getEndLine()
141                 )
142             );
143         }
144
145         return $lines;
146     }
147 }