X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Fsrc%2FGeneratorTester.php;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Fsrc%2FGeneratorTester.php;h=cb111be69e0b0077dc94b032cde3841318fcd30d;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/chi-teck/drupal-code-generator/src/GeneratorTester.php b/vendor/chi-teck/drupal-code-generator/src/GeneratorTester.php new file mode 100644 index 000000000..cb111be69 --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/src/GeneratorTester.php @@ -0,0 +1,180 @@ +command = $command; + $this->commandTester = new CommandTester($this->command); + + $application = ApplicationFactory::create(); + $helper_set = $application->getHelperSet(); + $helper_set->set(new QuestionHelper()); + $application->add($this->command); + + $this->setDirectory(sys_get_temp_dir() . '/dcg_' . uniqid()); + } + + /** + * Getter for the directory. + * + * @return string + * The directory. + */ + public function getDirectory() { + return $this->directory; + } + + /** + * Setter for the directory. + * + * @param string $directory + * The directory. + */ + public function setDirectory($directory) { + $this->directory = $directory; + } + + /** + * Getter for the interaction. + * + * @return array + * The interaction. + */ + public function getInteraction() { + return $this->interaction; + } + + /** + * Setter for the interaction. + * + * @param array $interaction + * The interaction. + */ + public function setInteraction(array $interaction) { + $this->interaction = $interaction; + } + + /** + * Getter for the fixtures. + * + * @return array + * The fixtures. + */ + public function getFixtures() { + return $this->fixtures; + } + + /** + * Setter for the fixtures. + * + * @param array $fixtures + * The fixtures. + */ + public function setFixtures(array $fixtures) { + $this->fixtures = $fixtures; + } + + /** + * Executes the command. + * + * @return int + * The command exit code + */ + public function execute() { + return $this->commandTester + ->setInputs(array_values($this->interaction)) + ->execute(['--directory' => $this->getDirectory()]); + } + + /** + * Gets the display returned by the last execution of the command. + * + * @return string + * The display. + */ + public function getDisplay() { + return $this->commandTester->getDisplay(); + } + + /** + * Gets expected display. + * + * @return string + * Expected display. + */ + public function getExpectedDisplay() { + $default_name = Utils::machine2human(basename($this->directory)); + + $expected_display = "\n"; + $name = $this->command->getName(); + $title = "Welcome to $name generator!"; + $expected_display .= " $title\n"; + $expected_display .= str_repeat('–', strlen($title) + 2) . "\n"; + + foreach ($this->interaction as $question => $answer) { + $expected_display .= "\n"; + $expected_display .= " $question\n"; + $expected_display .= " ➤ \n"; + } + + $expected_display = str_replace('%default_name%', $default_name, $expected_display); + $default_machine_name = Utils::human2machine(basename($this->directory)); + $expected_display = str_replace('%default_machine_name%', $default_machine_name, $expected_display); + + $targets = implode("\n • ", array_keys($this->fixtures)); + $expected_display .= "\n"; + $expected_display .= " The following directories and files have been created or updated:\n"; + $expected_display .= "–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––\n"; + $expected_display .= " • $targets\n"; + $expected_display .= "\n"; + return $expected_display; + } + +}