Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Output / Node / EventListener / JUnit / JUnitOutlineStoreListener.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\EventListener\JUnit;
12
13 use Behat\Behat\EventDispatcher\Event\BeforeOutlineTested;
14 use Behat\Behat\Output\Node\Printer\SuitePrinter;
15 use Behat\Gherkin\Node\ExampleNode;
16 use Behat\Gherkin\Node\OutlineNode;
17 use Behat\Testwork\EventDispatcher\Event\AfterSuiteTested;
18 use Behat\Testwork\EventDispatcher\Event\BeforeSuiteTested;
19 use Behat\Testwork\Output\Formatter;
20 use Behat\Testwork\Output\Node\EventListener\EventListener;
21 use Symfony\Component\EventDispatcher\Event;
22
23 /**
24  * Listens for Outline events store the current one
25  *
26  * @author James Watson <james@sitepulse.org>
27  */
28 final class JUnitOutlineStoreListener implements EventListener
29 {
30
31     /**
32      * @var SuitePrinter
33      */
34     private $suitePrinter;
35
36     /**
37      * @var array
38      */
39     private $lineScenarioMap = array();
40
41     /**
42      * Initializes listener.
43      *
44      * @param SuitePrinter $suitePrinter
45      */
46     public function __construct(SuitePrinter $suitePrinter)
47     {
48         $this->suitePrinter = $suitePrinter;
49     }
50
51     /**
52      * {@inheritdoc}
53      */
54     public function listenEvent(Formatter $formatter, Event $event, $eventName)
55     {
56         $this->captureOutlineOnBeforeOutlineEvent($event);
57
58         $this->printHeaderOnBeforeSuiteTestedEvent($formatter, $event);
59         $this->printFooterOnAfterSuiteTestedEvent($formatter, $event);
60     }
61
62     /**
63      * Captures outline into the ivar on outline BEFORE event.
64      *
65      * @param Event $event
66      */
67     private function captureOutlineOnBeforeOutlineEvent(Event $event)
68     {
69         if (!$event instanceof BeforeOutlineTested) {
70             return;
71         }
72
73         $outline = $event->getOutline();
74         foreach ($outline->getExamples() as $example) {
75             $this->lineScenarioMap[$example->getLine()] = $outline;
76         }
77     }
78
79     /**
80      * @param Formatter $formatter
81      * @param Event     $event
82      */
83     private function printHeaderOnBeforeSuiteTestedEvent(Formatter $formatter, Event $event)
84     {
85         if (!$event instanceof BeforeSuiteTested) {
86             return;
87         }
88         $this->suitePrinter->printHeader($formatter, $event->getSuite());
89     }
90
91     /**
92      * @param Formatter $formatter
93      * @param Event     $event
94      */
95     private function printFooterOnAfterSuiteTestedEvent(Formatter $formatter, Event $event)
96     {
97         if (!$event instanceof AfterSuiteTested) {
98             return;
99         }
100         $this->suitePrinter->printFooter($formatter, $event->getSuite());
101     }
102
103     /**
104      * @param ExampleNode $scenario
105      * @return OutlineNode
106      */
107     public function getCurrentOutline(ExampleNode $scenario)
108     {
109         return $this->lineScenarioMap[$scenario->getLine()];
110     }
111 }