From 21e708f2c47a5c11b38d8b9d74fa7abe48419857 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 1 Jun 2020 09:39:44 +0200 Subject: [PATCH] Remove upper bound PHP version checks from platform-check as there is not enough value added and it risks causing issues --- src/Composer/Autoload/AutoloadGenerator.php | 33 +++++++++---------- .../Test/Autoload/AutoloadGeneratorTest.php | 10 ++++-- .../autoload_real_files_by_dependency.php | 2 -- .../Fixtures/autoload_real_functions.php | 2 -- ...load_real_functions_with_include_paths.php | 2 -- ...emoved_include_paths_and_autolad_files.php | 2 -- .../Fixtures/autoload_real_include_path.php | 2 -- .../Fixtures/autoload_real_target_dir.php | 2 -- .../platform/no_extensions_required.php | 4 +-- .../Fixtures/platform/no_php_lower_bound.php | 14 -------- .../platform/specific_php_release.php | 4 +-- .../Autoload/Fixtures/platform/typical.php | 4 +-- 12 files changed, 29 insertions(+), 52 deletions(-) delete mode 100644 tests/Composer/Test/Autoload/Fixtures/platform/no_php_lower_bound.php diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 91bf5ba7e..ef3d54573 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -316,7 +316,13 @@ EOF; $filesystem->filePutContentsIfModified($targetDir.'/autoload_static.php', $this->getStaticFile($suffix, $targetDir, $vendorPath, $basePath, $staticPhpVersion)); $checkPlatform = $config->get('platform-check'); if ($checkPlatform) { - $filesystem->filePutContentsIfModified($targetDir.'/platform_check.php', $this->getPlatformCheck($packageMap)); + $platformCheckContent = $this->getPlatformCheck($packageMap); + if (null === $platformCheckContent) { + $checkPlatform = false; + } + } + if ($checkPlatform) { + $filesystem->filePutContentsIfModified($targetDir.'/platform_check.php', $platformCheckContent); } elseif (file_exists($targetDir.'/platform_check.php')) { unlink($targetDir.'/platform_check.php'); } @@ -572,7 +578,6 @@ EOF; protected function getPlatformCheck($packageMap) { $lowestPhpVersion = Bound::zero(); - $highestPhpVersion = Bound::positiveInfinity(); $requiredExtensions = array(); $extensionProviders = array(); @@ -592,9 +597,6 @@ EOF; if ($constraint->getLowerBound()->compareTo($lowestPhpVersion, '>')) { $lowestPhpVersion = $constraint->getLowerBound(); } - if ($constraint->getUpperBound()->compareTo($highestPhpVersion, '<')) { - $highestPhpVersion = $constraint->getUpperBound(); - } } if (preg_match('{^ext-(.+)$}iD', $link->getTarget(), $match)) { @@ -648,22 +650,15 @@ EOF; return implode('.', $chunks); }; - $requiredPhp = array(); - $requiredPhpError = array(); + $requiredPhp = ''; + $requiredPhpError = ''; if (!$lowestPhpVersion->isZero()) { $operator = $lowestPhpVersion->isInclusive() ? '>=' : '>'; - $requiredPhp[] = 'PHP_VERSION_ID '.$operator.' '.$formatToPhpVersionId($lowestPhpVersion); - $requiredPhpError[] = '"'.$operator.' '.$formatToHumanReadable($lowestPhpVersion).'"'; - } - if (!$highestPhpVersion->isPositiveInfinity()) { - $operator = $highestPhpVersion->isInclusive() ? '<=' : '<'; - $requiredPhp[] = 'PHP_VERSION_ID '.$operator.' '.$formatToPhpVersionId($highestPhpVersion); - $requiredPhpError[] = '"'.$operator.' '.$formatToHumanReadable($highestPhpVersion).'"'; + $requiredPhp = 'PHP_VERSION_ID '.$operator.' '.$formatToPhpVersionId($lowestPhpVersion); + $requiredPhpError = '"'.$operator.' '.$formatToHumanReadable($lowestPhpVersion).'"'; } if ($requiredPhp) { - $requiredPhp = implode(' && ', $requiredPhp); - $requiredPhpError = implode(' and ', $requiredPhpError); $requiredPhp = <<generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1'); - $this->assertFileContentEquals(__DIR__ . '/Fixtures/platform/' . $expectedFixture . '.php', $this->vendorDir . '/composer/platform_check.php'); + if (null === $expectedFixture) { + $this->assertFalse(file_exists($this->vendorDir . '/composer/platform_check.php')); + $this->assertNotContains("require __DIR__ . '/platform_check.php';", file_get_contents($this->vendorDir.'/composer/autoload_real.php')); + } else { + $this->assertFileContentEquals(__DIR__ . '/Fixtures/platform/' . $expectedFixture . '.php', $this->vendorDir . '/composer/platform_check.php'); + $this->assertContains("require __DIR__ . '/platform_check.php';", file_get_contents($this->vendorDir.'/composer/autoload_real.php')); + } } public function platformCheckProvider() @@ -1687,7 +1693,7 @@ EOF; array( new Link('a', 'php', $versionParser->parseConstraints('< 8')), ), - 'no_php_lower_bound' + null ), 'No PHP upper bound' => array( array( diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php index ab3dd2758..fdff2bd42 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php @@ -22,8 +22,6 @@ class ComposerAutoloaderInitFilesAutoloadOrder return self::$loader; } - require __DIR__ . '/platform_check.php'; - spl_autoload_register(array('ComposerAutoloaderInitFilesAutoloadOrder', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInitFilesAutoloadOrder', 'loadClassLoader')); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php index 27dc60bf6..67ce8ffe2 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php @@ -22,8 +22,6 @@ class ComposerAutoloaderInitFilesAutoload return self::$loader; } - require __DIR__ . '/platform_check.php'; - spl_autoload_register(array('ComposerAutoloaderInitFilesAutoload', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInitFilesAutoload', 'loadClassLoader')); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php index be7dd7907..790029096 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php @@ -22,8 +22,6 @@ class ComposerAutoloaderInitFilesAutoload return self::$loader; } - require __DIR__ . '/platform_check.php'; - spl_autoload_register(array('ComposerAutoloaderInitFilesAutoload', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInitFilesAutoload', 'loadClassLoader')); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php index c3617696b..7b7898df1 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php @@ -22,8 +22,6 @@ class ComposerAutoloaderInitFilesAutoload return self::$loader; } - require __DIR__ . '/platform_check.php'; - spl_autoload_register(array('ComposerAutoloaderInitFilesAutoload', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInitFilesAutoload', 'loadClassLoader')); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_include_path.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_include_path.php index 7639b4336..2747dbc0a 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_include_path.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_include_path.php @@ -22,8 +22,6 @@ class ComposerAutoloaderInitIncludePath return self::$loader; } - require __DIR__ . '/platform_check.php'; - spl_autoload_register(array('ComposerAutoloaderInitIncludePath', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInitIncludePath', 'loadClassLoader')); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php index 0d9685d71..8ec8cdd47 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php @@ -22,8 +22,6 @@ class ComposerAutoloaderInitTargetDir return self::$loader; } - require __DIR__ . '/platform_check.php'; - spl_autoload_register(array('ComposerAutoloaderInitTargetDir', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInitTargetDir', 'loadClassLoader')); diff --git a/tests/Composer/Test/Autoload/Fixtures/platform/no_extensions_required.php b/tests/Composer/Test/Autoload/Fixtures/platform/no_extensions_required.php index 1dbfcd455..85a922d49 100644 --- a/tests/Composer/Test/Autoload/Fixtures/platform/no_extensions_required.php +++ b/tests/Composer/Test/Autoload/Fixtures/platform/no_extensions_required.php @@ -4,8 +4,8 @@ $issues = array(); -if (!(PHP_VERSION_ID >= 70200 && PHP_VERSION_ID < 80000)) { - $issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.0" and "< 8.0.0". You are running ' . PHP_VERSION . '.'; +if (!(PHP_VERSION_ID >= 70200)) { + $issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.0". You are running ' . PHP_VERSION . '.'; } if ($issues) { diff --git a/tests/Composer/Test/Autoload/Fixtures/platform/no_php_lower_bound.php b/tests/Composer/Test/Autoload/Fixtures/platform/no_php_lower_bound.php deleted file mode 100644 index 373d93ff5..000000000 --- a/tests/Composer/Test/Autoload/Fixtures/platform/no_php_lower_bound.php +++ /dev/null @@ -1,14 +0,0 @@ -= 70208 && PHP_VERSION_ID < 80000)) { - $issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.8" and "< 8.0.0". You are running ' . PHP_VERSION . '.'; +if (!(PHP_VERSION_ID >= 70208)) { + $issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.8". You are running ' . PHP_VERSION . '.'; } if ($issues) { diff --git a/tests/Composer/Test/Autoload/Fixtures/platform/typical.php b/tests/Composer/Test/Autoload/Fixtures/platform/typical.php index 728e68b63..dde12ec46 100644 --- a/tests/Composer/Test/Autoload/Fixtures/platform/typical.php +++ b/tests/Composer/Test/Autoload/Fixtures/platform/typical.php @@ -4,8 +4,8 @@ $issues = array(); -if (!(PHP_VERSION_ID >= 70200 && PHP_VERSION_ID < 80000)) { - $issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.0" and "< 8.0.0". You are running ' . PHP_VERSION . '.'; +if (!(PHP_VERSION_ID >= 70200)) { + $issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.0". You are running ' . PHP_VERSION . '.'; } $missingExtensions = array();