MetapackageUpdateTest.php in Drupal 9
File
core/tests/Drupal/Tests/Composer/Generator/MetapackageUpdateTest.php
View source
<?php
namespace Drupal\Tests\Composer\Generator;
use Drupal\Composer\Generator\Builder\DrupalCoreRecommendedBuilder;
use Drupal\Composer\Generator\Builder\DrupalDevDependenciesBuilder;
use Drupal\Composer\Generator\Builder\DrupalPinnedDevDependenciesBuilder;
use Drupal\Composer\Generator\PackageGenerator;
use Drupal\Composer\Generator\Util\DrupalCoreComposer;
use PHPUnit\Framework\TestCase;
class MetapackageUpdateTest extends TestCase {
public function updatedTestData() {
return [
[
DrupalCoreRecommendedBuilder::class,
'composer/Metapackage/CoreRecommended',
],
[
DrupalDevDependenciesBuilder::class,
'composer/Metapackage/DevDependencies',
],
[
DrupalPinnedDevDependenciesBuilder::class,
'composer/Metapackage/PinnedDevDependencies',
],
];
}
public function testUpdated($builderClass, $path) {
$repositoryRoot = dirname(__DIR__, 6);
$drupalCoreInfo = DrupalCoreComposer::createFromPath($repositoryRoot);
$builder = new $builderClass($drupalCoreInfo);
$generatedJson = $builder
->getPackage();
$generatedJson = PackageGenerator::encode($generatedJson);
$loadedJson = file_get_contents("{$repositoryRoot}/{$path}/composer.json");
$version = str_replace('.0-dev', '.x-dev', \Drupal::VERSION);
$message = <<<__EOT__
The rebuilt version of {<span class="php-variable">$path</span>} does not match what is in the source tree.
To fix, run:
COMPOSER_ROOT_VERSION={<span class="php-variable">$version</span>} composer update --lock
__EOT__;
$this
->assertEquals($generatedJson, $loadedJson, $message);
}
}