public function testLineBreak()
 {
     $color = new Color();
     $color->setForceStyle(true);
     $terminal = $this->getMock(TerminalInterface::class);
     $terminal->expects($this->once())->method('getWidth')->will($this->returnValue(10));
     $renderer = new ResultsRenderer('app', $color, $terminal, new ExerciseRepository([]), (new Factory())->__invoke(), new ResultRendererFactory());
     $this->assertSame("──────────", $renderer->lineBreak());
 }
 /**
  * @param Input $input The command line arguments passed to the command.
  *
  * @return int|void
  */
 public function __invoke(Input $input)
 {
     $exercise = $this->exerciseRepository->findByName($this->userState->getCurrentExercise());
     $results = $this->exerciseDispatcher->verify($exercise, $input);
     if ($results->isSuccessful()) {
         $this->userState->addCompletedExercise($exercise->getName());
         $this->userStateSerializer->serialize($this->userState);
     }
     $this->resultsRenderer->render($results, $exercise, $this->userState, $this->output);
     return $results->isSuccessful() ? 0 : 1;
 }
 /**
  * @param array $headers
  * @param ResultsRenderer $renderer
  * @param bool $actual
  * @return string
  */
 private function headers(array $headers, ResultsRenderer $renderer, $actual = true)
 {
     $indent = false;
     $output = '';
     foreach ($headers as $name => $value) {
         if ($indent) {
             $output .= str_repeat(' ', 21);
         }
         $output .= $renderer->style(sprintf("%s: %s", $name, $value), $actual ? 'red' : 'default') . "\n";
         $indent = true;
     }
     return $output;
 }
 /**
  * Print a list of the missing, required functions & print a list of used but banned functions.
  *
  * @param ResultsRenderer $renderer
  * @return string
  */
 public function render(ResultsRenderer $renderer)
 {
     $output = '';
     if (count($bannedFunctions = $this->result->getBannedFunctions())) {
         $output .= sprintf("  %s\n%s\n", $renderer->style("Some functions were used which should not be used in this exercise", ['bold', 'underline', 'yellow']), implode("\n", array_map(function (array $call) {
             return sprintf('    %s on line %s', $call['function'], $call['line']);
         }, $bannedFunctions)));
     }
     if (count($missingFunctions = $this->result->getMissingFunctions())) {
         $output .= sprintf("  %s\n%s\n", $renderer->style("Some function requirements were missing. You should use the functions", ['bold', 'underline', 'yellow']), implode("\n", array_map(function ($function) {
             return sprintf('    %s', $function);
         }, $missingFunctions)));
     }
     return $output;
 }
 /**
  * @param string $appName
  * @param string $program
  *
  * @return int|void
  */
 public function __invoke($appName, $program)
 {
     if (!file_exists($program)) {
         $this->output->printError(sprintf('Could not verify. File: "%s" does not exist', $program));
         return 1;
     }
     $program = realpath($program);
     if (!$this->userState->isAssignedExercise()) {
         $this->output->printError("No active exercises. Select one from the menu");
         return 1;
     }
     $exercise = $this->exerciseRepository->findByName($this->userState->getCurrentExercise());
     $results = $this->exerciseDispatcher->verify($exercise, $program);
     if ($results->isSuccessful()) {
         $this->userState->addCompletedExercise($exercise->getName());
         $this->userStateSerializer->serialize($this->userState);
     }
     $this->resultsRenderer->render($results, $exercise, $this->userState, $this->output);
     return $results->isSuccessful() ? 0 : 1;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 public function testRenderAllFailures()
 {
     $color = new Color();
     $color->setForceStyle(true);
     $resultRendererFactory = new ResultRendererFactory();
     $resultRendererFactory->registerRenderer(Failure::class, FailureRenderer::class, function (Failure $failure) {
         $renderer = $this->prophesize(FailureRenderer::class);
         $renderer->render(Argument::type(ResultsRenderer::class))->willReturn($failure->getReason() . "\n");
         return $renderer->reveal();
     });
     $terminal = $this->prophesize(TerminalInterface::class);
     $terminal->getWidth()->willReturn(100);
     $terminal = $terminal->reveal();
     $exerciseRepo = $this->prophesize(ExerciseRepository::class);
     $exerciseRepo->count()->willReturn(2);
     $renderer = new ResultsRenderer('app', $color, $terminal, $exerciseRepo->reveal(), (new Factory())->__invoke(), $resultRendererFactory);
     $resultSet = new ResultAggregator();
     $resultSet->add(new Failure('Failure 1', 'Failure 1'));
     $resultSet->add(new Failure('Failure 2', 'Failure 2'));
     $this->expectOutputString($this->getExpectedOutput());
     $renderer->render($resultSet, $this->createMock(ExerciseInterface::class), new UserState(), new StdOutput($color, $terminal));
 }
 /**
  * @param ResultsRenderer $renderer
  * @return string
  */
 public function render(ResultsRenderer $renderer)
 {
     return sprintf("  %s\n%s\n\n  %s\n%s\n", $renderer->style("ACTUAL", ['bold', 'underline', 'yellow']), $this->indent($renderer->style(sprintf('"%s"', $this->result->getActualOutput()), 'red')), $renderer->style("EXPECTED", ['yellow', 'bold', 'underline']), $this->indent($renderer->style(sprintf('"%s"', $this->result->getExpectedOutput()), 'red')));
 }
 /**
  * Print the actual and expected output.
  *
  * @param ResultsRenderer $renderer
  * @return string
  */
 public function render(ResultsRenderer $renderer)
 {
     return sprintf("  %s\n%s\n\n  %s\n%s\n", $renderer->style('YOUR OUTPUT:', ['bold', 'yellow']), $this->indent($renderer->style(sprintf('"%s"', $this->result->getActualValue()), 'red')), $renderer->style('EXPECTED OUTPUT:', ['bold', 'yellow']), $this->indent($renderer->style(sprintf('"%s"', $this->result->getExpectedValue()), 'green')));
 }
 /**
  * Simply print the reason.
  *
  * @param ResultsRenderer $renderer
  * @return string
  */
 public function render(ResultsRenderer $renderer)
 {
     return $renderer->center($this->result->getReason()) . "\n";
 }