Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Output / Node / EventListener / JUnit / JUnitOutlineStoreListener.php
diff --git a/vendor/behat/behat/src/Behat/Behat/Output/Node/EventListener/JUnit/JUnitOutlineStoreListener.php b/vendor/behat/behat/src/Behat/Behat/Output/Node/EventListener/JUnit/JUnitOutlineStoreListener.php
new file mode 100644 (file)
index 0000000..4458ebb
--- /dev/null
@@ -0,0 +1,111 @@
+<?php
+
+/*
+ * This file is part of the Behat.
+ * (c) Konstantin Kudryashov <ever.zet@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Behat\Behat\Output\Node\EventListener\JUnit;
+
+use Behat\Behat\EventDispatcher\Event\BeforeOutlineTested;
+use Behat\Behat\Output\Node\Printer\SuitePrinter;
+use Behat\Gherkin\Node\ExampleNode;
+use Behat\Gherkin\Node\OutlineNode;
+use Behat\Testwork\EventDispatcher\Event\AfterSuiteTested;
+use Behat\Testwork\EventDispatcher\Event\BeforeSuiteTested;
+use Behat\Testwork\Output\Formatter;
+use Behat\Testwork\Output\Node\EventListener\EventListener;
+use Symfony\Component\EventDispatcher\Event;
+
+/**
+ * Listens for Outline events store the current one
+ *
+ * @author James Watson <james@sitepulse.org>
+ */
+final class JUnitOutlineStoreListener implements EventListener
+{
+
+    /**
+     * @var SuitePrinter
+     */
+    private $suitePrinter;
+
+    /**
+     * @var array
+     */
+    private $lineScenarioMap = array();
+
+    /**
+     * Initializes listener.
+     *
+     * @param SuitePrinter $suitePrinter
+     */
+    public function __construct(SuitePrinter $suitePrinter)
+    {
+        $this->suitePrinter = $suitePrinter;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function listenEvent(Formatter $formatter, Event $event, $eventName)
+    {
+        $this->captureOutlineOnBeforeOutlineEvent($event);
+
+        $this->printHeaderOnBeforeSuiteTestedEvent($formatter, $event);
+        $this->printFooterOnAfterSuiteTestedEvent($formatter, $event);
+    }
+
+    /**
+     * Captures outline into the ivar on outline BEFORE event.
+     *
+     * @param Event $event
+     */
+    private function captureOutlineOnBeforeOutlineEvent(Event $event)
+    {
+        if (!$event instanceof BeforeOutlineTested) {
+            return;
+        }
+
+        $outline = $event->getOutline();
+        foreach ($outline->getExamples() as $example) {
+            $this->lineScenarioMap[$example->getLine()] = $outline;
+        }
+    }
+
+    /**
+     * @param Formatter $formatter
+     * @param Event     $event
+     */
+    private function printHeaderOnBeforeSuiteTestedEvent(Formatter $formatter, Event $event)
+    {
+        if (!$event instanceof BeforeSuiteTested) {
+            return;
+        }
+        $this->suitePrinter->printHeader($formatter, $event->getSuite());
+    }
+
+    /**
+     * @param Formatter $formatter
+     * @param Event     $event
+     */
+    private function printFooterOnAfterSuiteTestedEvent(Formatter $formatter, Event $event)
+    {
+        if (!$event instanceof AfterSuiteTested) {
+            return;
+        }
+        $this->suitePrinter->printFooter($formatter, $event->getSuite());
+    }
+
+    /**
+     * @param ExampleNode $scenario
+     * @return OutlineNode
+     */
+    public function getCurrentOutline(ExampleNode $scenario)
+    {
+        return $this->lineScenarioMap[$scenario->getLine()];
+    }
+}