From c2495d1b0df5b1b587a415eac6d9077f317253c6 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Fri, 4 Mar 2022 10:25:48 +0000
Subject: [PATCH] Issue #3266525 by alexpott, quietone, xjm, daffie, longwave:
 MINIMUM_SUPPORTED_PHP is less than MINIMUM_PHP

---
 core/lib/Drupal.php                         |  2 +-
 core/tests/Drupal/Tests/Core/DrupalTest.php | 25 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php
index f654f2ec3edc..c0270ada4a7f 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 e48e5c778188..ae549b3b4cd2 100644
--- a/core/tests/Drupal/Tests/Core/DrupalTest.php
+++ b/core/tests/Drupal/Tests/Core/DrupalTest.php
@@ -433,6 +433,31 @@ 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 {
+      // 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');
+    };
+
+    $minimum_supported_php = $normalizer(\Drupal::MINIMUM_SUPPORTED_PHP);
+    $recommended_php = $normalizer(\Drupal::RECOMMENDED_PHP);
+    $this->assertTrue(version_compare($minimum_supported_php, \Drupal::MINIMUM_PHP, '>='), "\Drupal::MINIMUM_SUPPORTED_PHP should be greater or equal to \Drupal::MINIMUM_PHP");
+    $this->assertTrue(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.
    *
-- 
GitLab