/** * @return int|void */ public function __invoke() { $currentExercise = $this->userState->getCurrentExercise(); $exercise = $this->exerciseRepository->findByName($currentExercise); $markDown = file_get_contents($exercise->getProblem()); $doc = $this->markdownRenderer->render($markDown); $doc = str_replace('{appname}', $this->appName, $doc); $this->output->write($doc); }
/** * @param Event $event */ public function __invoke(Event $event) { /** @var CommandDefinition $command */ $command = $event->getParameter('command'); if (!in_array($command->getName(), ['verify', 'run'])) { return; } $currentExercise = $this->exerciseRepository->findByName($this->userState->getCurrentExercise()); $this->runnerManager->configureInput($currentExercise, $command); }
public function testSetCompletedExercise() { $state = new UserState(['exercise1']); $this->assertFalse($state->isAssignedExercise()); $this->assertNull($state->getCurrentExercise()); $this->assertSame(['exercise1'], $state->getCompletedExercises()); $state->setCurrentExercise('exercise2'); $this->assertTrue($state->isAssignedExercise()); $this->assertSame('exercise2', $state->getCurrentExercise()); $this->assertSame(['exercise1'], $state->getCompletedExercises()); }
/** * @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; }
/** * @return int|void */ public function __invoke() { if (!$this->userState->isAssignedExercise()) { $this->output->printError("No active exercises. Select one from the menu"); return 1; } $currentExercise = $this->userState->getCurrentExercise(); $exercise = $this->exerciseRepository->findByName($currentExercise); $markDown = file_get_contents($exercise->getProblem()); $doc = $this->markdownRenderer->render($markDown); $doc = str_replace('{appname}', $this->appName, $doc); $this->output->write($doc); }
/** * @param string $appName * @param string $program * * @return int|void */ public function __invoke($appName, $program) { if (!file_exists($program)) { $this->output->printError(sprintf('Could not run. 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()); $this->exerciseDispatcher->run($exercise, $program, $this->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; }
/** * @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()); $this->exerciseDispatcher->run($exercise, $input, $this->output); }