function ComposerIntegrationTest::testComposerLockHash

Same name in other branches
  1. 9 core/tests/Drupal/Tests/ComposerIntegrationTest.php \Drupal\Tests\ComposerIntegrationTest::testComposerLockHash()
  2. 8.9.x core/tests/Drupal/Tests/ComposerIntegrationTest.php \Drupal\Tests\ComposerIntegrationTest::testComposerLockHash()
  3. 11.x 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/m…

File

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

Class

ComposerIntegrationTest
Tests Composer integration.

Namespace

Drupal\Tests

Code

public function testComposerLockHash() : void {
    $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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.