コード例 #1
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;
 }
コード例 #2
0
ファイル: UserStateTest.php プロジェクト: jacmoe/php-workshop
 public function testAddCompletedExercise()
 {
     $state = new UserState([], 'exercise1');
     $this->assertTrue($state->isAssignedExercise());
     $this->assertSame([], $state->getCompletedExercises());
     $this->assertSame('exercise1', $state->getCurrentExercise());
     $state->addCompletedExercise('exercise1');
     $this->assertSame(['exercise1'], $state->getCompletedExercises());
     $this->assertSame('exercise1', $state->getCurrentExercise());
 }
コード例 #3
0
ファイル: VerifyCommand.php プロジェクト: jacmoe/php-workshop
 /**
  * @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;
 }