public function testWhenBeforeChecksFailTheyReturnImmediately() { $this->createExercise(); $this->check->expects($this->once())->method('check')->will($this->returnValue(new Failure('Failure', 'nope'))); $doNotRunMe = $this->getMock(SimpleCheckInterface::class, [], [], 'DoNotRunMeCheck'); $doNotRunMe->expects($this->never())->method('check'); $this->check->expects($this->once())->method('canRun')->with($this->exerciseType)->will($this->returnValue(true)); $this->check->expects($this->once())->method('getExerciseInterface')->will($this->returnValue(ExerciseInterface::class)); $doNotRunMe->expects($this->once())->method('canRun')->with($this->exerciseType)->will($this->returnValue(true)); $doNotRunMe->expects($this->once())->method('getExerciseInterface')->will($this->returnValue(ExerciseInterface::class)); $this->checkRepository->registerCheck($doNotRunMe); $this->exerciseDispatcher->requireCheck(get_class($this->check), ExerciseDispatcher::CHECK_BEFORE); $this->exerciseDispatcher->requireCheck(get_class($doNotRunMe), ExerciseDispatcher::CHECK_BEFORE); $result = $this->exerciseDispatcher->verify($this->exercise, $this->file); $this->assertInstanceOf(ResultAggregator::class, $result); $this->assertFalse($result->isSuccessful()); }
public function testRequireListenableCheckAttachesToDispatcher() { $eventDispatcher = $this->prophesize(EventDispatcher::class)->reveal(); $checkProphecy = $this->prophesize(ListenableCheckInterface::class); $checkProphecy->attach($eventDispatcher)->shouldBeCalled(); $check = $checkProphecy->reveal(); $exerciseDispatcher = new ExerciseDispatcher($this->prophesize(RunnerManager::class)->reveal(), new ResultAggregator(), $eventDispatcher, new CheckRepository([$check])); $exerciseDispatcher->requireCheck(get_class($check)); }
/** * @param ExerciseDispatcher $dispatcher */ public function configure(ExerciseDispatcher $dispatcher) { $dispatcher->requireCheck(FunctionRequirementsCheck::class); }
/** * @param ExerciseDispatcher $dispatcher */ public function configure(ExerciseDispatcher $dispatcher) { $dispatcher->requireCheck(ComposerCheck::class); }
/** * @param ExerciseDispatcher $dispatcher */ public function configure(ExerciseDispatcher $dispatcher) { $dispatcher->requireCheck(DatabaseCheck::class); }
use PhpSchool\PhpWorkshop\Factory\MarkdownCliRendererFactory; use PhpSchool\PhpWorkshop\MarkdownRenderer; use PhpSchool\PhpWorkshop\Result\FunctionRequirementsFailure; use PhpSchool\PhpWorkshop\Result\Success; use PhpSchool\PhpWorkshop\Result\Failure; use PhpSchool\PhpWorkshop\ResultRenderer\FailureRenderer; use PhpSchool\PhpWorkshop\ResultRenderer\FunctionRequirementsFailureRenderer; use PhpSchool\PhpWorkshop\ResultRenderer\ResultsRenderer; use PhpSchool\PhpWorkshop\ResultRenderer\SuccessRenderer; use PhpSchool\PhpWorkshop\UserState; use PhpSchool\PhpWorkshop\UserStateSerializer; use Symfony\Component\Filesystem\Filesystem; return ['appName' => basename($_SERVER['argv'][0]), ExerciseDispatcher::class => factory(function (ContainerInterface $c) { $dispatcher = new ExerciseDispatcher($c->get(RunnerFactory::class), $c->get(ResultAggregator::class), $c->get(EventDispatcher::class), $c->get(CheckRepository::class)); //checks which should always run (probably) $dispatcher->requireCheck(FileExistsCheck::class, ExerciseDispatcher::CHECK_BEFORE); $dispatcher->requireCheck(PhpLintCheck::class, ExerciseDispatcher::CHECK_BEFORE); $dispatcher->requireCheck(CodeParseCheck::class, ExerciseDispatcher::CHECK_BEFORE); return $dispatcher; }), ResultAggregator::class => object(ResultAggregator::class), CheckRepository::class => factory(function (ContainerInterface $c) { return new CheckRepository([$c->get(FileExistsCheck::class), $c->get(PhpLintCheck::class), $c->get(CodeParseCheck::class), $c->get(ComposerCheck::class), $c->get(FunctionRequirementsCheck::class), $c->get(DatabaseCheck::class)]); }), CommandRouter::class => factory(function (ContainerInterface $c) { return new CommandRouter([new CommandDefinition('menu', [], MenuCommand::class), new CommandDefinition('help', [], HelpCommand::class), new CommandDefinition('print', [], PrintCommand::class), new CommandDefinition('verify', ['program'], VerifyCommand::class), new CommandDefinition('run', ['program'], RunCommand::class), new CommandDefinition('credits', [], CreditsCommand::class)], 'menu', $c); }), Color::class => factory(function (ContainerInterface $c) { $colors = new Color(); $colors->setForceStyle(true); return $colors; }), OutputInterface::class => factory(function (ContainerInterface $c) { return new StdOutput($c->get(Color::class), $c->get(TerminalInterface::class)); }), ExerciseRepository::class => factory(function (ContainerInterface $c) { return new ExerciseRepository(array_map(function ($exerciseClass) use($c) {
use PhpSchool\PhpWorkshop\CommandDefinition; use PhpSchool\PhpWorkshop\CommandRouter; use PhpSchool\PhpWorkshop\ExerciseRenderer; use PhpSchool\PhpWorkshop\ExerciseRepository; use PhpSchool\PhpWorkshop\Factory\MarkdownCliRendererFactory; use PhpSchool\PhpWorkshop\MarkdownRenderer; use PhpSchool\PhpWorkshop\ResultRenderer\ResultsRenderer; use PhpSchool\PhpWorkshop\UserState; use PhpSchool\PhpWorkshop\UserStateSerializer; use Symfony\Component\Filesystem\Filesystem; use Faker\Factory as FakerFactory; use Faker\Generator as FakerGenerator; return ['appName' => basename($_SERVER['argv'][0]), WorkshopType::class => WorkshopType::STANDARD(), ExerciseDispatcher::class => function (ContainerInterface $c) { $dispatcher = new ExerciseDispatcher($c->get(RunnerFactory::class), $c->get(ResultAggregator::class), $c->get(EventDispatcher::class), $c->get(CheckRepository::class)); //checks which should always run (probably) $dispatcher->requireCheck(FileExistsCheck::class); $dispatcher->requireCheck(PhpLintCheck::class); $dispatcher->requireCheck(CodeParseCheck::class); return $dispatcher; }, ResultAggregator::class => object(ResultAggregator::class), CheckRepository::class => function (ContainerInterface $c) { return new CheckRepository([$c->get(FileExistsCheck::class), $c->get(PhpLintCheck::class), $c->get(CodeParseCheck::class), $c->get(ComposerCheck::class), $c->get(FunctionRequirementsCheck::class), $c->get(DatabaseCheck::class)]); }, CommandRouter::class => function (ContainerInterface $c) { return new CommandRouter([new CommandDefinition('menu', [], MenuCommand::class), new CommandDefinition('help', [], HelpCommand::class), new CommandDefinition('print', [], PrintCommand::class), new CommandDefinition('verify', ['program'], VerifyCommand::class), new CommandDefinition('run', ['program'], RunCommand::class), new CommandDefinition('credits', [], CreditsCommand::class)], 'menu', $c); }, Color::class => function () { $colors = new Color(); $colors->setForceStyle(true); return $colors; }, OutputInterface::class => function (ContainerInterface $c) { return new StdOutput($c->get(Color::class), $c->get(TerminalInterface::class)); }, ExerciseRepository::class => function (ContainerInterface $c) { return new ExerciseRepository(array_map(function ($exerciseClass) use($c) {
/** * @param ExerciseDispatcher $dispatcher */ public function configure(ExerciseDispatcher $dispatcher) { $dispatcher->requireCheck(ComposerCheck::class, $dispatcher::CHECK_BEFORE); }