function DrupalTest::testPhpConstants
Same name in other branches
- 11.x core/tests/Drupal/Tests/Core/DrupalTest.php \Drupal\Tests\Core\DrupalTest::testPhpConstants()
Tests the PHP constants have consistent values.
File
-
core/
tests/ Drupal/ Tests/ Core/ DrupalTest.php, line 441
Class
- DrupalTest
- Tests the Drupal class.
Namespace
Drupal\Tests\CoreCode
public function testPhpConstants() : void {
// RECOMMENDED_PHP can be just MAJOR.MINOR so normalize it to allow using
// version_compare().
$normalizer = function (string $version) : string {
// The regex below is from \Composer\Semver\VersionParser::normalize().
preg_match('{^(\\d{1,5})(\\.\\d++)?(\\.\\d++)?$}i', $version, $matches);
return $matches[1] . (!empty($matches[2]) ? $matches[2] : '.9999999') . (!empty($matches[3]) ? $matches[3] : '.9999999');
};
$recommended_php = $normalizer(\Drupal::RECOMMENDED_PHP);
$this->assertTrue(version_compare($recommended_php, \Drupal::MINIMUM_PHP, '>='), "\\Drupal::RECOMMENDED_PHP should be greater or equal to \\Drupal::MINIMUM_PHP");
// As this test depends on the $normalizer function it is tested.
$this->assertSame('10.9999999.9999999', $normalizer('10'));
$this->assertSame('10.1.9999999', $normalizer('10.1'));
$this->assertSame('10.1.2', $normalizer('10.1.2'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.