function ComposerIntegrationTest::testComposerTilde

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/ComposerIntegrationTest.php \Drupal\Tests\ComposerIntegrationTest::testComposerTilde()
  2. 10 core/tests/Drupal/Tests/ComposerIntegrationTest.php \Drupal\Tests\ComposerIntegrationTest::testComposerTilde()
  3. 11.x 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) {
    if (preg_match('#composer/Metapackage/CoreRecommended/composer.json$#', $path)) {
        $this->markTestSkipped("{$path} has tilde");
    }
    $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.");
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.