function DrScriptTest::testDirectCallFromWebDocroot

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/BuildTests/Command/DrScriptTest.php \Drupal\BuildTests\Command\DrScriptTest::testDirectCallFromWebDocroot()

Tests calling a CLI script directly when the Drupal root is in web/.

Attributes

#[TestWith([ 'dr', ])] #[TestWith([ 'drupal', ])]

Parameters

string $script: The name of the script in core/scripts.

File

core/tests/Drupal/BuildTests/Command/DrScriptTest.php, line 29

Class

DrScriptTest
Tests running the CLI scripts directly from a web/ docroot.

Namespace

Drupal\BuildTests\Command

Code

public function testDirectCallFromWebDocroot(string $script) : void {
  // Build a small project with the Drupal root in web/, and only the files
  // the scripts need. Like the scaffold plugin does for a real project, the
  // autoload files in web/ point to the vendor directory outside of it.
  $vendor = $this->getComposerRoot() . '/vendor';
  $web = $this->getWorkspaceDirectory() . '/web';
  $fs = new Filesystem();
  // The drupal script includes dr, so the test needs both.
  foreach ([
    'dr',
    'drupal',
  ] as $file) {
    $fs->copy($this->root . "/core/scripts/{$file}", "{$web}/core/scripts/{$file}");
  }
  $fs->dumpFile("{$web}/autoload.php", "<?php\n\nreturn require '{$vendor}/autoload.php';\n");
  $fs->dumpFile("{$web}/autoload_runtime.php", "<?php\n\n\$_ENV['APP_RUNTIME'] ??= \\Drupal\\Core\\Runtime\\DrupalRuntime::class;\nreturn require '{$vendor}/autoload_runtime.php';\n");
  $php = (new PhpExecutableFinder())->find();
  $this->executeCommand(escapeshellarg($php) . " core/scripts/{$script} list", 'web');
  $this->assertCommandSuccessful();
  $this->assertCommandOutputContains('Available commands:');
}

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