class 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
- class \Drupal\BuildTests\Framework\BuildTestBase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\TestTools\Extension\RequiresComposerTrait, \Drupal\Tests\PhpUnitCompatibilityTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\BuildTests\Command\DrScriptTest extends \Drupal\BuildTests\Framework\BuildTestBase
Expanded class hierarchy of DrScriptTest
File
-
core/
tests/ Drupal/ BuildTests/ Command/ DrScriptTest.php, line 20
Namespace
Drupal\BuildTests\CommandView 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:');
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
|---|---|---|---|---|---|
| BuildTestBase::$commandProcess | private | property | The most recent command process. | ||
| BuildTestBase::$destroyBuild | protected | property | Default to destroying build artifacts after a test finishes. | ||
| BuildTestBase::$hostName | private static | property | Our native host name, used by PHP when it starts up the server. | ||
| BuildTestBase::$hostPort | private | property | Port that will be tested. | ||
| BuildTestBase::$mink | private | property | The Mink session manager. | ||
| BuildTestBase::$phpFinder | private | property | The PHP executable finder. | ||
| BuildTestBase::$portLocks | private | property | A list of ports used by the test. | ||
| BuildTestBase::$serverDocroot | private | property | The docroot for the server process. | ||
| BuildTestBase::$serverProcess | private | property | The process that's running the HTTP server. | ||
| BuildTestBase::$workspaceDir | private | property | The working directory where this test will manipulate files. | ||
| BuildTestBase::assertCommandExitCode | public | function | Asserts that the last command returned the specified exit code. | ||
| BuildTestBase::assertCommandOutputContains | public | function | Assert that text is present in the output of the most recent command. | ||
| BuildTestBase::assertCommandSuccessful | public | function | Asserts that the last command ran without error. | ||
| BuildTestBase::assertDrupalVisit | public | function | Helper function to assert that the last visit was a Drupal site. | ||
| BuildTestBase::assertErrorOutputContains | public | function | Assert that text is present in the error output of the most recent command. | ||
| BuildTestBase::assertErrorOutputNotContains | public | function | Assert text is not present in the error output of the most recent command. | ||
| BuildTestBase::checkPortIsAvailable | protected | function | Checks whether a port is available. | ||
| BuildTestBase::copyCodebase | public | function | Copy the current working codebase into a workspace. | 1 | |
| BuildTestBase::executeCommand | public | function | Run a command. | ||
| BuildTestBase::findAvailablePort | protected | function | Discover an available port number. | ||
| BuildTestBase::getCodebaseFinder | public | function | Get a default Finder object for a Drupal codebase. | ||
| BuildTestBase::getComposerRoot | public | function | Gets the path to the Composer root directory. | ||
| BuildTestBase::getDrupalRoot | public | function | Get the root path of this Drupal codebase. | Overrides DrupalTestCaseTrait::getDrupalRoot | |
| BuildTestBase::getDrupalRootStatic | public static | function | Get the root path of this Drupal codebase. | ||
| BuildTestBase::getMink | public | function | Get the Mink instance. | ||
| BuildTestBase::getPortNumber | protected | function | Get the port number for requests. | ||
| BuildTestBase::getWorkingPath | protected | function | Get the working directory within the workspace, creating if necessary. | ||
| BuildTestBase::getWorkingPathDrupalRoot | public | function | Gets the working path for Drupal core. | ||
| BuildTestBase::getWorkspaceDirectory | public | function | Full path to the workspace where this test can build. | ||
| BuildTestBase::getWorkspaceDrupalRoot | public | function | Gets the path to Drupal root in the workspace directory. | ||
| BuildTestBase::initMink | protected | function | Set up the Mink session manager. | ||
| BuildTestBase::instantiateServer | protected | function | Do the work of making a server process. | 1 | |
| BuildTestBase::setUp | protected | function | 7 | ||
| BuildTestBase::standUpServer | protected | function | Makes a local test server using PHP's internal HTTP server. | ||
| BuildTestBase::stopServer | protected | function | Stop the HTTP server, zero out all necessary variables. | ||
| BuildTestBase::tearDown | protected | function | 5 | ||
| BuildTestBase::visit | public | function | Visit a URI on the HTTP server. | 1 | |
| DrScriptTest::testDirectCallFromWebDocroot | public | function | Tests calling a CLI script directly when the Drupal root is in web/. | ||
| DrupalTestCaseTrait::$root | protected | property | The Drupal root directory. | ||
| DrupalTestCaseTrait::checkErrorHandlerOnTearDown | public | function | Checks the test error handler after test execution. | 1 | |
| DrupalTestCaseTrait::checkLegacySymfonyDeprecationHelperEnvVariable | public | function | Checks legacy SYMFONY_DEPRECATIONS_HELPER env variable is not used. | ||
| DrupalTestCaseTrait::expectExceptionMessageIs | protected | function | Expects an exactly matching exception message. | ||
| DrupalTestCaseTrait::expectExceptionMessageIsOrContains | protected | function | Expects an exception message containing a specified string. | ||
| DrupalTestCaseTrait::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | ||
| DrupalTestCaseTrait::setUpRoot | final protected | function | Ensure that the $root property is set initially. | ||
| DrupalTestCaseTrait::skipTestWithAttribute | final protected | function | Supports skipping tests with the Skip attribute. | ||
| RequiresComposerTrait::requiresComposer | public static | function | #[BeforeClass] |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.