function TestSiteInstallCommand::execute

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

File

core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php, line 84

Class

TestSiteInstallCommand
Command to create a test Drupal site.

Namespace

Drupal\TestSite\Commands

Code

protected function execute(InputInterface $input, OutputInterface $output) {
    // Determines and validates the setup class prior to installing a database
    // to avoid creating unnecessary sites.
    $root = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
    chdir($root);
    $class_name = $this->getSetupClass($input->getOption('setup-file'));
    // Ensure we can install a site in the sites/simpletest directory.
    $this->ensureDirectory($root);
    $db_url = $input->getOption('db-url');
    $base_url = $input->getOption('base-url');
    putenv("SIMPLETEST_DB={$db_url}");
    putenv("SIMPLETEST_BASE_URL={$base_url}");
    // Manage site fixture.
    $this->setup($input->getOption('install-profile'), $class_name, $input->getOption('langcode'));
    $user_agent = drupal_generate_test_ua($this->databasePrefix);
    if ($input->getOption('json')) {
        $output->writeln(json_encode([
            'db_prefix' => $this->databasePrefix,
            'user_agent' => $user_agent,
            'site_path' => $this->siteDirectory,
        ]));
    }
    else {
        $output->writeln('<info>Successfully installed a test site</info>');
        $io = new SymfonyStyle($input, $output);
        $io->table([], [
            [
                'Database prefix',
                $this->databasePrefix,
            ],
            [
                'User agent',
                $user_agent,
            ],
            [
                'Site path',
                $this->siteDirectory,
            ],
        ]);
    }
    return 0;
}

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