Esempio n. 1
0
 /**
  * @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);
 }
Esempio n. 3
0
 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());
 }
Esempio n. 4
0
 /**
  * @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);
 }
Esempio n. 6
0
 /**
  * @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);
 }
Esempio n. 7
0
 /**
  * @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;
 }
Esempio n. 8
0
 /**
  * @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);
 }