public function testExceptionIsThrownWhenGettingRunnerIfNoFactorySupportsExercise() { $exercise = new CliExerciseImpl(); $manager = new RunnerManager(); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Exercise Type: "CLI" not supported'); $manager->getRunner($exercise); }
/** * @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); }
public function setUp() { $results = new ResultAggregator(); $eventDispatcher = new EventDispatcher($results); $r = new \ReflectionClass(CliRunner::class); $rp = $r->getProperty('requiredChecks'); $rp->setAccessible(true); $rp->setValue([]); $runnerManager = new RunnerManager(); $runnerManager->addFactory(new CliRunnerFactory($eventDispatcher)); $this->exerciseDispatcher = new ExerciseDispatcher($runnerManager, $results, $eventDispatcher, new CheckRepository()); $this->exercise = new TimeServer(new TcpSocketFactory()); }
/** * Run a student's solution against a specific exercise. Does not invoke checks. Invokes the * correct runner for the exercise based on the exercise type. Various events are triggered throughout the process. * The output of the solution is written directly to the `OutputInterface` instance. * * @param ExerciseInterface $exercise The exercise instance. * @param Input $input The command line arguments passed to the command. * @param OutputInterface $output An output instance capable of writing to stdout. * @return bool Whether the solution ran successfully or not. */ public function run(ExerciseInterface $exercise, Input $input, OutputInterface $output) { $exercise->configure($this); $this->eventDispatcher->dispatch(new ExerciseRunnerEvent('run.start', $exercise, $input)); try { $exitStatus = $this->runnerManager->getRunner($exercise)->run($input, $output); } finally { $this->eventDispatcher->dispatch(new ExerciseRunnerEvent('run.finish', $exercise, $input)); } return $exitStatus; }
}, 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', [], VerifyCommand::class), new CommandDefinition('run', [], RunCommand::class), new CommandDefinition('credits', [], CreditsCommand::class)], 'menu', $c->get(EventDispatcher::class), $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) { return $c->get($exerciseClass); }, $c->get('exercises'))); }, EventDispatcher::class => factory(EventDispatcherFactory::class), EventDispatcherFactory::class => object(), RunnerManager::class => function (ContainerInterface $c) { $manager = new RunnerManager(); $manager->addFactory(new CliRunnerFactory($c->get(EventDispatcher::class))); $manager->addFactory(new CgiRunnerFactory($c->get(EventDispatcher::class), $c->get(RequestRenderer::class))); $manager->addFactory(new CustomVerifyingRunnerFactory()); return $manager; }, MenuCommand::class => function (ContainerInterface $c) { return new MenuCommand($c->get('menu')); }, PrintCommand::class => function (ContainerInterface $c) { return new PrintCommand($c->get('appName'), $c->get(ExerciseRepository::class), $c->get(UserState::class), $c->get(MarkdownRenderer::class), $c->get(OutputInterface::class)); }, VerifyCommand::class => function (ContainerInterface $c) { return new VerifyCommand($c->get(ExerciseRepository::class), $c->get(ExerciseDispatcher::class), $c->get(UserState::class), $c->get(UserStateSerializer::class), $c->get(OutputInterface::class), $c->get(ResultsRenderer::class)); }, RunCommand::class => function (ContainerInterface $c) { return new RunCommand($c->get(ExerciseRepository::class), $c->get(ExerciseDispatcher::class), $c->get(UserState::class), $c->get(OutputInterface::class)); }, CreditsCommand::class => function (ContainerInterface $c) { return new CreditsCommand($c->get('coreContributors'), $c->get('appContributors'), $c->get(OutputInterface::class), $c->get(Color::class)); }, HelpCommand::class => function (ContainerInterface $c) {