You are here

public function MetapackageUpdateTest::testUpdated in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Composer/Generator/MetapackageUpdateTest.php \Drupal\Tests\Composer\Generator\MetapackageUpdateTest::testUpdated()
  2. 10 core/tests/Drupal/Tests/Composer/Generator/MetapackageUpdateTest.php \Drupal\Tests\Composer\Generator\MetapackageUpdateTest::testUpdated()

Test to see if the generated metapackages are in sync with composer.lock.

Note that this is not a test of code correctness, but rather it merely confirms if the package builder was used on the most recent set of metapackages.

See BuilderTest.php for a test that checks for code correctness.

Parameters

string $builderClass: The metapackage builder to test.

string $path: The relative path to the metapackage

@dataProvider updatedTestData

File

core/tests/Drupal/Tests/Composer/Generator/MetapackageUpdateTest.php, line 56

Class

MetapackageUpdateTest
Test to see if the metapackages are up-to-date with the root composer.lock.

Namespace

Drupal\Tests\Composer\Generator

Code

public function testUpdated($builderClass, $path) {

  // Create a DrupalCoreComposer for the System Under Test (current repo)
  $repositoryRoot = dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))));
  $drupalCoreInfo = DrupalCoreComposer::createFromPath($repositoryRoot);

  // Rebuild the metapackage for the composer.json / composer.lock of
  // the current repo.
  $builder = new $builderClass($drupalCoreInfo);
  $generatedJson = $builder
    ->getPackage();
  $generatedJson = PackageGenerator::encode($generatedJson);

  // Also load the most-recently-generated version of the metapackage.
  $loadedJson = file_get_contents("{$repositoryRoot}/{$path}/composer.json");

  // The generated json is the "expected", what we think the loaded
  // json would contain, if the current patch is generated correctly
  // (metapackages updated when composer.lock is updated).
  $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);
}