Merge #15754 - Fix #15745 - Version 5.0.1 suggests 4.9.4 as latest stable version

Pull-request: #15754
Fixes: #15745
Closes: #15952
Closes: #15860

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2020-02-14 20:08:10 +01:00
commit 61b8e27f55
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
2 changed files with 288 additions and 9 deletions

View File

@ -141,6 +141,8 @@ class VersionInformation
*/
public function getLatestCompatibleVersion(array $releases)
{
// Maintains the latest compatible version
$latestRelease = null;
foreach ($releases as $release) {
$phpVersions = $release->php_versions;
$phpConditions = explode(",", $phpVersions);
@ -150,7 +152,7 @@ class VersionInformation
}
}
// We evalute MySQL version constraint if there are only
// We evaluate MySQL version constraint if there are only
// one server configured.
if (count($GLOBALS['cfg']['Servers']) === 1) {
$mysqlVersions = $release->mysql_versions;
@ -161,15 +163,17 @@ class VersionInformation
}
}
}
return [
'version' => $release->version,
'date' => $release->date,
];
// To compare the current release with the previous latest release or no release is set
if ($latestRelease === null || version_compare($latestRelease['version'], $release->version, '<')) {
$latestRelease = [
'version' => $release->version,
'date' => $release->date
];
}
}
// no compatible version
return null;
return $latestRelease;
}
/**

View File

@ -221,7 +221,7 @@ class VersionInformationTest extends PmaTestCase
*
* @return void
*/
public function testGetLaestCompatibleVersionWithMultipleServers()
public function testGetLatestCompatibleVersionWithMultipleServers()
{
$GLOBALS['cfg']['Servers'] = [
[],
@ -252,7 +252,7 @@ class VersionInformationTest extends PmaTestCase
*
* @return void
*/
public function testGetLaestCompatibleVersionWithOldPHPVersion()
public function testGetLatestCompatibleVersionWithOldPHPVersion()
{
$GLOBALS['cfg']['Servers'] = [
[],
@ -288,6 +288,281 @@ class VersionInformationTest extends PmaTestCase
$this->assertEquals('4.0.10.10', $compatible['version']);
}
/**
* Tests getLatestCompatibleVersion() with an new PHP version
*
* @dataProvider dataProviderVersionConditions
* @param array[] $versions The versions to use
* @param array[] $conditions The conditions that will be executed
* @param string|null $matchedLastVersion The version that will be matched
* @return void
*/
public function testGetLatestCompatibleVersionWithNewPHPVersion(array $versions, array $conditions, ?string $matchedLastVersion): void
{
$GLOBALS['cfg']['Servers'] = [];
$mockVersionInfo = $this->getMockBuilder(VersionInformation::class)
->setMethods(['evaluateVersionCondition'])
->getMock();
$i = 0;
foreach ($conditions as $conditionArray) {
[
$condition,
$returnValue,
] = $conditionArray;
$mockVersionInfo->expects($this->at($i))
->method('evaluateVersionCondition')
->with('PHP', $condition)
->will($this->returnValue($returnValue));
$i++;
}
/** @var VersionInformation $mockVersionInfo */
$compatible = $mockVersionInfo->getLatestCompatibleVersion($versions);
$this->assertEquals($matchedLastVersion, $compatible['version'] ?? null);
}
/**
* Provider for testGetLatestCompatibleVersionWithNewPHPVersion
* Returns the conditions to be used for mocks
* @return array[]
*/
public function dataProviderVersionConditions(): array
{
return [
[
[
(object) [
'date' => '2019-12-26',
'php_versions' => '>=5.5,<8.0',
'version' => '4.9.3',
'mysql_versions' => '>=5.5',
],
(object) [
'date' => '2019-12-26',
'php_versions' => '>=7.1,<8.0',
'version' => '5.0.0',
'mysql_versions' => '>=5.5',
],
],
[
[
'>=5.5',
true,
],
[
'<8.0',
true,
],
[
'>=7.1',
true,
],
[
'<8.0',
false,
],
],
'4.9.3',
],
[
[
(object) [
'date' => '2019-12-26',
'php_versions' => '>=5.5,<7.0',
'version' => '6.0.0',
'mysql_versions' => '>=5.5',
],
(object) [
'date' => '2019-12-26',
'php_versions' => '>=7.1,<8.0',
'version' => '5.0.0',
'mysql_versions' => '>=5.5',
],
],
[
[
'>=5.5',
true,
],
[
'<7.0',
true,
],
[
'>=7.1',
false,
],
],
'6.0.0',
],
[
[
(object) [
'date' => '2019-12-26',
'php_versions' => '>=5.5,<7.0',
'version' => '6.0.0-rc1',
'mysql_versions' => '>=5.5',
],
(object) [
'date' => '2019-12-26',
'php_versions' => '>=7.1,<8.0',
'version' => '6.0.0-rc2',
'mysql_versions' => '>=5.5',
],
],
[
[
'>=5.5',
true,
],
[
'<7.0',
true,
],
[
'>=7.1',
false,
],
],
'6.0.0-rc1',
],
[
[
(object) [
'date' => '2019-12-26',
'php_versions' => '>=5.5,<7.0',
'version' => '6.0.0',
'mysql_versions' => '>=5.5',
],
(object) [
'date' => '2019-12-26',
'php_versions' => '>=7.1,<8.0',
'version' => '5.0.0',
'mysql_versions' => '>=5.5',
],
],
[
[
'>=5.5',
false,
],
[
'>=7.1',
true,
],
[
'<8.0',
false,
],
],
null,
],
[
[
(object) [
'date' => '2019-12-26',
'php_versions' => '>=5.5,<7.0',
'version' => '6.0.0',
'mysql_versions' => '>=5.5',
],
(object) [
'date' => '2019-12-26',
'php_versions' => '>=7.1,<8.0',
'version' => '5.0.0',
'mysql_versions' => '>=5.5',
],
],
[
[
'>=5.5',
false,
],
[
'>=7.1',
true,
],
[
'<8.0',
true,
],
],
'5.0.0',
],
[
[
(object) [
'date' => '2019-12-26',
'php_versions' => '>=5.5,<8.0',
'version' => '4.9.3',
'mysql_versions' => '>=5.5',
],
(object) [
'date' => '2019-12-26',
'php_versions' => '>=7.1,<8.0',
'version' => '5.0.0',
'mysql_versions' => '>=5.5',
],
],
[
[
'>=5.5',
true,
],
[
'<8.0',
true,
],
[
'>=7.1',
true,
],
[
'<8.0',
true,
],
],
'5.0.0',
],
[
[
(object) [
'date' => '2019-12-26',
'php_versions' => '>=7.1,<8.0',
'version' => '5.0.0',
'mysql_versions' => '>=5.5',
],
(object) [
'date' => '2019-12-26',
'php_versions' => '>=5.5,<8.0',
'version' => '4.9.3',
'mysql_versions' => '>=5.5',
],
],
[
[
'>=7.1',
true,
],
[
'<8.0',
true,
],
[
'>=5.5',
true,
],
[
'<8.0',
true,
],
],
'5.0.0',
],
];
}
/**
* Tests evaluateVersionCondition() method
*