function ScaffoldUpgradeTest::copyPluginVersion
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ScaffoldUpgradeTest.php \Drupal\Tests\Composer\Plugin\Scaffold\Functional\ScaffoldUpgradeTest::copyPluginVersion()
Copies the Scaffold plugin source to a target directory with a version.
Parameters
string $target: Directory to place the plugin copy in.
string $version: Version to set in the composer.json of the copy, so that the path repository provides an update when the version is bumped.
bool $stale: When TRUE, remove all knowledge of autoload_runtime.php from the copy to simulate the plugin from before Drupal 11.4.0. A marker is written to output by the modified Handler so that tests can verify that the stale Handler code ran.
File
-
core/
tests/ Drupal/ Tests/ Composer/ Plugin/ Scaffold/ Functional/ ScaffoldUpgradeTest.php, line 183
Class
- ScaffoldUpgradeTest
- Tests Upgrading the Composer Scaffold plugin.
Namespace
Drupal\Tests\Composer\Plugin\Scaffold\FunctionalCode
protected function copyPluginVersion(string $target, string $version, bool $stale) : void {
$filesystem = new Filesystem();
$filesystem->remove($target);
$filesystem->copy($this->fixtures
->projectRoot(), $target);
$composerJson = json_decode(file_get_contents("{$target}/composer.json"), TRUE);
$composerJson['version'] = $version;
file_put_contents("{$target}/composer.json", json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
if ($stale) {
$generateRuntime = <<<'PHP'
// The same is done for the autoload_runtime file that loads the Symfony
// runtime.
if (!GenerateAutoloadRuntimeReferenceFile::autoloadRuntimeFileCommitted($this->io, $this->rootPackageName(), $web_root)) {
$scaffold_results[] = GenerateAutoloadRuntimeReferenceFile::generateAutoloadRuntime($this->io, $this->rootPackageName(), $web_root, $this->getVendorPath());
}
PHP;
$this->replaceCodeInFile("{$target}/Handler.php", $generateRuntime, " \$this->io->write('SCAFFOLD_TEST_STALE_HANDLER');");
$this->replaceCodeInFile("{$target}/Plugin.php", " \$this->ensureAutoloadRuntimeFile();\n", '');
unlink("{$target}/GenerateAutoloadRuntimeReferenceFile.php");
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.