Skip to content

Commit 05a3e7e

Browse files
authored
Merge pull request #6458 from magento-lynx/MC-39542
[lynx] MC-39044: Test for Compatibility with the New PHP Versions [2.4]
2 parents 38d712e + d2e7d5d commit 05a3e7e

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,14 @@ private function getFullWhitelist()
209209
}
210210

211211
/**
212-
* Retrieves the lowest PHP version specified in <kbd>composer.json</var> of project.
212+
* Retrieves the lowest and highest PHP version specified in <kbd>composer.json</var> of project.
213213
*
214-
* @return string
214+
* @return array
215215
*/
216-
private function getLowestPhpVersion(): string
216+
private function getTargetPhpVersions(): array
217217
{
218218
$composerJson = json_decode(file_get_contents(BP . '/composer.json'), true);
219-
$phpVersion = '7.0';
219+
$versionsRange = [];
220220

221221
if (isset($composerJson['require']['php'])) {
222222
$versions = explode('||', $composerJson['require']['php']);
@@ -232,12 +232,17 @@ private function getLowestPhpVersion(): string
232232
//sort versions
233233
usort($versions, 'version_compare');
234234

235-
$lowestVersion = array_shift($versions);
236-
$versionParts = explode('.', $lowestVersion);
237-
$phpVersion = sprintf('%s.%s', $versionParts[0], $versionParts[1] ?? '0');
235+
$versionsRange[] = array_shift($versions);
236+
if (!empty($versions)) {
237+
$versionsRange[] = array_pop($versions);
238+
}
239+
foreach ($versionsRange as $key => $version) {
240+
$versionParts = explode('.', $versionsRange[$key]);
241+
$versionsRange[$key] = sprintf('%s.%s', $versionParts[0], $versionParts[1] ?? '0');
242+
}
238243
}
239244

240-
return $phpVersion;
245+
return $versionsRange;
241246
}
242247

243248
/**
@@ -408,7 +413,8 @@ public function testStrictTypes()
408413
*/
409414
public function testPhpCompatibility()
410415
{
411-
$targetVersion = $this->getLowestPhpVersion();
416+
$targetVersions = $this->getTargetPhpVersions();
417+
$this->assertNotEmpty($targetVersions, 'No supported versions information in composer.json');
412418
$reportFile = self::$reportDir . '/phpcompatibility_report.txt';
413419
$rulesetDir = __DIR__ . '/_files/PHPCompatibilityMagento';
414420

@@ -417,7 +423,11 @@ public function testPhpCompatibility()
417423
}
418424

419425
$codeSniffer = new PhpCompatibility($rulesetDir, $reportFile, new Wrapper());
420-
$codeSniffer->setTestVersion($targetVersion);
426+
if (count($targetVersions) > 1) {
427+
$codeSniffer->setTestVersion($targetVersions[0] . '-' . $targetVersions[1]);
428+
} else {
429+
$codeSniffer->setTestVersion($targetVersions[0]);
430+
}
421431

422432
$result = $codeSniffer->run(
423433
$this->isFullScan() ? $this->getFullWhitelist() : self::getWhitelist(['php', 'phtml'])

0 commit comments

Comments
 (0)