/**
  * Render the details of each failed request including the mismatching headers and body.
  *
  * @param ResultsRenderer $renderer
  * @return string
  */
 public function render(ResultsRenderer $renderer)
 {
     $results = array_filter($this->result->getIterator()->getArrayCopy(), function (ResultInterface $result) {
         return $result instanceof FailureInterface;
     });
     $output = '';
     foreach ($results as $key => $request) {
         $output .= "\n";
         $output .= $renderer->style(sprintf("Request %02d\n\n", $key + 1), ['bold', 'underline', 'green']);
         if (!$request instanceof CgiOutRequestFailure) {
             $output .= $renderer->renderResult($request);
             $output .= $renderer->lineBreak();
             continue;
         }
         if ($request->headersDifferent()) {
             $output .= sprintf("  %s    %s\n  %s  %s\n", $renderer->style("ACTUAL HEADERS:", ['bold', 'yellow']), $this->headers($request->getActualHeaders(), $renderer), $renderer->style("EXPECTED HEADERS:", ['bold', 'yellow']), $this->headers($request->getExpectedHeaders(), $renderer, false));
         }
         if ($request->bodyDifferent()) {
             if ($request->headersAndBodyDifferent()) {
                 $output .= $renderer->style("  * * * * * * * * *\n\n", ['green', 'bold']);
             }
             $output .= sprintf("  %s    %s\n\n  %s  %s\n", $renderer->style("ACTUAL CONTENT:", ['bold', 'yellow']), $renderer->style(sprintf('"%s"', $request->getActualOutput()), 'red'), $renderer->style("EXPECTED CONTENT:", ['bold', 'yellow']), $renderer->style(sprintf('"%s"', $request->getExpectedOutput()), 'default'));
         }
         $output .= $renderer->lineBreak();
     }
     return $output . "\n";
 }
Exemplo n.º 2
0
 public function testRenderIndividualResult()
 {
     $color = new Color();
     $color->setForceStyle(true);
     $renderer = new ResultsRenderer('app', $color, $this->getMock(TerminalInterface::class), new ExerciseRepository([]), (new Factory())->__invoke(), new ResultRendererFactory());
     $result = new Failure('Failure', 'Some Failure');
     $this->assertSame("  Some Failure\n", $renderer->renderResult($result));
 }
 public function testRenderIndividualResult()
 {
     $color = new Color();
     $color->setForceStyle(true);
     $resultRendererFactory = new ResultRendererFactory();
     $resultRendererFactory->registerRenderer(Failure::class, FailureRenderer::class);
     $terminal = $this->prophesize(TerminalInterface::class);
     $terminal->getWidth()->willReturn(30);
     $renderer = new ResultsRenderer('app', $color, $terminal->reveal(), new ExerciseRepository([]), (new Factory())->__invoke(), $resultRendererFactory);
     $result = new Failure('Failure', 'Some Failure');
     $this->assertSame("         Some Failure\n", $renderer->renderResult($result));
 }
Exemplo n.º 4
0
 /**
  * Render the details of each failed request including the mismatching headers and body.
  *
  * @param ResultsRenderer $renderer
  * @return string
  */
 public function render(ResultsRenderer $renderer)
 {
     $results = array_filter($this->result->getResults(), function (ResultInterface $result) {
         return $result instanceof FailureInterface;
     });
     $output = '';
     if (count($results)) {
         $output .= $renderer->center("Some requests to your solution produced incorrect output!\n");
     }
     foreach ($results as $key => $request) {
         $output .= $renderer->lineBreak();
         $output .= "\n";
         $output .= $renderer->style(sprintf('Request %d', $key + 1), ['bold', 'underline', 'blue']);
         $output .= ' ' . $renderer->style(' FAILED ', ['bg_red', 'bold']) . "\n\n";
         $output .= "Request Details:\n\n";
         $output .= $this->requestRenderer->renderRequest($request->getRequest()) . "\n";
         $output .= $renderer->renderResult($request) . "\n";
     }
     return $output;
 }
Exemplo n.º 5
0
 /**
  * Render the details of each failed request including the mismatching headers and body.
  *
  * @param ResultsRenderer $renderer
  * @return string
  */
 public function render(ResultsRenderer $renderer)
 {
     $results = array_filter($this->result->getResults(), function (ResultInterface $result) {
         return $result instanceof FailureInterface;
     });
     $output = '';
     if (count($results)) {
         $output .= $renderer->center("Some executions of your solution produced incorrect output!\n");
     }
     /** @var FailureInterface $request **/
     foreach ($results as $key => $request) {
         $output .= $renderer->lineBreak();
         $output .= "\n";
         $output .= $renderer->style(sprintf('Execution %d', $key + 1), ['bold', 'underline', 'blue']);
         $output .= ' ' . $renderer->style(' FAILED ', ['bg_red', 'bold']) . "\n\n";
         $output .= $request->getArgs()->isEmpty() ? "Arguments: None\n" : sprintf("Arguments: \"%s\"\n", $request->getArgs()->implode('", "'));
         $output .= "\n" . $renderer->renderResult($request) . "\n";
     }
     return $output;
 }