/** * @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 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; }
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)); }