Loading composer/Plugin/Scaffold/Handler.php +1 −1 Original line number Diff line number Diff line Loading @@ -164,7 +164,7 @@ public function scaffold() { $scaffold_files->filterFiles($unchanged); // Process the list of scaffolded files. $scaffold_results = $scaffold_files->process($this->io, $scaffold_options); $scaffold_results = $scaffold_files->processScaffoldFiles($this->io, $scaffold_options); // Generate an autoload file in the document root that includes the // autoload.php file in the vendor directory, wherever that is. Drupal Loading composer/Plugin/Scaffold/Operations/ScaffoldFileCollection.php +29 −1 Original line number Diff line number Diff line Loading @@ -130,7 +130,7 @@ public function getIterator() { * @return \Drupal\Composer\Plugin\Scaffold\Operations\ScaffoldResult[] * The results array. */ public function process(IOInterface $io, ScaffoldOptions $scaffold_options) { public function processScaffoldFiles(IOInterface $io, ScaffoldOptions $scaffold_options) { $results = []; foreach ($this as $project_name => $scaffold_files) { $io->write("Scaffolding files for <comment>{$project_name}</comment>:"); Loading @@ -141,6 +141,34 @@ public function process(IOInterface $io, ScaffoldOptions $scaffold_options) { return $results; } /** * Processes the iterator created by ScaffoldFileCollection::create(). * * @param \Drupal\Composer\Plugin\Scaffold\Operations\ScaffoldFileCollection $collection * The iterator to process. * @param \Composer\IO\IOInterface $io * The Composer IO object. * @param \Drupal\Composer\Plugin\Scaffold\ScaffoldOptions $scaffold_options * The scaffold options. * * @return \Drupal\Composer\Plugin\Scaffold\Operations\ScaffoldResult[] * The results array. * * @deprecated. Called when upgrading from the Core Composer Scaffold plugin * version 8.8.x due to a bug in the plugin and handler classes. Do not use * in 8.9.x or 9.x, and remove in Drupal 10.x. */ public static function process(ScaffoldFileCollection $collection, IOInterface $io, ScaffoldOptions $scaffold_options) { $results = []; foreach ($collection as $project_name => $scaffold_files) { $io->write("Scaffolding files for <comment>{$project_name}</comment>:"); foreach ($scaffold_files as $scaffold_file) { $results[$scaffold_file->destination()->relativePath()] = $scaffold_file->process($io, $scaffold_options); } } return $results; } /** * Returns the list of files that have not changed since they were scaffolded. * Loading core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ScaffoldUpgradeTest.php +42 −4 Original line number Diff line number Diff line Loading @@ -2,9 +2,11 @@ namespace Drupal\Tests\Composer\Plugin\Scaffold\Functional; use Composer\Util\Filesystem; use Drupal\Tests\Composer\Plugin\Scaffold\AssertUtilsTrait; use Drupal\Tests\Composer\Plugin\Scaffold\ExecTrait; use Drupal\Tests\Composer\Plugin\Scaffold\Fixtures; use Drupal\Tests\PhpunitCompatibilityTrait; use PHPUnit\Framework\TestCase; /** Loading @@ -24,6 +26,7 @@ class ScaffoldUpgradeTest extends TestCase { use AssertUtilsTrait; use ExecTrait; use PhpunitCompatibilityTrait; /** * The Fixtures object. Loading Loading @@ -63,16 +66,26 @@ public function testScaffoldUpgrade() { // Packagist is disabled in the fixture; we bring it back by removing the // line that disables it. $this->mustExec("composer config --unset repositories.packagist.org", $sut); $stdout = $this->mustExec("composer require drupal/core-composer-scaffold:8.8.0 --no-plugins 2>&1", $sut); $stdout = $this->mustExec("composer require --no-ansi drupal/core-composer-scaffold:8.8.0 --no-plugins 2>&1", $sut); $this->assertContains(" - Installing drupal/core-composer-scaffold (8.8.0):", $stdout); // We can't force the path repo to re-install over the stable version // without removing it, and removing it masks the bugs we are testing for. // We will therefore make a git repo so that we can tag an explicit version // to require. $testVersion = '99.99.99'; $scaffoldPluginTmpRepo = $this->createTmpRepo($this->fixtures->projectRoot(), $this->fixturesDir, $testVersion); // Disable packagist.org and upgrade back to the Scaffold plugin under test. // This puts the `"packagist.org": false` config line back in composer.json // so that Packagist will no longer be used. $this->mustExec("composer remove drupal/core-composer-scaffold --no-plugins", $sut); $this->mustExec("composer config repositories.packagist.org false", $sut); $stdout = $this->mustExec("composer require drupal/core-composer-scaffold:* 2>&1", $sut); $this->assertRegExp("#Installing drupal/core-composer-scaffold.*Symlinking from#", $stdout); $this->mustExec("composer config repositories.composer-scaffold vcs 'file:///$scaffoldPluginTmpRepo'", $sut); // Using 'mustExec' was giving a strange binary string here. $output = $this->mustExec("composer require --no-ansi drupal/core-composer-scaffold:$testVersion 2>&1", $sut); $this->assertStringContainsString("Installing drupal/core-composer-scaffold ($testVersion)", $output); // Remove a scaffold file and run the scaffold command again to prove that // scaffolding is still working. unlink("$sut/index.php"); Loading @@ -81,4 +94,29 @@ public function testScaffoldUpgrade() { $this->assertFileExists("$sut/index.php"); } /** * Copy the provided source directory and create a temporary git repository. * * @param string $source * Path to directory to copy. * @param string $destParent * Path to location to create git repository. * @param string $version * Version to tag the repository with. * @return string * Path to temporary git repository. */ protected function createTmpRepo($source, $destParent, $version) { $target = $destParent . '/' . basename($source); $filesystem = new Filesystem(); $filesystem->copy($source, $target); $this->mustExec("git init", $target); $this->mustExec('git config user.email "scaffoldtest@example.com"', $target); $this->mustExec('git config user.name "Scaffold Test"', $target); $this->mustExec("git add .", $target); $this->mustExec("git commit -m 'Initial commit'", $target); $this->mustExec("git tag $version", $target); return $target; } } Loading
composer/Plugin/Scaffold/Handler.php +1 −1 Original line number Diff line number Diff line Loading @@ -164,7 +164,7 @@ public function scaffold() { $scaffold_files->filterFiles($unchanged); // Process the list of scaffolded files. $scaffold_results = $scaffold_files->process($this->io, $scaffold_options); $scaffold_results = $scaffold_files->processScaffoldFiles($this->io, $scaffold_options); // Generate an autoload file in the document root that includes the // autoload.php file in the vendor directory, wherever that is. Drupal Loading
composer/Plugin/Scaffold/Operations/ScaffoldFileCollection.php +29 −1 Original line number Diff line number Diff line Loading @@ -130,7 +130,7 @@ public function getIterator() { * @return \Drupal\Composer\Plugin\Scaffold\Operations\ScaffoldResult[] * The results array. */ public function process(IOInterface $io, ScaffoldOptions $scaffold_options) { public function processScaffoldFiles(IOInterface $io, ScaffoldOptions $scaffold_options) { $results = []; foreach ($this as $project_name => $scaffold_files) { $io->write("Scaffolding files for <comment>{$project_name}</comment>:"); Loading @@ -141,6 +141,34 @@ public function process(IOInterface $io, ScaffoldOptions $scaffold_options) { return $results; } /** * Processes the iterator created by ScaffoldFileCollection::create(). * * @param \Drupal\Composer\Plugin\Scaffold\Operations\ScaffoldFileCollection $collection * The iterator to process. * @param \Composer\IO\IOInterface $io * The Composer IO object. * @param \Drupal\Composer\Plugin\Scaffold\ScaffoldOptions $scaffold_options * The scaffold options. * * @return \Drupal\Composer\Plugin\Scaffold\Operations\ScaffoldResult[] * The results array. * * @deprecated. Called when upgrading from the Core Composer Scaffold plugin * version 8.8.x due to a bug in the plugin and handler classes. Do not use * in 8.9.x or 9.x, and remove in Drupal 10.x. */ public static function process(ScaffoldFileCollection $collection, IOInterface $io, ScaffoldOptions $scaffold_options) { $results = []; foreach ($collection as $project_name => $scaffold_files) { $io->write("Scaffolding files for <comment>{$project_name}</comment>:"); foreach ($scaffold_files as $scaffold_file) { $results[$scaffold_file->destination()->relativePath()] = $scaffold_file->process($io, $scaffold_options); } } return $results; } /** * Returns the list of files that have not changed since they were scaffolded. * Loading
core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ScaffoldUpgradeTest.php +42 −4 Original line number Diff line number Diff line Loading @@ -2,9 +2,11 @@ namespace Drupal\Tests\Composer\Plugin\Scaffold\Functional; use Composer\Util\Filesystem; use Drupal\Tests\Composer\Plugin\Scaffold\AssertUtilsTrait; use Drupal\Tests\Composer\Plugin\Scaffold\ExecTrait; use Drupal\Tests\Composer\Plugin\Scaffold\Fixtures; use Drupal\Tests\PhpunitCompatibilityTrait; use PHPUnit\Framework\TestCase; /** Loading @@ -24,6 +26,7 @@ class ScaffoldUpgradeTest extends TestCase { use AssertUtilsTrait; use ExecTrait; use PhpunitCompatibilityTrait; /** * The Fixtures object. Loading Loading @@ -63,16 +66,26 @@ public function testScaffoldUpgrade() { // Packagist is disabled in the fixture; we bring it back by removing the // line that disables it. $this->mustExec("composer config --unset repositories.packagist.org", $sut); $stdout = $this->mustExec("composer require drupal/core-composer-scaffold:8.8.0 --no-plugins 2>&1", $sut); $stdout = $this->mustExec("composer require --no-ansi drupal/core-composer-scaffold:8.8.0 --no-plugins 2>&1", $sut); $this->assertContains(" - Installing drupal/core-composer-scaffold (8.8.0):", $stdout); // We can't force the path repo to re-install over the stable version // without removing it, and removing it masks the bugs we are testing for. // We will therefore make a git repo so that we can tag an explicit version // to require. $testVersion = '99.99.99'; $scaffoldPluginTmpRepo = $this->createTmpRepo($this->fixtures->projectRoot(), $this->fixturesDir, $testVersion); // Disable packagist.org and upgrade back to the Scaffold plugin under test. // This puts the `"packagist.org": false` config line back in composer.json // so that Packagist will no longer be used. $this->mustExec("composer remove drupal/core-composer-scaffold --no-plugins", $sut); $this->mustExec("composer config repositories.packagist.org false", $sut); $stdout = $this->mustExec("composer require drupal/core-composer-scaffold:* 2>&1", $sut); $this->assertRegExp("#Installing drupal/core-composer-scaffold.*Symlinking from#", $stdout); $this->mustExec("composer config repositories.composer-scaffold vcs 'file:///$scaffoldPluginTmpRepo'", $sut); // Using 'mustExec' was giving a strange binary string here. $output = $this->mustExec("composer require --no-ansi drupal/core-composer-scaffold:$testVersion 2>&1", $sut); $this->assertStringContainsString("Installing drupal/core-composer-scaffold ($testVersion)", $output); // Remove a scaffold file and run the scaffold command again to prove that // scaffolding is still working. unlink("$sut/index.php"); Loading @@ -81,4 +94,29 @@ public function testScaffoldUpgrade() { $this->assertFileExists("$sut/index.php"); } /** * Copy the provided source directory and create a temporary git repository. * * @param string $source * Path to directory to copy. * @param string $destParent * Path to location to create git repository. * @param string $version * Version to tag the repository with. * @return string * Path to temporary git repository. */ protected function createTmpRepo($source, $destParent, $version) { $target = $destParent . '/' . basename($source); $filesystem = new Filesystem(); $filesystem->copy($source, $target); $this->mustExec("git init", $target); $this->mustExec('git config user.email "scaffoldtest@example.com"', $target); $this->mustExec('git config user.name "Scaffold Test"', $target); $this->mustExec("git add .", $target); $this->mustExec("git commit -m 'Initial commit'", $target); $this->mustExec("git tag $version", $target); return $target; } }