You are here

protected function TestSiteInstallCommand::execute in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php \Drupal\TestSite\Commands\TestSiteInstallCommand::execute()
  2. 9 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) : int {

  // Determines and validates the setup class prior to installing a database
  // to avoid creating unnecessary sites.
  $root = dirname(__DIR__, 5);
  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;
}