/** * {@inheritdoc} */ public function printStep(Formatter $formatter, Scenario $scenario, StepNode $step, StepResult $result) { $printer = $formatter->getOutputPrinter(); $style = $this->resultConverter->convertResultToString($result); switch ($result->getResultCode()) { case TestResult::PASSED: $printer->write("{+{$style}}.{-{$style}}"); break; case TestResult::SKIPPED: $printer->write("{+{$style}}-{-{$style}}"); break; case TestResult::PENDING: $printer->write("{+{$style}}P{-{$style}}"); break; case StepResult::UNDEFINED: $printer->write("{+{$style}}U{-{$style}}"); break; case TestResult::FAILED: $printer->write("{+{$style}}F{-{$style}}"); break; } if (++$this->stepsPrinted % 70 == 0) { $printer->writeln(' ' . $this->stepsPrinted); } }
/** * {@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(); } /** @var JUnitOutputPrinter $outputPrinter */ $outputPrinter = $formatter->getOutputPrinter(); $outputPrinter->addTestcase(array('name' => $name, 'status' => $this->resultConverter->convertResultToString($result))); }
/** * Creates wrapper-closure for the example header. * * @return callable */ private function getWrapperClosure() { $style = $this->resultConverter->convertResultCodeToString(TestResult::SKIPPED); return function ($col) use($style) { return sprintf('{+%s_param}%s{-%s_param}', $style, $col, $style); }; }
/** * Prints step multiline arguments. * * @param Formatter $formatter * @param ArgumentInterface[] $arguments */ private function printArguments(Formatter $formatter, array $arguments) { $style = $this->resultConverter->convertResultCodeToString(TestResult::SKIPPED); foreach ($arguments as $argument) { $text = $this->getArgumentString($argument, !$formatter->getParameter('multiline')); $indentedText = implode("\n", array_map(array($this, 'subIndent'), explode("\n", $text))); $formatter->getOutputPrinter()->writeln(sprintf('{+%s}%s{-%s}', $style, $indentedText, $style)); } }
/** * 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)); }
/** * Prints failed hooks list. * * @param OutputPrinter $printer * @param string $intro * @param HookStat[] $failedHookStats */ public function printFailedHooksList(OutputPrinter $printer, $intro, array $failedHookStats) { if (!count($failedHookStats)) { return; } $style = $this->resultConverter->convertResultCodeToString(TestResult::FAILED); $intro = $this->translator->trans($intro, array(), 'output'); $printer->writeln(sprintf('--- {+%s}%s{-%s}' . PHP_EOL, $style, $intro, $style)); foreach ($failedHookStats as $hookStat) { $this->printHookStat($printer, $hookStat, $style); } }
/** * Colorizes step text arguments according to definition. * * @param string $text * @param Definition $definition * @param TestResult $result * * @return string */ public function paintText($text, Definition $definition, TestResult $result) { $regex = $this->patternTransformer->transformPatternToRegex($definition->getPattern()); $style = $this->resultConverter->convertResultToString($result); $paramStyle = $style . '_param'; // If it's just a string - skip if ('/' !== substr($regex, 0, 1)) { return $text; } // Find arguments with offsets $matches = array(); preg_match($regex, $text, $matches, PREG_OFFSET_CAPTURE); array_shift($matches); // Replace arguments with colorized ones $shift = 0; $lastReplacementPosition = 0; foreach ($matches as $key => $match) { if (!is_numeric($key) || -1 === $match[1] || false !== strpos($match[0], '<')) { continue; } $offset = $match[1] + $shift; $value = $match[0]; // Skip inner matches if ($lastReplacementPosition > $offset) { continue; } $lastReplacementPosition = $offset + strlen($value); $begin = substr($text, 0, $offset); $end = substr($text, $lastReplacementPosition); $format = "{-{$style}}{+{$paramStyle}}%s{-{$paramStyle}}{+{$style}}"; $text = sprintf("%s{$format}%s", $begin, $value, $end); // Keep track of how many extra characters are added $shift += strlen($format) - 2; $lastReplacementPosition += strlen($format) - 2; } // Replace "<", ">" with colorized ones $text = preg_replace('/(<[^>]+>)/', "{-{$style}}{+{$paramStyle}}\$1{-{$paramStyle}}{+{$style}}", $text); return $text; }
/** * Prints scenario and step counters. * * @param OutputPrinter $printer * @param string $intro * @param array $stats */ public function printCounters(OutputPrinter $printer, $intro, array $stats) { $stats = array_filter($stats, function ($count) { return 0 !== $count; }); if (0 === count($stats)) { $totalCount = 0; } else { $totalCount = array_sum($stats); } $detailedStats = array(); foreach ($stats as $resultCode => $count) { $style = $this->resultConverter->convertResultCodeToString($resultCode); $transId = $style . '_count'; $message = $this->translator->transChoice($transId, $count, array('%1%' => $count), 'output'); $detailedStats[] = sprintf('{+%s}%s{-%s}', $style, $message, $style); } $message = $this->translator->transChoice($intro, $totalCount, array('%1%' => $totalCount), 'output'); $printer->write($message); if (count($detailedStats)) { $printer->write(sprintf(' (%s)', implode(', ', $detailedStats))); } $printer->writeln(); }
/** * Prints failed hooks list. * * @param OutputPrinter $printer * @param string $intro * @param HookStat[] $failedHookStats */ public function printFailedHooksList(OutputPrinter $printer, $intro, array $failedHookStats) { if (!count($failedHookStats)) { return; } $style = $this->resultConverter->convertResultCodeToString(TestResult::FAILED); $intro = $this->translator->trans($intro, array(), 'output'); $printer->writeln(sprintf('--- {+%s}%s{-%s}' . PHP_EOL, $style, $intro, $style)); foreach ($failedHookStats as $hookStat) { $name = $hookStat->getName(); $path = $hookStat->getPath(); $stdOut = $hookStat->getStdOut(); $error = $hookStat->getError(); $this->printStat($printer, $name, $path, $style, $stdOut, $error); } }
/** * Prints teardown hook call result. * * @param OutputPrinter $printer * @param CallResult $callResult */ private function printTeardownHookCallResult(OutputPrinter $printer, CallResult $callResult) { if (!$callResult->hasStdOut() && !$callResult->hasException()) { return; } $resultCode = $callResult->hasException() ? TestResult::FAILED : TestResult::PASSED; $style = $this->resultConverter->convertResultCodeToString($resultCode); $hook = $callResult->getCall()->getCallee(); $path = $hook->getPath(); $printer->writeln(sprintf('%s│', $this->indentText)); $this->printHookCallStdOut($printer, $callResult, $this->indentText); $this->printHookCallException($printer, $callResult, $this->indentText); $printer->writeln(sprintf('%s└─ {+%s}@%s{-%s} {+comment}# %s{-comment}', $this->indentText, $style, $hook, $style, $path)); if ($this->newlineAfter) { $printer->writeln(); } }