View source
<?php
namespace Drupal\Tests\Core\Utility;
use Drupal\Core\Utility\PhpRequirements;
use Drupal\Tests\UnitTestCase;
class PhpRequirementsTest extends UnitTestCase {
public function testPhpEolDates() : void {
$reflected = new \ReflectionClass(PhpRequirements::class);
$php_eol_dates = $reflected
->getStaticPropertyValue('phpEolDates');
foreach ($php_eol_dates as $version => $eol_date) {
$this
->assertMatchesRegularExpression('/^([0-9]+)(\\.([0-9]+)(\\.([0-9]+)(-[A-Za-z0-9]+)?)?)?$/', $version);
$this
->assertMatchesRegularExpression('/^([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])$/', $eol_date);
}
uksort($php_eol_dates, function ($a, $b) use ($php_eol_dates) {
$a_date = strtotime($php_eol_dates[$a]);
$b_date = strtotime($php_eol_dates[$b]);
if ($a_date === $b_date) {
return $a <=> $b;
}
return $a_date <=> $b_date;
});
$this
->assertSame($php_eol_dates, $reflected
->getStaticPropertyValue('phpEolDates'));
}
public function testMinimumSupportedPhp(string $date_string, string $drupal_minimum_php, array $php_eol_dates, string $expected_php_version) : void {
$reflected = new \ReflectionClass(PhpRequirements::class);
$reflected
->setStaticPropertyValue('drupalMinimumPhp', $drupal_minimum_php);
$reflected
->setStaticPropertyValue('phpEolDates', $php_eol_dates);
$date = new \DateTime($date_string);
$this
->assertSame($expected_php_version, PhpRequirements::getMinimumSupportedPhp($date));
}
public function providerMinimumSupportedPhp() : \Generator {
$eol_lists = [];
$eol_lists['d9_release'] = [
'7.2' => '2020-11-30',
'7.3' => '2021-12-06',
'7.4' => '2022-11-28',
'8.0' => '2023-11-26',
'8.1' => '2024-11-25',
];
(yield [
'2020-06-03',
'7.3.0',
$eol_lists['d9_release'],
'7.3.0',
]);
(yield [
'2020-06-03',
'7.3.12',
$eol_lists['d9_release'],
'7.3.12',
]);
(yield [
'2020-06-03',
'7.2.17',
$eol_lists['d9_release'],
'7.2.17',
]);
(yield [
'2020-06-03',
'7.1.5',
$eol_lists['d9_release'],
'7.2',
]);
(yield [
'2020-06-03',
'7.3.0',
[],
'7.3.0',
]);
(yield [
'2020-11-29',
'7.3.0',
$eol_lists['d9_release'],
'7.3.0',
]);
(yield [
'2020-11-30',
'7.3.0',
$eol_lists['d9_release'],
'7.3.0',
]);
(yield [
'2020-12-01',
'7.3.0',
$eol_lists['d9_release'],
'7.3.0',
]);
(yield [
'2021-12-05',
'7.3.0',
$eol_lists['d9_release'],
'7.3.0',
]);
(yield [
'2021-12-06',
'7.3.0',
$eol_lists['d9_release'],
'7.4',
]);
(yield [
'2021-12-07',
'7.3.0',
$eol_lists['d9_release'],
'7.4',
]);
(yield [
'2022-11-27',
'7.3.0',
$eol_lists['d9_release'],
'7.4',
]);
(yield [
'2022-11-28',
'7.3.0',
$eol_lists['d9_release'],
'8.0',
]);
(yield [
'2022-11-29',
'7.3.0',
$eol_lists['d9_release'],
'8.0',
]);
(yield [
'2023-11-25',
'7.3.0',
$eol_lists['d9_release'],
'8.0',
]);
(yield [
'2023-11-26',
'7.3.0',
$eol_lists['d9_release'],
'8.1',
]);
(yield [
'2023-11-27',
'7.3.0',
$eol_lists['d9_release'],
'8.1',
]);
(yield [
'2024-11-24',
'7.3.0',
$eol_lists['d9_release'],
'8.1',
]);
(yield [
'2024-11-25',
'7.3.0',
$eol_lists['d9_release'],
'8.1',
]);
(yield [
'2024-11-26',
'7.3.0',
$eol_lists['d9_release'],
'8.1',
]);
(yield [
'2021-12-05',
'8.0.2',
$eol_lists['d9_release'],
'8.0.2',
]);
(yield [
'2021-12-06',
'8.0.2',
$eol_lists['d9_release'],
'8.0.2',
]);
(yield [
'2021-12-07',
'8.0.2',
$eol_lists['d9_release'],
'8.0.2',
]);
(yield [
'2022-11-27',
'8.0.2',
$eol_lists['d9_release'],
'8.0.2',
]);
(yield [
'2022-11-28',
'8.0.2',
$eol_lists['d9_release'],
'8.0.2',
]);
(yield [
'2022-11-29',
'8.0.2',
$eol_lists['d9_release'],
'8.0.2',
]);
(yield [
'2023-11-25',
'8.0.2',
$eol_lists['d9_release'],
'8.0.2',
]);
(yield [
'2023-11-26',
'8.0.2',
$eol_lists['d9_release'],
'8.1',
]);
(yield [
'2023-11-27',
'8.0.2',
$eol_lists['d9_release'],
'8.1',
]);
(yield [
'2024-11-24',
'8.0.2',
$eol_lists['d9_release'],
'8.1',
]);
(yield [
'2024-11-25',
'8.0.2',
$eol_lists['d9_release'],
'8.1',
]);
(yield [
'2024-11-26',
'8.0.2',
$eol_lists['d9_release'],
'8.1',
]);
(yield [
'2027-01-01',
'8.0.2',
$eol_lists['d9_release'],
'8.1',
]);
$eol_lists['php_with_lts'] = $eol_lists['d9_release'];
unset($eol_lists['php_with_lts']['7.4']);
$eol_lists['php_with_lts']['7.4'] = '2025-11-28';
(yield [
'2021-12-05',
'7.3',
$eol_lists['php_with_lts'],
'7.3',
]);
(yield [
'2021-12-06',
'7.3',
$eol_lists['php_with_lts'],
'7.4',
]);
(yield [
'2022-11-28',
'7.3',
$eol_lists['php_with_lts'],
'7.4',
]);
(yield [
'2023-11-26',
'7.3',
$eol_lists['php_with_lts'],
'7.4',
]);
(yield [
'2024-11-25',
'7.3',
$eol_lists['php_with_lts'],
'7.4',
]);
(yield [
'2025-12-01',
'7.3',
$eol_lists['php_with_lts'],
'7.4',
]);
$eol_lists['same_eol_date'] = $eol_lists['d9_release'];
$eol_lists['same_eol_date']['8.2'] = $eol_lists['same_eol_date']['8.1'];
(yield [
'2021-12-05',
'7.3',
$eol_lists['same_eol_date'],
'7.3',
]);
(yield [
'2023-11-27',
'8.0.2',
$eol_lists['same_eol_date'],
'8.1',
]);
(yield [
'2027-07-31',
'8.0.2',
$eol_lists['same_eol_date'],
'8.2',
]);
}
}