function it_does_not_take_a_screenshot_after_a_skipped_step(ScreenshotTaker $screenshotTaker, Environment $env, FeatureNode $feature, StepNode $step, StepResult $result, Teardown $tearDown) { $event = new AfterStepTested($env->getWrappedObject(), $feature->getWrappedObject(), $step->getWrappedObject(), $result->getWrappedObject(), $tearDown->getWrappedObject()); $result->getResultCode()->willReturn(TestResult::SKIPPED); $screenshotTaker->takeScreenshot()->shouldNotBeCalled(); $this->takeScreenshot($event); }
function it_generates_filename_from_step_name(ScreenshotTaker $screenshotTaker, StepFilenameGenerator $filenameGenerator, Environment $env, FeatureNode $feature, StepNode $step, StepResult $result, Teardown $tearDown) { $event = new AfterStepTested($env->getWrappedObject(), $feature->getWrappedObject(), $step->getWrappedObject(), $result->getWrappedObject(), $tearDown->getWrappedObject()); $result->getResultCode()->willReturn(TestResult::FAILED); $filenameGenerator->convertStepToFileName($step)->willReturn('test.jpg')->shouldBeCalled(); $screenshotTaker->takeScreenshot('test.jpg')->shouldBeCalled(); $this->checkAfterStep($event); }
/** * Prints step path comment. * * @param Formatter $formatter * @param Scenario $scenario * @param StepNode $step * @param StepResult $result * @param integer $indentation */ public function printStepPath(Formatter $formatter, Scenario $scenario, StepNode $step, StepResult $result, $indentation) { $printer = $formatter->getOutputPrinter(); if (!$result instanceof DefinedStepResult || !$result->getStepDefinition() || !$formatter->getParameter('paths')) { $printer->writeln(); return; } $textWidth = $this->widthCalculator->calculateStepWidth($step, $indentation); $scenarioWidth = $this->widthCalculator->calculateScenarioWidth($scenario, $indentation - 2, 2); $this->printDefinedStepPath($printer, $result, $scenarioWidth, $textWidth); }
/** * Checks if result is executed and call result has produced exception or stdOut. * * @return Boolean */ private function resultCallHasOutput() { if (!$this->result instanceof ExecutedStepResult) { return false; } return $this->result->getCallResult()->hasStdOut() || $this->result->getCallResult()->hasException(); }
/** * Prints step text. * * @param OutputPrinter $printer * @param string $stepType * @param string $stepText * @param StepResult $result */ private function printText(OutputPrinter $printer, $stepType, $stepText, StepResult $result) { $style = $this->resultConverter->convertResultCodeToString(TestResult::SKIPPED); if ($result instanceof DefinedStepResult && $result->getStepDefinition()) { $definition = $result->getStepDefinition(); $stepText = $this->textPainter->paintText($stepText, $definition, new IntegerTestResult(TestResult::SKIPPED)); } $printer->write(sprintf('%s{+%s}%s %s{-%s}', $this->indentText, $style, $stepType, $stepText, $style)); }
/** * Prints step using provided printer. * * @param Formatter $formatter * @param Scenario $scenario * @param StepNode $step * @param StepResult $result */ public function printStep(Formatter $formatter, Scenario $scenario, StepNode $step, StepResult $result) { /** @var JUnitOutputPrinter $outputPrinter */ $outputPrinter = $formatter->getOutputPrinter(); $message = $step->getKeyword() . ' ' . $step->getText(); if ($result instanceof ExceptionResult && $result->hasException()) { $message .= ': ' . $this->exceptionPresenter->presentException($result->getException()); } $attributes = array('message' => $message); switch ($result->getResultCode()) { case TestResult::FAILED: $outputPrinter->addTestcaseChild('failure', $attributes); break; case TestResult::PENDING: $attributes['type'] = 'pending'; $outputPrinter->addTestcaseChild('error', $attributes); break; case StepResult::UNDEFINED: $attributes['type'] = 'undefined'; $outputPrinter->addTestcaseChild('error', $attributes); break; } }
/** * Gets exception from the step test results. * * @param StepResult $result * * @return null|Exception */ private function getStepException(StepResult $result) { if ($result instanceof ExceptionResult) { return $result->getException(); } return null; }
/** * Prints step output (if has one). * * @param OutputPrinter $printer * @param StepResult $result */ private function printStepStdOut(OutputPrinter $printer, StepResult $result) { if (!$result instanceof ExecutedStepResult || null === $result->getCallResult()->getStdOut()) { return; } $callResult = $result->getCallResult(); $indentedText = $this->subIndentText; $pad = function ($line) use($indentedText) { return sprintf('%s│ {+stdout}%s{-stdout}', $indentedText, $line); }; $printer->writeln(implode("\n", array_map($pad, explode("\n", $callResult->getStdOut())))); }