class DrScriptTest

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

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

In projects created from drupal/recommended-project, the vendor directory is next to the Drupal root, not inside it. Running core/scripts/dr directly, instead of through vendor/bin/dr, must still find the autoloader.

Attributes

#[Group('Command')]

Hierarchy

Expanded class hierarchy of DrScriptTest

File

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

Namespace

Drupal\BuildTests\Command
View source
class DrScriptTest extends BuildTestBase {
  
  /**
   * Tests calling a CLI script directly when the Drupal root is in web/.
   *
   * @param string $script
   *   The name of the script in core/scripts.
   */
  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.