function ScaffoldUpgradeTest::testUpgradeWithStaleHandler
Same name and namespace in other branches
- main core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ScaffoldUpgradeTest.php \Drupal\Tests\Composer\Plugin\Scaffold\Functional\ScaffoldUpgradeTest::testUpgradeWithStaleHandler()
Tests upgrading the plugin when the Handler class is stale.
See also
\Drupal\Composer\Plugin\Scaffold\Plugin::ensureAutoloadRuntimeFile()
File
-
core/
tests/ Drupal/ Tests/ Composer/ Plugin/ Scaffold/ Functional/ ScaffoldUpgradeTest.php, line 114
Class
- ScaffoldUpgradeTest
- Tests Upgrading the Composer Scaffold plugin.
Namespace
Drupal\Tests\Composer\Plugin\Scaffold\FunctionalCode
public function testUpgradeWithStaleHandler() : void {
$this->fixturesDir = $this->fixtures
->tmpDir($this->name());
$pluginSource = $this->fixturesDir . '/composer-scaffold-plugin';
$replacements = [
'SYMLINK' => 'false',
'PROJECT_ROOT' => $pluginSource,
];
$this->fixtures
->cloneFixtureProjects($this->fixturesDir, $replacements);
$sut = $this->fixturesDir . '/drupal-drupal';
// The Scaffold plugin must be copied rather than symlinked into the
// vendor directory, so that the installed plugin keeps the old code
// after the plugin source is updated below.
$composerJson = json_decode(file_get_contents("{$sut}/composer.json"), TRUE);
$composerJson['repositories']['composer-scaffold']['options']['symlink'] = FALSE;
file_put_contents("{$sut}/composer.json", json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
// Create an "old" copy of the Scaffold plugin that behaves like the
// plugin from before Drupal 11.4.0: it knows nothing about
// autoload_runtime.php.
$this->copyPluginVersion($pluginSource, '100.0.0', TRUE);
$this->mustExec('composer install --no-ansi', $sut);
$this->assertFileExists("{$sut}/autoload.php");
$this->assertFileDoesNotExist("{$sut}/autoload_runtime.php");
// Replace the plugin source with the current code, then require a
// package containing a Composer plugin flagged with
// 'plugin-modifies-downloads'. Composer will install that package before
// the Scaffold plugin's update operation, so its post-package-install
// event fires while the old Scaffold plugin code is still installed,
// pinning the old Handler class for the remainder of the process.
$this->copyPluginVersion($pluginSource, '100.0.1', FALSE);
$composerJson['repositories']['downloads-modifier'] = [
'type' => 'path',
'url' => '../composer-plugin-downloads-modifier',
];
$composerJson['require']['fixtures/composer-plugin-downloads-modifier'] = '*';
$composerJson['config']['allow-plugins']['fixtures/composer-plugin-downloads-modifier'] = TRUE;
file_put_contents("{$sut}/composer.json", json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
$stdout = $this->mustExec('composer update --no-ansi --no-interaction 2>&1', $sut);
// Verify that this test executed the stale Handler class: the
// downloads-modifier plugin must have been installed before the Scaffold
// plugin was updated, and the marker written by the stale Handler code
// must appear in the output.
$installPos = strpos($stdout, 'Installing fixtures/composer-plugin-downloads-modifier');
$upgradePos = strpos($stdout, 'Upgrading drupal/core-composer-scaffold (100.0.0 => 100.0.1):');
$this->assertNotFalse($installPos, $stdout);
$this->assertNotFalse($upgradePos, $stdout);
$this->assertLessThan($upgradePos, $installPos, $stdout);
$this->assertStringContainsString('SCAFFOLD_TEST_STALE_HANDLER', $stdout);
// Even though the stale Handler did not generate autoload_runtime.php,
// the refreshed Plugin class must have generated it.
$this->assertFileExists("{$sut}/autoload_runtime.php");
$this->assertStringContainsString("require __DIR__ . '/vendor/autoload_runtime.php'", file_get_contents("{$sut}/autoload_runtime.php"));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.