/** * Prints step exception (if has one). * * @param OutputPrinter $printer * @param StepResult $result */ private function printStepException(OutputPrinter $printer, StepResult $result) { $style = $this->resultConverter->convertResultToString($result); if (!$result instanceof ExceptionResult || !$result->hasException()) { return; } $text = $this->exceptionPresenter->presentException($result->getException()); $indentedText = implode("\n", array_map(array($this, 'subIndent'), explode("\n", $text))); $printer->writeln(sprintf('{+%s}%s{-%s}', $style, $indentedText, $style)); }
/** * Captures hook call result. * * @param CallResult $hookCallResult */ private function captureHookStat(CallResult $hookCallResult) { $callee = $hookCallResult->getCall()->getCallee(); $hook = (string) $callee; $path = $callee->getPath(); $stdOut = $hookCallResult->getStdOut(); $error = $hookCallResult->getException() ? $this->exceptionPresenter->presentException($hookCallResult->getException()) : null; $stat = new HookStat($hook, $path, $error, $stdOut); $this->statistics->registerHookStat($stat); }
/** * @param Formatter $formatter * @param CallResults $results * @param string $messageType */ private function handleHookCalls(Formatter $formatter, CallResults $results, $messageType) { /** @var CallResult $hookCallResult */ foreach ($results as $hookCallResult) { if ($hookCallResult->hasException()) { /** @var HookCall $call */ $call = $hookCallResult->getCall(); $scope = $call->getScope(); /** @var JUnitOutputPrinter $outputPrinter */ $outputPrinter = $formatter->getOutputPrinter(); $message = ''; if ($scope instanceof StepScope) { $message .= $scope->getStep()->getKeyword() . ' ' . $scope->getStep()->getText() . ': '; } $message .= $this->exceptionPresenter->presentException($hookCallResult->getException()); $attributes = array('message' => $message, 'type' => $messageType); $outputPrinter->addTestcaseChild('failure', $attributes); } } }
/** * Prints hook call exception (if has some). * * @param OutputPrinter $printer * @param CallResult $callResult * @param string $indentText */ private function printHookCallException(OutputPrinter $printer, CallResult $callResult, $indentText) { if (!$callResult->hasException()) { return; } $pad = function ($l) use($indentText) { return sprintf('%s╳ {+exception}%s{-exception}', $indentText, $l); }; $exception = $this->exceptionPresenter->presentException($callResult->getException()); $printer->writeln(implode("\n", array_map($pad, explode("\n", $exception)))); $printer->writeln(sprintf('%s│', $indentText)); }
/** * 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; } }
/** * Captures step stats on step AFTER event. * * @param Event $event */ private function captureStepStatsOnAfterEvent(Event $event) { if (!$event instanceof AfterStepTested) { return; } $result = $event->getTestResult(); $step = $event->getStep(); $text = sprintf('%s %s', $step->getKeyword(), $step->getText()); $exception = $this->getStepException($result); $path = $this->getStepPath($event, $exception); $error = $exception ? $this->exceptionPresenter->presentException($exception) : null; $stdOut = $result instanceof ExecutedStepResult ? $result->getCallResult()->getStdOut() : null; $resultCode = $result->getResultCode(); $stat = new StepStatV2($this->scenarioTitle, $this->scenarioPath, $text, $path, $resultCode, $error, $stdOut); $this->statistics->registerStepStat($stat); }