You are here

public function ComposerIntegrationTest::testComposerLockHash in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/ComposerIntegrationTest.php \Drupal\Tests\ComposerIntegrationTest::testComposerLockHash()

Tests composer.lock content-hash.

If you have made a change to composer.json, you may need to reconstruct composer.lock. Follow the link below for further instructions.

See also

https://www.drupal.org/about/core/policies/core-dependencies-policies/ma...

File

core/tests/Drupal/Tests/ComposerIntegrationTest.php, line 28

Class

ComposerIntegrationTest
Tests Composer integration.

Namespace

Drupal\Tests

Code

public function testComposerLockHash() {
  $content_hash = self::getContentHash(file_get_contents($this->root . '/composer.json'));
  $lock = json_decode(file_get_contents($this->root . '/composer.lock'), TRUE);
  $this
    ->assertSame($content_hash, $lock['content-hash']);

  // @see \Composer\Repository\PathRepository::initialize()
  $core_lock_file_hash = '';
  $options = [];
  foreach ($lock['packages'] as $package) {
    if ($package['name'] === 'drupal/core') {
      $core_lock_file_hash = $package['dist']['reference'];
      $options = $package['transport-options'] ?? [];
      break;
    }
  }
  $core_content_hash = sha1(file_get_contents($this->root . '/core/composer.json') . serialize($options));
  $this
    ->assertSame($core_content_hash, $core_lock_file_hash);
}