3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
8 use PhpMyAdmin\Release
;
9 use PhpMyAdmin\VersionInformation
;
10 use PHPUnit\Framework\Attributes\CoversClass
;
11 use PHPUnit\Framework\Attributes\DataProvider
;
12 use PHPUnit\Framework\Attributes\Group
;
13 use PHPUnit\Framework\Attributes\Large
;
15 #[CoversClass(VersionInformation::class)]
16 #[CoversClass(Release::class)]
18 class VersionInformationTest
extends AbstractTestCase
21 private array $releases;
24 * Sets up the fixture, for example, opens a network connection.
25 * This method is called before a test is executed.
27 protected function setUp(): void
31 $this->setProxySettings();
35 $release = new Release('4.4.14.1', '2015-09-08', '>=5.3,<7.1', '>=5.5');
36 $this->releases
[] = $release;
38 $release = new Release('4.4.13.3', '2015-09-09', '>=5.3,<7.0', '>=5.5');
39 $this->releases
[] = $release;
41 $release = new Release('4.0.10.10', '2015-05-13', '>=5.2,<5.3', '>=5.0');
42 $this->releases
[] = $release;
46 * Test version checking
49 public function testGetLatestVersion(): void
51 $this->setProxySettings();
52 Config
::getInstance()->settings
['VersionCheck'] = true;
53 unset($_SESSION['cache']['version_check']);
54 $versionInformation = new VersionInformation();
55 $version = $versionInformation->getLatestVersions();
56 self
::assertIsArray($version);
57 self
::assertNotEmpty($version);
61 * Test version to int conversion.
63 * @param string $version Version string
64 * @param int $numeric Integer matching version
66 #[DataProvider('dataVersions')]
67 public function testVersionToInt(string $version, int $numeric): void
69 $versionInformation = new VersionInformation();
72 $versionInformation->versionToInt($version),
77 * Data provider for version parsing
81 public static function dataVersions(): array
85 ['2.0.0.2-dev', 2000002],
87 ['3.4.2-dev3', 3040203],
88 ['3.4.2-dev', 3040200],
89 ['3.4.2-pl', 3040260],
90 ['3.4.2-pl3', 3040263],
91 ['4.4.2-rc22', 4040252],
92 ['4.4.2-rc', 4040230],
93 ['4.4.22-beta22', 4042242],
94 ['4.4.22-beta', 4042220],
95 ['4.4.21-alpha22', 4042132],
96 ['4.4.20-alpha', 4042010],
97 ['4.40.20-alpha-dev', 4402010],
99 ['4.4.4-test', 4040400],
101 ['4.0.1.3', 4000153],
102 ['4.1-dev', 4010000],
107 * Tests getLatestCompatibleVersion() when there is only one server configured
109 public function testGetLatestCompatibleVersionWithSingleServer(): void
111 Config
::getInstance()->settings
['Servers'] = [[]];
113 $mockVersionInfo = $this->createPartialMock(VersionInformation
::class, ['getPHPVersion', 'getMySQLVersion']);
114 $mockVersionInfo->expects(self
::exactly(6))->method('getPHPVersion')->willReturn('5.6.0');
115 $mockVersionInfo->expects(self
::exactly(2))->method('getMySQLVersion')->willReturn('5.5.0');
117 $compatible = $mockVersionInfo->getLatestCompatibleVersion($this->releases
);
118 self
::assertInstanceOf(Release
::class, $compatible);
119 self
::assertSame('4.4.14.1', $compatible->version
);
123 * Tests getLatestCompatibleVersion() when there are multiple servers configured
125 public function testGetLatestCompatibleVersionWithMultipleServers(): void
127 Config
::getInstance()->settings
['Servers'] = [[], []];
129 $mockVersionInfo = $this->createPartialMock(VersionInformation
::class, ['getPHPVersion', 'getMySQLVersion']);
130 $mockVersionInfo->expects(self
::exactly(6))->method('getPHPVersion')->willReturn('5.6.0');
131 $mockVersionInfo->expects(self
::never())->method('getMySQLVersion');
133 $compatible = $mockVersionInfo->getLatestCompatibleVersion($this->releases
);
134 self
::assertInstanceOf(Release
::class, $compatible);
135 self
::assertSame('4.4.14.1', $compatible->version
);
139 * Tests getLatestCompatibleVersion() with an old PHP version
141 public function testGetLatestCompatibleVersionWithOldPHPVersion(): void
143 Config
::getInstance()->settings
['Servers'] = [[], []];
145 $mockVersionInfo = $this->createPartialMock(VersionInformation
::class, ['getPHPVersion', 'getMySQLVersion']);
146 $mockVersionInfo->expects(self
::exactly(4))->method('getPHPVersion')->willReturn('5.2.1');
147 $mockVersionInfo->expects(self
::never())->method('getMySQLVersion');
149 $compatible = $mockVersionInfo->getLatestCompatibleVersion($this->releases
);
150 self
::assertInstanceOf(Release
::class, $compatible);
151 self
::assertSame('4.0.10.10', $compatible->version
);
155 * Tests getLatestCompatibleVersion() with an new PHP version
157 * @param list<Release> $versions The versions to use
158 * @param array{int, string} $conditions The conditions that will be executed
159 * @param string|null $matchedLastVersion The version that will be matched
161 #[DataProvider('dataProviderVersionConditions')]
162 public function testGetLatestCompatibleVersionWithNewPHPVersion(
165 string|
null $matchedLastVersion,
167 Config
::getInstance()->settings
['Servers'] = [];
169 $mockVersionInfo = $this->createPartialMock(VersionInformation
::class, ['getPHPVersion', 'getMySQLVersion']);
170 $mockVersionInfo->expects(self
::exactly($conditions[0]))->method('getPHPVersion')->willReturn($conditions[1]);
171 $mockVersionInfo->expects(self
::never())->method('getMySQLVersion');
173 $compatible = $mockVersionInfo->getLatestCompatibleVersion($versions);
174 self
::assertSame($matchedLastVersion, $compatible->version ??
null);
178 * Provider for testGetLatestCompatibleVersionWithNewPHPVersion
179 * Returns the conditions to be used for mocks
181 * @return list<array{list<Release>, array{int, string}, string|null}>
183 public static function dataProviderVersionConditions(): array
188 new Release('4.9.3', '2019-12-26', '>=5.5,<8.0', '>=5.5'),
189 new Release('5.0.0', '2019-12-26', '>=7.1,<8.0', '>=5.5'),
196 new Release('6.0.0', '2019-12-26', '>=5.5,<7.0', '>=5.5'),
197 new Release('5.0.0', '2019-12-26', '>=7.1,<8.0', '>=5.5'),
204 new Release('6.0.0-rc1', '2019-12-26', '>=5.5,<7.0', '>=5.5'),
205 new Release('6.0.0-rc2', '2019-12-26', '>=7.1,<8.0', '>=5.5'),
212 new Release('6.0.0', '2019-12-26', '>=5.5,<7.0', '>=5.5'),
213 new Release('5.0.0', '2019-12-26', '>=7.1,<8.0', '>=5.5'),
220 new Release('6.0.0', '2019-12-26', '>=5.5,<7.0', '>=5.5'),
221 new Release('5.0.0', '2019-12-26', '>=7.1,<8.0', '>=5.5'),
228 new Release('4.9.3', '2019-12-26', '>=5.5,<8.0', '>=5.5'),
229 new Release('5.0.0', '2019-12-26', '>=7.1,<8.0', '>=5.5'),
236 new Release('5.0.0', '2019-12-26', '>=7.1,<8.0', '>=5.5'),
237 new Release('4.9.3', '2019-12-26', '>=5.5,<8.0', '>=5.5'),
246 * Tests evaluateVersionCondition() method
248 public function testEvaluateVersionCondition(): void
250 $mockVersionInfo = $this->getMockBuilder(VersionInformation
::class)
251 ->onlyMethods(['getPHPVersion'])
254 $mockVersionInfo->expects(self
::any())
255 ->method('getPHPVersion')
256 ->willReturn('5.2.4');
258 self
::assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '<=5.3'));
259 self
::assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '<5.3'));
260 self
::assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '>=5.2'));
261 self
::assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '>5.2'));
262 self
::assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '!=5.3'));
264 self
::assertFalse($mockVersionInfo->evaluateVersionCondition('PHP', '<=5.2'));
265 self
::assertFalse($mockVersionInfo->evaluateVersionCondition('PHP', '<5.2'));
266 self
::assertFalse($mockVersionInfo->evaluateVersionCondition('PHP', '>=7.0'));
267 self
::assertFalse($mockVersionInfo->evaluateVersionCondition('PHP', '>7.0'));
268 self
::assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '!=5.2'));