You are here

public function ComposerIntegrationTest::testComposerTilde in Drupal 9

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

Tests composer.json versions.

@dataProvider providerTestComposerJson

Parameters

string $path: Path to a composer.json to test.

File

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

Class

ComposerIntegrationTest
Tests Composer integration.

Namespace

Drupal\Tests

Code

public function testComposerTilde($path) {
  $content = json_decode(file_get_contents($path), TRUE);
  $composer_keys = array_intersect([
    'require',
    'require-dev',
  ], array_keys($content));
  if (empty($composer_keys)) {
    $this
      ->markTestSkipped("{$path} has no keys to test");
  }
  foreach ($composer_keys as $composer_key) {
    foreach ($content[$composer_key] as $dependency => $version) {

      // We allow tildes if the dependency is a Symfony component.
      // @see https://www.drupal.org/node/2887000
      if (strpos($dependency, 'symfony/') === 0) {
        continue;
      }
      $this
        ->assertStringNotContainsString('~', $version, "Dependency {$dependency} in {$path} contains a tilde, use a caret.");
    }
  }
}