X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FOutput%2FNode%2FEventListener%2FJUnit%2FJUnitOutlineStoreListener.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FOutput%2FNode%2FEventListener%2FJUnit%2FJUnitOutlineStoreListener.php;h=4458ebb73e810c876185e60ce87993c06c0dca13;hp=0000000000000000000000000000000000000000;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68 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 index 000000000..4458ebb73 --- /dev/null +++ b/vendor/behat/behat/src/Behat/Behat/Output/Node/EventListener/JUnit/JUnitOutlineStoreListener.php @@ -0,0 +1,111 @@ + + * + * 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 + */ +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()]; + } +}