/** * @param string $appName * @param string $program * * @return int|void */ public function __invoke($appName, $program) { if (!file_exists($program)) { $this->output->printError(sprintf('Could not run. 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()); $this->exerciseDispatcher->run($exercise, $program, $this->output); }
public function testRun() { $exercise = $this->getMock(ExerciseInterface::class); $output = $this->getMock(OutputInterface::class); $this->mockRunner($exercise); $this->runner->expects($this->once())->method('run')->with($this->file, $output)->will($this->returnValue(true)); $this->assertTrue($this->exerciseDispatcher->run($exercise, $this->file, $output)); }
public function testRun() { $color = new Color(); $color->setForceStyle(true); $output = new StdOutput($color, $terminal = $this->getMock(TerminalInterface::class)); $outputRegEx = "/\n"; $outputRegEx .= '\\[1m\\[4mArguments\\[0m\\[0m'; $outputRegEx .= "\n"; $outputRegEx .= '127.0.0.1, \\d+'; $outputRegEx .= "\n\n"; $outputRegEx .= '\\[1m\\[4mOutput\\[0m\\[0m'; $outputRegEx .= "\n"; $outputRegEx .= '\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}'; $outputRegEx .= "\n/"; $this->expectOutputRegex($outputRegEx); $this->exerciseDispatcher->run($this->exercise, __DIR__ . '/../res/time-server/solution.php', $output); }
public function testRunExercise() { $this->exercise->expects($this->once())->method('getArgs')->will($this->returnValue([])); $this->exercise->expects($this->atLeastOnce())->method('getType')->will($this->returnValue(ExerciseType::CLI())); $this->exercise->expects($this->once())->method('configure')->will($this->returnCallback(function (ExerciseDispatcher $dispatcher) { $dispatcher->requireCheck(DatabaseCheck::class); })); $results = new ResultAggregator(); $eventDispatcher = new EventDispatcher($results); $checkRepository = new CheckRepository([$this->check]); $dispatcher = new ExerciseDispatcher(new RunnerFactory(), $results, $eventDispatcher, $checkRepository); $dispatcher->run($this->exercise, __DIR__ . '/../res/database/user-solution-alter-db.php', $this->createMock(OutputInterface::class)); }
public function testRun() { $input = new Input('app', ['program' => $this->file]); $output = $this->prophesize(OutputInterface::class)->reveal(); $exercise = new CliExerciseImpl('Some Exercise'); $runner = $this->prophesize(ExerciseRunnerInterface::class); $runner->getRequiredChecks()->willReturn([]); $runner->run($input, $output)->willReturn(true); $runnerManager = $this->prophesize(RunnerManager::class); $runnerManager->getRunner($exercise)->willReturn($runner->reveal()); $exerciseDispatcher = new ExerciseDispatcher($runnerManager->reveal(), new ResultAggregator(), $this->prophesize(EventDispatcher::class)->reveal(), new CheckRepository()); $this->assertTrue($exerciseDispatcher->run($exercise, $input, $output)); }
public function testRunExercise() { $this->exercise->expects($this->once())->method('getArgs')->will($this->returnValue([])); $this->exercise->expects($this->once())->method('configure')->will($this->returnCallback(function (ExerciseDispatcher $dispatcher) { $dispatcher->requireCheck(DatabaseCheck::class); })); $this->checkRepository->registerCheck($this->check); $results = new ResultAggregator(); $eventDispatcher = new EventDispatcher($results); $dispatcher = new ExerciseDispatcher($this->getRunnerManager($this->exercise, $eventDispatcher), $results, $eventDispatcher, $this->checkRepository); $dispatcher->run($this->exercise, new Input('app', ['program' => __DIR__ . '/../res/database/user-solution-alter-db.php']), $this->createMock(OutputInterface::class)); }
/** * @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()); $this->exerciseDispatcher->run($exercise, $input, $this->output); }