diff --git a/core/tests/Drupal/Tests/ComposerIntegrationTest.php b/core/tests/Drupal/Tests/ComposerIntegrationTest.php index 80a18b6513..c01ca25070 100644 --- a/core/tests/Drupal/Tests/ComposerIntegrationTest.php +++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php @@ -86,7 +86,7 @@ public function testComposerJson() { public function testComposerLockHash() { $json = file_get_contents($this->root . '/composer.json'); $lock = json_decode(file_get_contents($this->root . '/composer.lock'), TRUE); - $this->assertSame(md5($json), $lock['hash']); + $this->assertSame(self::getContentHash($json), $lock['content-hash']); } /** @@ -126,4 +126,44 @@ public function testAllModulesReplaced() { } } + /** + * Returns the md5 hash of the sorted content of the composer file. + * + * Note that this is a near copy-paste of + * \Composer\Package\Locker::getContentHash() from the Composer package. + * + * @param string $composerFileContents + * The contents of the composer file. + * + * @return string + * Hash of the contents of the composer file. + * + * @see https://github.com/composer/composer/blob/1.3/src/Composer/Package/Locker.php + */ + private static function getContentHash($composerFileContents) { + $content = json_decode($composerFileContents, true); + $relevantKeys = array( + 'name', + 'version', + 'require', + 'require-dev', + 'conflict', + 'replace', + 'provide', + 'minimum-stability', + 'prefer-stable', + 'repositories', + 'extra', + ); + $relevantContent = array(); + foreach (array_intersect($relevantKeys, array_keys($content)) as $key) { + $relevantContent[$key] = $content[$key]; + } + if (isset($content['config']['platform'])) { + $relevantContent['config']['platform'] = $content['config']['platform']; + } + ksort($relevantContent); + return md5(json_encode($relevantContent)); + } + }