You are here

private function ConstraintTest::createTestsForVersions in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Version/ConstraintTest.php \Drupal\Tests\Component\Version\ConstraintTest::createTestsForVersions()

Create testIsCompatible() test cases for constraints and versions.

Parameters

string $constraint_string: The constraint string to be used in \Drupal\Component\Version\Constraint for example ">8.x-2.4".

string[] $versions: Version strings be passed to \Drupal\Component\Version\Constraint::isCompatible(), for example "8.x-2.4". One test case will be returned for every version.

bool $expected_result: The expect result for all versions.

string $core_compatibility: (optional) The core compatibility to be used in \Drupal\Component\Version\Constraint, for example "7.x". Defaults to "8.x".

Return value

array[] The test cases to be used with ::testIsCompatible().

1 call to ConstraintTest::createTestsForVersions()
ConstraintTest::providerIsCompatible in core/tests/Drupal/Tests/Component/Version/ConstraintTest.php
Provider for testIsCompatible.

File

core/tests/Drupal/Tests/Component/Version/ConstraintTest.php, line 172

Class

ConstraintTest
@coversDefaultClass \Drupal\Component\Version\Constraint @group Version

Namespace

Drupal\Tests\Component\Version

Code

private function createTestsForVersions($constraint_string, array $versions, $expected_result, $core_compatibility = '8.x') {
  $constraint = new Constraint($constraint_string, $core_compatibility);
  $tests = [];
  foreach ($versions as $version) {
    $tests["{$core_compatibility}::({$constraint_string})::{$version}"] = [
      $constraint,
      $version,
      $expected_result,
    ];
  }
  return $tests;
}