Issue #2843259 by alexpott, Mile23: Drupal\Tests\ComposerIntegrationTest breaks when composer.lock generated with composer version 1.3 and higher
parent
bf05c52097
commit
03cd7e5ee5
|
@ -74,19 +74,18 @@ class ComposerIntegrationTest extends UnitTestCase {
|
||||||
public function testComposerJson() {
|
public function testComposerJson() {
|
||||||
foreach ($this->getPaths() as $path) {
|
foreach ($this->getPaths() as $path) {
|
||||||
$json = file_get_contents($path . '/composer.json');
|
$json = file_get_contents($path . '/composer.json');
|
||||||
|
|
||||||
$result = json_decode($json);
|
$result = json_decode($json);
|
||||||
$this->assertNotNull($result, $this->getErrorMessages()[json_last_error()]);
|
$this->assertNotNull($result, $this->getErrorMessages()[json_last_error()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests composer.lock hash.
|
* Tests composer.lock content-hash.
|
||||||
*/
|
*/
|
||||||
public function testComposerLockHash() {
|
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);
|
$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 @@ class ComposerIntegrationTest extends UnitTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue