Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Output / Node / Printer / JUnit / JUnitScenarioPrinter.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\JUnit;
12
13 use Behat\Behat\Output\Node\EventListener\JUnit\JUnitOutlineStoreListener;
14 use Behat\Behat\Output\Node\Printer\Helper\ResultToStringConverter;
15 use Behat\Gherkin\Node\ExampleNode;
16 use Behat\Gherkin\Node\FeatureNode;
17 use Behat\Gherkin\Node\OutlineNode;
18 use Behat\Gherkin\Node\ScenarioLikeInterface;
19 use Behat\Testwork\Output\Formatter;
20 use Behat\Testwork\Output\Printer\JUnitOutputPrinter;
21 use Behat\Testwork\Tester\Result\TestResult;
22
23 /**
24  * Prints the <testcase> element.
25  *
26  * @author Wouter J <wouter@wouterj.nl>
27  */
28 final class JUnitScenarioPrinter
29 {
30     /**
31      * @var ResultToStringConverter
32      */
33     private $resultConverter;
34
35     /**
36      * @var JUnitOutlineStoreListener
37      */
38     private $outlineStoreListener;
39
40     /**
41      * @var OutlineNode
42      */
43     private $lastOutline;
44
45     /**
46      * @var int
47      */
48     private $outlineStepCount;
49
50     public function __construct(ResultToStringConverter $resultConverter, JUnitOutlineStoreListener $outlineListener)
51     {
52         $this->resultConverter = $resultConverter;
53         $this->outlineStoreListener = $outlineListener;
54     }
55
56     /**
57      * {@inheritDoc}
58      */
59     public function printOpenTag(Formatter $formatter, FeatureNode $feature, ScenarioLikeInterface $scenario, TestResult $result)
60     {
61         $name = implode(' ', array_map(function ($l) {
62             return trim($l);
63         }, explode("\n", $scenario->getTitle())));
64
65         if ($scenario instanceof ExampleNode) {
66             $name = $this->buildExampleName($scenario);
67         }
68
69         /** @var JUnitOutputPrinter $outputPrinter */
70         $outputPrinter = $formatter->getOutputPrinter();
71
72         $outputPrinter->addTestcase(array(
73             'name' => $name,
74             'status' => $this->resultConverter->convertResultToString($result)
75         ));
76     }
77
78     /**
79      * @param ExampleNode $scenario
80      * @return string
81      */
82     private function buildExampleName(ExampleNode $scenario)
83     {
84         $currentOutline = $this->outlineStoreListener->getCurrentOutline($scenario);
85         if ($currentOutline === $this->lastOutline) {
86             $this->outlineStepCount++;
87         } else {
88             $this->lastOutline = $currentOutline;
89             $this->outlineStepCount = 1;
90         }
91
92         $name = $currentOutline->getTitle() . ' #' . $this->outlineStepCount;
93         return $name;
94     }
95 }