Chris@0: command = $command; Chris@0: $this->commandTester = new CommandTester($this->command); Chris@0: Chris@0: $application = ApplicationFactory::create(); Chris@0: $helper_set = $application->getHelperSet(); Chris@0: $helper_set->set(new QuestionHelper()); Chris@0: $application->add($this->command); Chris@0: Chris@0: $this->setDirectory(sys_get_temp_dir() . '/dcg_' . uniqid()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Getter for the directory. Chris@0: * Chris@0: * @return string Chris@0: * The directory. Chris@0: */ Chris@0: public function getDirectory() { Chris@0: return $this->directory; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Setter for the directory. Chris@0: * Chris@0: * @param string $directory Chris@0: * The directory. Chris@0: */ Chris@0: public function setDirectory($directory) { Chris@0: $this->directory = $directory; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Getter for the interaction. Chris@0: * Chris@0: * @return array Chris@0: * The interaction. Chris@0: */ Chris@0: public function getInteraction() { Chris@0: return $this->interaction; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Setter for the interaction. Chris@0: * Chris@0: * @param array $interaction Chris@0: * The interaction. Chris@0: */ Chris@0: public function setInteraction(array $interaction) { Chris@0: $this->interaction = $interaction; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Getter for the fixtures. Chris@0: * Chris@0: * @return array Chris@0: * The fixtures. Chris@0: */ Chris@0: public function getFixtures() { Chris@0: return $this->fixtures; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Setter for the fixtures. Chris@0: * Chris@0: * @param array $fixtures Chris@0: * The fixtures. Chris@0: */ Chris@0: public function setFixtures(array $fixtures) { Chris@0: $this->fixtures = $fixtures; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Executes the command. Chris@0: * Chris@0: * @return int Chris@0: * The command exit code Chris@0: */ Chris@0: public function execute() { Chris@0: return $this->commandTester Chris@0: ->setInputs(array_values($this->interaction)) Chris@0: ->execute(['--directory' => $this->getDirectory()]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the display returned by the last execution of the command. Chris@0: * Chris@0: * @return string Chris@0: * The display. Chris@0: */ Chris@0: public function getDisplay() { Chris@0: return $this->commandTester->getDisplay(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets expected display. Chris@0: * Chris@0: * @return string Chris@0: * Expected display. Chris@0: */ Chris@0: public function getExpectedDisplay() { Chris@0: $default_name = Utils::machine2human(basename($this->directory)); Chris@0: Chris@0: $expected_display = "\n"; Chris@0: $name = $this->command->getName(); Chris@0: $title = "Welcome to $name generator!"; Chris@0: $expected_display .= " $title\n"; Chris@0: $expected_display .= str_repeat('–', strlen($title) + 2) . "\n"; Chris@0: Chris@0: foreach ($this->interaction as $question => $answer) { Chris@4: $question = preg_replace('/^<\d*> /', '', $question); Chris@0: $expected_display .= "\n"; Chris@0: $expected_display .= " $question\n"; Chris@4: // Regular question. Chris@4: if (strpos($question, "\n") === FALSE) { Chris@4: $expected_display .= " ➤ \n"; Chris@4: } Chris@4: // Choice question. Chris@4: else { Chris@4: $expected_display .= " ➤➤➤ \n"; Chris@4: } Chris@0: } Chris@0: Chris@0: $expected_display = str_replace('%default_name%', $default_name, $expected_display); Chris@0: $default_machine_name = Utils::human2machine(basename($this->directory)); Chris@0: $expected_display = str_replace('%default_machine_name%', $default_machine_name, $expected_display); Chris@0: Chris@0: $targets = implode("\n • ", array_keys($this->fixtures)); Chris@0: $expected_display .= "\n"; Chris@0: $expected_display .= " The following directories and files have been created or updated:\n"; Chris@0: $expected_display .= "–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––\n"; Chris@0: $expected_display .= " • $targets\n"; Chris@0: $expected_display .= "\n"; Chris@0: return $expected_display; Chris@0: } Chris@0: Chris@0: }