function TestSiteTearDownCommand::execute

Same name in other branches
  1. 9 core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php \Drupal\TestSite\Commands\TestSiteTearDownCommand::execute()
  2. 8.9.x core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php \Drupal\TestSite\Commands\TestSiteTearDownCommand::execute()
  3. 10 core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php \Drupal\TestSite\Commands\TestSiteTearDownCommand::execute()

File

core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php, line 42

Class

TestSiteTearDownCommand
Command to tear down a test Drupal site.

Namespace

Drupal\TestSite\Commands

Code

protected function execute(InputInterface $input, OutputInterface $output) : int {
    $root = dirname(__DIR__, 5);
    chdir($root);
    $db_prefix = $input->getArgument('db-prefix');
    // Validate the db_prefix argument.
    try {
        $test_database = new TestDatabase($db_prefix);
    } catch (\InvalidArgumentException) {
        $io = new SymfonyStyle($input, $output);
        $io->getErrorStyle()
            ->error("Invalid database prefix: {$db_prefix}\n\nValid database prefixes match the regular expression '/test(\\d+)\$/'. For example, 'test12345678'.");
        // Display the synopsis of the command like Composer does.
        $output->writeln(sprintf('<info>%s</info>', sprintf($this->getSynopsis(), $this->getName())), OutputInterface::VERBOSITY_QUIET);
        return 1;
    }
    $db_url = $input->getOption('db-url');
    putenv("SIMPLETEST_DB={$db_url}");
    // Handle the cleanup of the test site.
    $this->tearDown($test_database, $db_url);
    // Release the test database prefix lock.
    if (!$input->getOption('keep-lock')) {
        $test_database->releaseLock();
    }
    $output->writeln("<info>Successfully uninstalled {$db_prefix} test site</info>");
    return 0;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.