diff -u b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php --- b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php +++ b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php @@ -12,6 +12,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; /** * Command to create a test Drupal site. @@ -64,12 +65,13 @@ protected function configure() { $this->setName('install') ->setDescription('Creates a test Drupal site') - ->setHelp('The details to connect to the test site created will be returned in JSON. It will contain the database prefix and the user agent.') + ->setHelp('The details to connect to the test site created will be displayed upon succes. It will contain the database prefix and the user agent.') ->addOption('setup_class', NULL, InputOption::VALUE_OPTIONAL, 'A PHP class to setup configuration used by the test, for example, \Drupal\TestSite\TestSiteInstallTestScript') ->addOption('db_url', NULL, InputOption::VALUE_OPTIONAL, 'URL for database or SIMPLETEST_DB', getenv('SIMPLETEST_DB')) ->addOption('base_url', NULL, InputOption::VALUE_OPTIONAL, 'Base URL for site under test or SIMPLETEST_BASE_URL', getenv('SIMPLETEST_BASE_URL')) ->addOption('install_profile', NULL, InputOption::VALUE_OPTIONAL, 'Install profile to install the site in. Defaults to testing', 'testing') - ->addOption('langcode', NULL, InputOption::VALUE_OPTIONAL, 'The language to install the site in.'); + ->addOption('langcode', NULL, InputOption::VALUE_OPTIONAL, 'The language to install the site in.') + ->addOption('json', NULL, InputOption::VALUE_NONE, 'Output test site connection details in JSON'); } /** @@ -87,10 +89,21 @@ // Manage site fixture. $this->setup($input->getOption('install_profile'), $input->getOption('setup_class'), $input->getOption('langcode')); - $output->writeln(json_encode([ - 'db_prefix' => $this->databasePrefix, - 'user_agent' => drupal_generate_test_ua($this->databasePrefix), - ])); + $user_agent = drupal_generate_test_ua($this->databasePrefix); + if ($input->getOption('json')) { + $output->writeln(json_encode([ + 'db_prefix' => $this->databasePrefix, + 'user_agent' => $user_agent, + ])); + } + else { + $output->writeln('Successfully installed a test site'); + $io = new SymfonyStyle($input, $output); + $io->table([], [ + ['Database prefix', $this->databasePrefix], + ['User agent', $user_agent], + ]); + } } /** diff -u b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php --- b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php +++ b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php @@ -68,6 +68,7 @@ // Handle the cleanup of the test site. $this->tearDown($db_prefix, $db_url, $kernel->getAppRoot()); + $output->writeln("Successfully uninstalled $db_prefix test site"); } /** diff -u b/core/tests/Drupal/TestSite/TestSiteApplication.php b/core/tests/Drupal/TestSite/TestSiteApplication.php --- b/core/tests/Drupal/TestSite/TestSiteApplication.php +++ b/core/tests/Drupal/TestSite/TestSiteApplication.php @@ -31,7 +31,7 @@ */ public function __construct($autoloader) { $this->autoloader = $autoloader; - parent::__construct('install-test-site', '0.0.1'); + parent::__construct('test-site', '0.0.1'); } /** diff -u b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php --- b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php +++ b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php @@ -83,8 +83,10 @@ $phpBinaryFinder = new PhpExecutableFinder(); $phpBinaryPath = $phpBinaryFinder->find(); - $command_line = $phpBinaryPath . ' core/scripts/test-site.php install --setup_class "' . TestSiteInstallTestScript::class . '" --db_url "' . getenv('SIMPLETEST_DB') . '"'; + // Install a site using the JSON output. + $command_line = $phpBinaryPath . ' core/scripts/test-site.php install --json --setup_class "' . TestSiteInstallTestScript::class . '" --db_url "' . getenv('SIMPLETEST_DB') . '"'; $process = new Process($command_line, $this->root); + // Set the timeout to a value that allows debugging. $process->setTimeout(500); $process->run(); @@ -110,37 +112,50 @@ $this->assertFileExists($test_file); // Install another site so we can ensure tear down only removes one site at - // a time. + // a time. Use the regular output. + $command_line = $phpBinaryPath . ' core/scripts/test-site.php install --setup_class "' . TestSiteInstallTestScript::class . '" --db_url "' . getenv('SIMPLETEST_DB') . '"'; + $process = new Process($command_line, $this->root); + // Set the timeout to a value that allows debugging. + $process->setTimeout(500); $process->run(); - $result = json_decode($process->getOutput(), TRUE); - $other_db_prefix = $result['db_prefix']; + $this->assertContains('Successfully installed a test site', $process->getOutput()); + $this->assertSame(0, $process->getExitCode()); + $regex = '/Database prefix\s+([^\s]*)/'; + $this->assertRegExp($regex, $process->getOutput()); + preg_match('/Database prefix\s+([^\s]*)/', $process->getOutput(), $matches); + $other_db_prefix = $matches[1]; $other_key = $this->addTestDatabase($other_db_prefix); $this->assertGreaterThan(0, count(Database::getConnection('default', $other_key)->schema()->findTables('%'))); // Now test the tear down process as well. $command_line = $phpBinaryPath . ' core/scripts/test-site.php tear-down ' . $db_prefix . ' --db_url "' . getenv('SIMPLETEST_DB') . '"'; $process = new Process($command_line, $this->root); + // Set the timeout to a value that allows debugging. $process->setTimeout(500); $process->run(); $this->assertSame(0, $process->getExitCode()); + $this->assertContains("Successfully uninstalled $db_prefix test site", $process->getOutput()); // Ensure that all the tables and files for this DB prefix are gone. $this->assertCount(0, Database::getConnection('default', $key)->schema()->findTables('%')); $this->assertFileNotExists($test_file); - // Ensure the other sites tables and files still exist. + // Ensure the other site's tables and files still exist. $this->assertGreaterThan(0, count(Database::getConnection('default', $other_key)->schema()->findTables('%'))); $test_database = new TestDatabase($other_db_prefix); $test_file = $this->root . DIRECTORY_SEPARATOR . $test_database->getTestSitePath() . DIRECTORY_SEPARATOR . '.htkey'; $this->assertFileExists($test_file); - // Now test the tear down process as well. + // Tear down the other site installed. $command_line = $phpBinaryPath . ' core/scripts/test-site.php tear-down ' . $other_db_prefix . ' --db_url "' . getenv('SIMPLETEST_DB') . '"'; $process = new Process($command_line, $this->root); + // Set the timeout to a value that allows debugging. $process->setTimeout(500); $process->run(); $this->assertSame(0, $process->getExitCode()); + $this->assertContains("Successfully uninstalled $other_db_prefix test site", $process->getOutput()); + // Ensure that all the tables and files for this DB prefix are gone. $this->assertCount(0, Database::getConnection('default', $other_key)->schema()->findTables('%')); $this->assertFileNotExists($test_file); } @@ -152,7 +167,7 @@ $phpBinaryFinder = new PhpExecutableFinder(); $phpBinaryPath = $phpBinaryFinder->find(); - $command_line = $phpBinaryPath . ' core/scripts/test-site.php install --langcode fr --setup_class "' . TestSiteInstallTestScript::class . '" --db_url "' . getenv('SIMPLETEST_DB') . '"'; + $command_line = $phpBinaryPath . ' core/scripts/test-site.php install --json --langcode fr --setup_class "' . TestSiteInstallTestScript::class . '" --db_url "' . getenv('SIMPLETEST_DB') . '"'; $process = new Process($command_line, $this->root); $process->setTimeout(500); $process->run();