Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Output / Node / Printer / JUnit / JUnitStepPrinter.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\Tester\Result\StepResult;
14 use Behat\Behat\Output\Node\Printer\StepPrinter;
15 use Behat\Gherkin\Node\ScenarioLikeInterface as Scenario;
16 use Behat\Gherkin\Node\StepNode;
17 use Behat\Testwork\Exception\ExceptionPresenter;
18 use Behat\Testwork\Output\Formatter;
19 use Behat\Testwork\Output\Printer\JUnitOutputPrinter;
20 use Behat\Testwork\Tester\Result\TestResult;
21 use Behat\Testwork\Tester\Result\ExceptionResult;
22
23 /**
24  * Prints step with optional results.
25  *
26  * @author Wouter J <wouter@wouterj.nl>
27  * @author James Watson <james@sitepulse.org>
28  */
29 class JUnitStepPrinter implements StepPrinter
30 {
31     /**
32      * @var ExceptionPresenter
33      */
34     private $exceptionPresenter;
35
36     public function __construct(ExceptionPresenter $exceptionPresenter)
37     {
38         $this->exceptionPresenter = $exceptionPresenter;
39     }
40
41     /**
42      * Prints step using provided printer.
43      *
44      * @param Formatter  $formatter
45      * @param Scenario   $scenario
46      * @param StepNode   $step
47      * @param StepResult $result
48      */
49     public function printStep(Formatter $formatter, Scenario $scenario, StepNode $step, StepResult $result)
50     {
51         /** @var JUnitOutputPrinter $outputPrinter */
52         $outputPrinter = $formatter->getOutputPrinter();
53
54         $message = $step->getKeyword() . ' ' . $step->getText();
55
56         if ($result instanceof ExceptionResult && $result->hasException()) {
57             $message .= ': ' . $this->exceptionPresenter->presentException($result->getException());
58         }
59
60         $attributes = array('message' => $message);
61
62         switch ($result->getResultCode()) {
63             case TestResult::FAILED:
64                 $outputPrinter->addTestcaseChild('failure', $attributes);
65                 break;
66
67             case TestResult::PENDING:
68                 $attributes['type'] = 'pending';
69                 $outputPrinter->addTestcaseChild('error', $attributes);
70                 break;
71
72             case StepResult::UNDEFINED:
73                 $attributes['type'] = 'undefined';
74                 $outputPrinter->addTestcaseChild('error', $attributes);
75                 break;
76         }
77     }
78 }