View source
<?php
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 PHPUnit\Framework\TestCase;
class ScaffoldUpgradeTest extends TestCase {
use AssertUtilsTrait;
use ExecTrait;
protected $fixtures;
protected function setUp() : void {
$this->fixtures = new Fixtures();
$this->fixtures
->createIsolatedComposerCacheDir();
}
public function testScaffoldUpgrade() {
$composerVersionLine = exec('composer --version');
if (strpos($composerVersionLine, 'Composer version 2') !== FALSE) {
$this
->markTestSkipped('We cannot run the scaffold upgrade test with Composer 2 until we have a stable version of drupal/core-composer-scaffold to start from that we can install with Composer 2.x.');
}
$this->fixturesDir = $this->fixtures
->tmpDir($this
->getName());
$replacements = [
'SYMLINK' => 'false',
'PROJECT_ROOT' => $this->fixtures
->projectRoot(),
];
$this->fixtures
->cloneFixtureProjects($this->fixturesDir, $replacements);
$topLevelProjectDir = 'drupal-drupal';
$sut = $this->fixturesDir . '/' . $topLevelProjectDir;
$this
->mustExec("composer install --no-ansi", $sut);
$this
->assertScaffoldedFile($sut . '/sites/default/default.settings.php', FALSE, 'A settings.php fixture file scaffolded from the scaffold-override-fixture');
$this
->mustExec("composer config --unset repositories.packagist.org", $sut);
$stdout = $this
->mustExec("composer require --no-ansi drupal/core-composer-scaffold:8.8.0 --no-plugins 2>&1", $sut);
$this
->assertStringContainsString(" - Installing drupal/core-composer-scaffold (8.8.0):", $stdout);
$testVersion = '99.99.99';
$scaffoldPluginTmpRepo = $this
->createTmpRepo($this->fixtures
->projectRoot(), $this->fixturesDir, $testVersion);
$this
->mustExec("composer config repositories.packagist.org false", $sut);
$this
->mustExec("composer config repositories.composer-scaffold vcs 'file:///{$scaffoldPluginTmpRepo}'", $sut);
$output = $this
->mustExec("composer require --no-ansi drupal/core-composer-scaffold:{$testVersion} 2>&1", $sut);
$this
->assertStringContainsString("Installing drupal/core-composer-scaffold ({$testVersion})", $output);
unlink("{$sut}/index.php");
$stdout = $this
->mustExec("composer scaffold", $sut);
$this
->assertStringContainsString("Scaffolding files for", $stdout);
$this
->assertFileExists("{$sut}/index.php");
}
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;
}
}