Commit 0423e3b4 authored by catch's avatar catch
Browse files

Issue #3134606 by greg.1.anderson, longwave, catch, Kristen Pol, jungle,...

Issue #3134606 by greg.1.anderson, longwave, catch, Kristen Pol, jungle, alexpott: [backport] PHP Fatal error in 8.9.x / 9.0.x upgrade path
parent 86f2bc2b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+29 −1
Original line number Diff line number Diff line
@@ -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>:");
@@ -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.
   *
+42 −4
Original line number Diff line number Diff line
@@ -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;

/**
@@ -24,6 +26,7 @@ class ScaffoldUpgradeTest extends TestCase {

  use AssertUtilsTrait;
  use ExecTrait;
  use PhpunitCompatibilityTrait;

  /**
   * The Fixtures object.
@@ -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");
@@ -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;
  }

}