From 35986f56b7d03db895e239d03b18f0570ef97630 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Thu, 1 Feb 2018 11:37:06 +0000 Subject: [PATCH] Issue #2843328 by mpdonadio, alexpott, Mile23, cburschka, xjm: Enforce minimum PHP version in composer dependencies --- core/includes/bootstrap.inc | 9 +++++ .../Drupal/Tests/ComposerIntegrationTest.php | 39 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index a67d7ff654e..d906da442e3 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -21,6 +21,9 @@ use Drupal\Core\StringTranslation\TranslatableMarkup; * Minimum supported version of PHP. * * Drupal cannot be installed on versions of PHP older than this version. + * + * @todo Move this to an appropriate autoloadable class. See + * https://www.drupal.org/project/drupal/issues/2908079 */ const DRUPAL_MINIMUM_PHP = '5.5.9'; @@ -30,6 +33,9 @@ const DRUPAL_MINIMUM_PHP = '5.5.9'; * Sites installing Drupal on PHP versions lower than this will see a warning * message, but Drupal can still be installed. Used for (e.g.) PHP versions * that have reached their EOL or will in the near future. + * + * @todo Move this to an appropriate autoloadable class. See + * https://www.drupal.org/project/drupal/issues/2908079 */ const DRUPAL_RECOMMENDED_PHP = '7.1'; @@ -39,6 +45,9 @@ const DRUPAL_RECOMMENDED_PHP = '7.1'; * 64M was chosen as a minimum requirement in order to allow for additional * contributed modules to be installed prior to hitting the limit. However, * 40M is the target for the Standard installation profile. + * + * @todo Move this to an appropriate autoloadable class. See + * https://www.drupal.org/project/drupal/issues/2908079 */ const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = '64M'; diff --git a/core/tests/Drupal/Tests/ComposerIntegrationTest.php b/core/tests/Drupal/Tests/ComposerIntegrationTest.php index b56849d8631..8ee025a809c 100644 --- a/core/tests/Drupal/Tests/ComposerIntegrationTest.php +++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests; +use Composer\Semver\Semver; + /** * Tests Composer integration. * @@ -9,6 +11,15 @@ namespace Drupal\Tests; */ class ComposerIntegrationTest extends UnitTestCase { + /** + * The minimum PHP version supported by Drupal. + * + * @see https://www.drupal.org/docs/8/system-requirements/web-server + * + * @todo Remove as part of https://www.drupal.org/node/2908079 + */ + const MIN_PHP_VERSION = '5.5.9'; + /** * Gets human-readable JSON error messages. * @@ -171,6 +182,34 @@ class ComposerIntegrationTest extends UnitTestCase { } } + /** + * Tests package requirements for the minimum supported PHP version by Drupal. + * + * @todo This can be removed when DrupalCI supports dependency regression + * testing in https://www.drupal.org/node/2874198 + */ + public function testMinPHPVersion() { + // Check for lockfile in the application root. If the lockfile does not + // exist, then skip this test. + $lockfile = $this->root . '/composer.lock'; + if (!file_exists($lockfile)) { + $this->markTestSkipped('/composer.lock is not available.'); + } + + $lock = json_decode(file_get_contents($lockfile), TRUE); + + // Check the PHP version for each installed non-development package. The + // testing infrastructure uses the uses the development packages, and may + // update them for particular environment configurations. In particular, + // PHP 7.2+ require an updated version of phpunit, which is incompatible + // with Drupal's minimum PHP requirement. + foreach ($lock['packages'] as $package) { + if (isset($package['require']['php'])) { + $this->assertTrue(Semver::satisfies(static::MIN_PHP_VERSION, $package['require']['php']), $package['name'] . ' has a PHP dependency requirement of "' . $package['require']['php'] . '"'); + } + } + } + // @codingStandardsIgnoreStart /** * The following method is copied from \Composer\Package\Locker.