Пример #1
0
 /**
  * @param CliMenu $menu
  */
 public function __invoke(CliMenu $menu)
 {
     $menu->close();
     $item = $menu->getSelectedItem();
     $exercise = $this->exerciseRepository->findByName($item->getText());
     $exercises = $this->exerciseRepository->findAll();
     $this->userState->setCurrentExercise($item->getText());
     $this->userStateSerializer->serialize($this->userState);
     $numExercises = count($exercises);
     $exerciseIndex = array_search($exercise, $exercises) + 1;
     $output = "\n";
     $output .= $this->color->__invoke(' LEARN YOU THE PHP FOR MUCH WIN! ')->magenta()->bold() . "\n";
     $output .= $this->color->__invoke('*********************************')->magenta()->bold() . "\n";
     $output .= "\n";
     $output .= $this->color->__invoke(" " . $exercise->getName())->yellow()->bold() . "\n";
     $output .= $this->color->__invoke(sprintf(" Exercise %d of %d\n\n", $exerciseIndex, $numExercises))->yellow();
     $content = file_get_contents($exercise->getProblem());
     $doc = $this->markdownRenderer->render($content);
     $doc = str_replace('{appname}', $this->appName, $doc);
     $output .= $doc;
     $output .= "\n";
     $output .= $this->helpLine('To print these instructions again, run', 'print');
     $output .= $this->helpLine('To execute your program in a test environment, run', 'run program.php');
     $output .= $this->helpLine('To verify your program, run', 'verify program.php');
     $output .= $this->helpLine('For help run', 'help');
     $output .= "\n\n";
     $this->output->write($output);
 }
Пример #2
0
 public function testVerifyDoesNotAddCompletedExerciseAndReturnsCorrectCodeOnFailure()
 {
     $file = tempnam(sys_get_temp_dir(), 'pws');
     touch($file);
     $input = new Input('appName', ['program' => $file]);
     $exercise = new CliExerciseImpl();
     $repo = new ExerciseRepository([$exercise]);
     $state = new UserState();
     $state->setCurrentExercise('my-exercise');
     $color = new Color();
     $color->setForceStyle(true);
     $output = new StdOutput($color, $this->createMock(TerminalInterface::class));
     $serializer = $this->createMock(UserStateSerializer::class);
     $serializer->expects($this->never())->method('serialize')->with($state);
     $renderer = $this->createMock(ResultsRenderer::class);
     $results = new ResultAggregator();
     $results->add(new Failure($this->check, 'cba'));
     $dispatcher = $this->createMock(ExerciseDispatcher::class);
     $dispatcher->expects($this->once())->method('verify')->with($exercise, $input)->will($this->returnValue($results));
     $renderer->expects($this->once())->method('render')->with($results, $exercise, $state, $output);
     $command = new VerifyCommand($repo, $dispatcher, $state, $serializer, $output, $renderer);
     $this->assertEquals(1, $command->__invoke($input));
     $this->assertEquals([], $state->getCompletedExercises());
     unlink($file);
 }
Пример #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());
 }
Пример #4
0
 public function test()
 {
     $input = new Input('appName', ['program' => 'solution.php']);
     $exercise = new CliExerciseImpl();
     $repo = new ExerciseRepository([$exercise]);
     $state = new UserState();
     $state->setCurrentExercise('my-exercise');
     $color = new Color();
     $color->setForceStyle(true);
     $output = new StdOutput($color, $this->createMock(TerminalInterface::class));
     $dispatcher = $this->prophesize(ExerciseDispatcher::class);
     $dispatcher->run($exercise, $input, $output)->shouldBeCalled();
     $command = new RunCommand($repo, $dispatcher->reveal(), $state, $output);
     $command->__invoke($input);
 }
Пример #5
0
 public function testExerciseIsPrintedIfAssigned()
 {
     $file = tempnam(sys_get_temp_dir(), 'pws');
     file_put_contents($file, '### Exercise 1');
     $exercise = $this->createMock(ExerciseInterface::class);
     $exercise->expects($this->once())->method('getProblem')->will($this->returnValue($file));
     $exercise->expects($this->once())->method('getName')->will($this->returnValue('current-exercise'));
     $repo = new ExerciseRepository([$exercise]);
     $state = new UserState();
     $state->setCurrentExercise('current-exercise');
     $output = $this->createMock(OutputInterface::class);
     $renderer = $this->createMock(MarkdownRenderer::class);
     $renderer->expects($this->once())->method('render')->with('### Exercise 1')->will($this->returnValue('### Exercise 1'));
     $output->expects($this->once())->method('write')->with('### Exercise 1');
     $command = new PrintCommand('phpschool', $repo, $state, $renderer, $output);
     $command->__invoke();
     unlink($file);
 }