You are here

protected static function ComposerIntegrationTest::getContentHash in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/ComposerIntegrationTest.php \Drupal\Tests\ComposerIntegrationTest::getContentHash()

Returns the md5 hash of the sorted content of the composer file.

Parameters

string $composerFileContents The contents of the composer file.:

Return value

string

1 call to ComposerIntegrationTest::getContentHash()
ComposerIntegrationTest::testComposerLockHash in core/tests/Drupal/Tests/ComposerIntegrationTest.php
Tests composer.lock content-hash.

File

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

Class

ComposerIntegrationTest
Tests Composer integration.

Namespace

Drupal\Tests

Code

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