diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index f654f2ec3e..c0270ada4a 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -96,7 +96,7 @@ class Drupal { * that Drupal no longer supports that PHP version. * - An error is shown in the status report that the PHP version is too old. */ - const MINIMUM_SUPPORTED_PHP = '8.0.2'; + const MINIMUM_SUPPORTED_PHP = '8.1.0'; /** * Minimum allowed version of PHP for Drupal to be bootstrapped. diff --git a/core/tests/Drupal/Tests/Core/DrupalTest.php b/core/tests/Drupal/Tests/Core/DrupalTest.php index e48e5c7781..ce8013741a 100644 --- a/core/tests/Drupal/Tests/Core/DrupalTest.php +++ b/core/tests/Drupal/Tests/Core/DrupalTest.php @@ -433,6 +433,30 @@ public function testAccessManager() { $this->assertNotNull(\Drupal::accessManager()); } + /** + * Tests the PHP constants have consistent values. + */ + public function testPhpConstants() { + // RECOMMENDED_PHP and MINIMUM_SUPPORTED_PHP can be just MAJOR.MINOR so + // normalize them so that version_compare() can be used. + $normalizer = function (string $version): string { + 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'); + }; + + $minimum_supported_php = $normalizer(\Drupal::MINIMUM_SUPPORTED_PHP); + $recommended_php = $normalizer(\Drupal::RECOMMENDED_PHP); + $this->assertTrue((bool) version_compare($minimum_supported_php, \Drupal::MINIMUM_PHP, '>='), "\Drupal::MINIMUM_SUPPORTED_PHP should be greater or equal to \Drupal::MINIMUM_PHP"); + $this->assertTrue((bool) version_compare($recommended_php, \Drupal::MINIMUM_SUPPORTED_PHP, '>='), "\Drupal::RECOMMENDED_PHP should be greater or equal to \Drupal::MINIMUM_SUPPORTED_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')); + } + /** * Sets up a mock expectation for the container get() method. *