Exemplo n.º 1
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());
 }
Exemplo n.º 2
0
 /**
  * @param ExerciseInterface $exercise
  * @param UserState         $userState
  * @param WorkshopType      $type
  * @return bool
  */
 private function isExerciseDisabled(ExerciseInterface $exercise, UserState $userState, WorkshopType $type)
 {
     static $previous = null;
     if (null === $previous || !$type->isTutorialMode()) {
         $previous = $exercise;
         return false;
     }
     if (in_array($previous->getName(), $userState->getCompletedExercises())) {
         $previous = $exercise;
         return false;
     }
     $previous = $exercise;
     return true;
 }
Exemplo n.º 3
0
 /**
  * @param ExerciseInterface $exercise
  * @param UserState $userState
  * @param OutputInterface $output
  */
 private function renderSuccessInformation(ExerciseInterface $exercise, UserState $userState, OutputInterface $output)
 {
     $output->emptyLine();
     $output->writeLine($this->style(" PASS!", ['green', 'bg_default', 'bold']));
     $output->emptyLine();
     $output->writeLine("Here's the official solution in case you want to compare notes:");
     $output->writeLine($this->lineBreak());
     foreach ($exercise->getSolution()->getFiles() as $file) {
         $output->writeLine($this->style($file->getRelativePath(), ['bold', 'cyan', 'underline']));
         $output->emptyLine();
         $code = $file->getContents();
         if (pathinfo($file->getRelativePath(), PATHINFO_EXTENSION) === 'php') {
             $code = $this->syntaxHighlighter->highlight($code);
         }
         //make sure there is a new line at the end
         $code = preg_replace('/\\n$/', '', $code) . "\n";
         $output->write($code);
         $output->writeLine($this->lineBreak());
     }
     $completedCount = count($userState->getCompletedExercises());
     $numExercises = $this->exerciseRepository->count();
     $output->writeLine(sprintf('You have %d challenges left.', $numExercises - $completedCount));
     $output->writeLine(sprintf('Type "%s" to show the menu.', $this->appName));
     $output->emptyLine();
 }