X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FOutput%2FNode%2FPrinter%2FJUnit%2FJUnitScenarioPrinter.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FOutput%2FNode%2FPrinter%2FJUnit%2FJUnitScenarioPrinter.php;h=cf61eaab9f4cb06d3361616975cae5e57fdda968;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hp=0000000000000000000000000000000000000000;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68;p=yaffs-website diff --git a/vendor/behat/behat/src/Behat/Behat/Output/Node/Printer/JUnit/JUnitScenarioPrinter.php b/vendor/behat/behat/src/Behat/Behat/Output/Node/Printer/JUnit/JUnitScenarioPrinter.php new file mode 100644 index 000000000..cf61eaab9 --- /dev/null +++ b/vendor/behat/behat/src/Behat/Behat/Output/Node/Printer/JUnit/JUnitScenarioPrinter.php @@ -0,0 +1,95 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\Behat\Output\Node\Printer\JUnit; + +use Behat\Behat\Output\Node\EventListener\JUnit\JUnitOutlineStoreListener; +use Behat\Behat\Output\Node\Printer\Helper\ResultToStringConverter; +use Behat\Gherkin\Node\ExampleNode; +use Behat\Gherkin\Node\FeatureNode; +use Behat\Gherkin\Node\OutlineNode; +use Behat\Gherkin\Node\ScenarioLikeInterface; +use Behat\Testwork\Output\Formatter; +use Behat\Testwork\Output\Printer\JUnitOutputPrinter; +use Behat\Testwork\Tester\Result\TestResult; + +/** + * Prints the element. + * + * @author Wouter J + */ +final class JUnitScenarioPrinter +{ + /** + * @var ResultToStringConverter + */ + private $resultConverter; + + /** + * @var JUnitOutlineStoreListener + */ + private $outlineStoreListener; + + /** + * @var OutlineNode + */ + private $lastOutline; + + /** + * @var int + */ + private $outlineStepCount; + + public function __construct(ResultToStringConverter $resultConverter, JUnitOutlineStoreListener $outlineListener) + { + $this->resultConverter = $resultConverter; + $this->outlineStoreListener = $outlineListener; + } + + /** + * {@inheritDoc} + */ + public function printOpenTag(Formatter $formatter, FeatureNode $feature, ScenarioLikeInterface $scenario, TestResult $result) + { + $name = implode(' ', array_map(function ($l) { + return trim($l); + }, explode("\n", $scenario->getTitle()))); + + if ($scenario instanceof ExampleNode) { + $name = $this->buildExampleName($scenario); + } + + /** @var JUnitOutputPrinter $outputPrinter */ + $outputPrinter = $formatter->getOutputPrinter(); + + $outputPrinter->addTestcase(array( + 'name' => $name, + 'status' => $this->resultConverter->convertResultToString($result) + )); + } + + /** + * @param ExampleNode $scenario + * @return string + */ + private function buildExampleName(ExampleNode $scenario) + { + $currentOutline = $this->outlineStoreListener->getCurrentOutline($scenario); + if ($currentOutline === $this->lastOutline) { + $this->outlineStepCount++; + } else { + $this->lastOutline = $currentOutline; + $this->outlineStepCount = 1; + } + + $name = $currentOutline->getTitle() . ' #' . $this->outlineStepCount; + return $name; + } +}