Commit 03cd7e5e authored by catch's avatar catch

Issue #2843259 by alexpott, Mile23: Drupal\Tests\ComposerIntegrationTest...

Issue #2843259 by alexpott, Mile23: Drupal\Tests\ComposerIntegrationTest breaks when composer.lock generated with composer version 1.3 and higher
parent bf05c520
......@@ -74,19 +74,18 @@ protected function getPaths() {
public function testComposerJson() {
foreach ($this->getPaths() as $path) {
$json = file_get_contents($path . '/composer.json');
$result = json_decode($json);
$this->assertNotNull($result, $this->getErrorMessages()[json_last_error()]);
}
}
/**
* Tests composer.lock hash.
* Tests composer.lock content-hash.
*/
public function testComposerLockHash() {
$json = file_get_contents($this->root . '/composer.json');
$content_hash = self::getContentHash(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($content_hash, $lock['content-hash']);
}
/**
......@@ -126,4 +125,50 @@ public function testAllModulesReplaced() {
}
}
// @codingStandardsIgnoreStart
/**
* The following method is copied from \Composer\Package\Locker.
*
* @see https://github.com/composer/composer
*/
/**
* Returns the md5 hash of the sorted content of the composer file.
*
* @param string $composerFileContents The contents of the composer file.
*
* @return string
*/
protected 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));
}
// @codingStandardsIgnoreEnd
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment