You are here

public function ComposerIntegrationTest::testComposerLockHash in Drupal 8

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

Tests composer.lock content-hash.

File

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

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);
}