/** * {@inheritDoc} */ public function run(InputInterface $input, OutputInterface $output) { /** @var QuestionHelper $questionHelper */ $questionHelper = $this->getHelper('question'); $output->writeln('Hi'); $planetInput = $questionHelper->ask($input, $output, $this->questionFactory->createPlanetSizeQuestion()); $planet = new Planet($planetInput[0], $planetInput[1]); $newRoverShouldBeAddedQuestion = $this->questionFactory->createNewRoverShouldBeAddedQuestion(); $addRoverQuestion = $this->questionFactory->createAddRoverQuestion(); $sendCommandsToRoverQuestion = $this->questionFactory->createSendCommandsToRoverQuestion(); $newRoverShouldBeAdded = true; while ($newRoverShouldBeAdded) { $roverInput = $questionHelper->ask($input, $output, $addRoverQuestion); $rover = new Rover($roverInput[0], $roverInput[1], $roverInput[2]); $planet->addRover($rover); $commands = $questionHelper->ask($input, $output, $sendCommandsToRoverQuestion); foreach ($commands as $command) { try { $rover->executeCommand($command); } catch (\Exception $e) { $output->writeln(sprintf('Rover\'s mission failed: %s', $e->getMessage())); break; } } $output->writeln(sprintf('Rover\'s final coordinates: (%d:%d). Direction: %s', $rover->getX(), $rover->getY(), $rover->getDirection())); $newRoverShouldBeAdded = $questionHelper->ask($input, $output, $newRoverShouldBeAddedQuestion); } }
/** * @expectedException \Exception */ public function testOnRoverMoveFailure() { $rover = $this->getInvalidRover(); $this->planet->onRoverMove($rover); }