예제 #1
0
 /**
  * Save the screenshot as the given filename
  *
  * @param string $fileName
  */
 public function takeScreenshot($fileName = 'failure.png')
 {
     $screenshot = $this->mink->getSession()->getScreenshot();
     foreach ($this->imageDrivers as $imageDriver) {
         $imageUrl = $imageDriver->upload($screenshot, $fileName);
         $this->output->writeln('Screenshot has been taken. Open image at ' . $imageUrl);
     }
 }
 /**
  * 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));
 }
예제 #3
0
 /**
  * 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();
 }
 function its_printFooter_should_write_empty_line(Formatter $formatter, OutputPrinter $printer, TestResult $testResult)
 {
     $printer->writeln()->shouldBeCalled();
     $formatter->getOutputPrinter()->shouldBecalled()->willReturn($printer);
     $this->printFooter($formatter, $testResult);
 }
 /**
  * Triggers after running tests.
  *
  * @param TestworkEvent\AfterExerciseCompleted $event
  */
 public function onAfterExercise(TestworkEvent\AfterExerciseCompleted $event)
 {
     $this->timer->stop();
     $this->renderer->render();
     $this->printer->write($this->renderer->getResult());
 }
예제 #6
0
 /**
  * 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()))));
 }
예제 #7
0
 /**
  * Prints hook stat.
  *
  * @param OutputPrinter $printer
  * @param string        $name
  * @param string        $path
  * @param string        $style
  * @param null|string   $stdOut
  * @param null|string   $error
  */
 private function printStat(OutputPrinter $printer, $name, $path, $style, $stdOut, $error)
 {
     $path = $this->relativizePaths($path);
     $printer->writeln(sprintf('    {+%s}%s{-%s} {+comment}# %s{-comment}', $style, $name, $style, $path));
     $pad = function ($line) {
         return '      ' . $line;
     };
     if (null !== $stdOut) {
         $padText = function ($line) {
             return '      │ ' . $line;
         };
         $stdOutString = array_map($padText, explode("\n", $stdOut));
         $printer->writeln(implode("\n", $stdOutString));
     }
     if ($error) {
         $exceptionString = implode("\n", array_map($pad, explode("\n", $error)));
         $printer->writeln(sprintf('{+%s}%s{-%s}', $style, $exceptionString, $style));
     }
     $printer->writeln();
 }
예제 #8
0
 /**
  * Prints scenario description (other lines of long title).
  *
  * @param OutputPrinter $printer
  * @param string        $longTitle
  */
 private function printDescription(OutputPrinter $printer, $longTitle)
 {
     $lines = explode("\n", $longTitle);
     array_shift($lines);
     foreach ($lines as $line) {
         $printer->writeln(sprintf('%s%s', $this->subIndentText, $line));
     }
 }
예제 #9
0
 /**
  * Prints examples table header.
  *
  * @param OutputPrinter    $printer
  * @param ExampleTableNode $table
  */
 private function printExamplesTableHeader(OutputPrinter $printer, ExampleTableNode $table)
 {
     $printer->writeln(sprintf('%s{+keyword}%s:{-keyword}', $this->indentText, $table->getKeyword()));
     $rowNum = 0;
     $wrapper = $this->getWrapperClosure();
     $row = $table->getRowAsStringWithWrappedValues($rowNum, $wrapper);
     $printer->writeln(sprintf('%s%s', $this->subIndentText, $row));
 }
예제 #10
0
 /**
  * Prints feature description using provided printer.
  *
  * @param OutputPrinter $printer
  * @param FeatureNode   $feature
  */
 private function printDescription(OutputPrinter $printer, FeatureNode $feature)
 {
     if (!$feature->getDescription()) {
         $printer->writeln();
         return;
     }
     foreach (explode("\n", $feature->getDescription()) as $descriptionLine) {
         $printer->writeln(sprintf('%s%s', $this->subIndentText, $descriptionLine));
     }
     $printer->writeln();
 }
예제 #11
0
 /**
  * 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));
 }
예제 #12
0
 /**
  * Prints example title.
  *
  * @param OutputPrinter $printer
  * @param ExampleNode   $example
  */
 private function printTitle(OutputPrinter $printer, ExampleNode $example)
 {
     $printer->write(sprintf('%s%s', $this->indentText, $example->getTitle()));
 }
예제 #13
0
 /**
  * Prints step exception (if has one).
  *
  * @param OutputPrinter $printer
  * @param StepResult    $result
  */
 private function printException(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));
 }
예제 #14
0
 /**
  * Prints defined step path.
  *
  * @param OutputPrinter     $printer
  * @param DefinedStepResult $result
  * @param integer           $scenarioWidth
  * @param integer           $stepWidth
  */
 private function printDefinedStepPath(OutputPrinter $printer, DefinedStepResult $result, $scenarioWidth, $stepWidth)
 {
     $path = $result->getStepDefinition()->getPath();
     $spacing = str_repeat(' ', max(0, $scenarioWidth - $stepWidth));
     $printer->writeln(sprintf('%s {+comment}# %s{-comment}', $spacing, $path));
 }
예제 #15
0
파일: ListPrinter.php 프로젝트: sroze/Behat
 /**
  * Prints hook stat.
  *
  * @param OutputPrinter $printer
  * @param integer       $number
  * @param StepStatV2    $stat
  * @param string        $style
  */
 private function printStepStat(OutputPrinter $printer, $number, StepStatV2 $stat, $style)
 {
     $maxLength = max(mb_strlen($stat->getScenarioText(), 'utf8'), mb_strlen($stat->getStepText(), 'utf8') + 2) + 1;
     $printer->writeln(sprintf('%03d {+%s}%s{-%s}%s{+comment}# %s{-comment}', $number, $style, $stat->getScenarioText(), $style, str_pad(' ', $maxLength - mb_strlen($stat->getScenarioText(), 'utf8')), $this->relativizePaths($stat->getScenarioPath())));
     $printer->writeln(sprintf('      {+%s}%s{-%s}%s{+comment}# %s{-comment}', $style, $stat->getStepText(), $style, str_pad(' ', $maxLength - mb_strlen($stat->getStepText(), 'utf8') - 2), $this->relativizePaths($stat->getStepPath())));
     $pad = function ($line) {
         return '        ' . $line;
     };
     if (null !== $stat->getStdOut()) {
         $padText = function ($line) {
             return '        │ ' . $line;
         };
         $stdOutString = array_map($padText, explode("\n", $stat->getStdOut()));
         $printer->writeln(implode("\n", $stdOutString));
     }
     if ($stat->getError()) {
         $exceptionString = implode("\n", array_map($pad, explode("\n", $stat->getError())));
         $printer->writeln(sprintf('{+%s}%s{-%s}', $style, $exceptionString, $style));
     }
     $printer->writeln();
 }