2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Tests for methods in PhpMyAdmin\VersionInformation class
6 * @package PhpMyAdmin-test
8 declare(strict_types
=1);
10 namespace PhpMyAdmin\Tests
;
12 use PhpMyAdmin\Tests\PmaTestCase
;
13 use PhpMyAdmin\VersionInformation
;
17 * Tests for methods in PhpMyAdmin\VersionInformation class
19 * @package PhpMyAdmin-test
21 class VersionInformationTest
extends PmaTestCase
26 * Sets up the fixture, for example, opens a network connection.
27 * This method is called before a test is executed.
31 protected function setUp(): void
33 $this->_releases
= [];
35 $release = new stdClass();
36 $release->date
= "2015-09-08";
37 $release->php_versions
= ">=5.3,<7.1";
38 $release->version
= "4.4.14.1";
39 $release->mysql_versions
= ">=5.5";
40 $this->_releases
[] = $release;
42 $release = new stdClass();
43 $release->date
= "2015-09-09";
44 $release->php_versions
= ">=5.3,<7.0";
45 $release->version
= "4.4.13.3";
46 $release->mysql_versions
= ">=5.5";
47 $this->_releases
[] = $release;
49 $release = new stdClass();
50 $release->date
= "2015-05-13";
51 $release->php_versions
= ">=5.2,<5.3";
52 $release->version
= "4.0.10.10";
53 $release->mysql_versions
= ">=5.0";
54 $this->_releases
[] = $release;
58 * Test version checking
65 public function testGetLatestVersion()
67 $GLOBALS['cfg']['ProxyUrl'] = PROXY_URL
;
68 $GLOBALS['cfg']['ProxyUser'] = PROXY_USER
;
69 $GLOBALS['cfg']['ProxyPass'] = PROXY_PASS
;
70 $GLOBALS['cfg']['VersionCheck'] = true;
71 $versionInformation = new VersionInformation();
72 $version = $versionInformation->getLatestVersion();
73 $this->assertNotEmpty($version->version
);
74 $this->assertNotEmpty($version->date
);
78 * Test version to int conversion.
80 * @param string $version Version string
81 * @param int $numeric Integer matching version
85 * @dataProvider dataVersions
87 public function testVersionToInt($version, $numeric): void
89 $versionInformation = new VersionInformation();
92 $versionInformation->versionToInt($version)
98 * Data provider for version parsing
100 * @return array with test data
102 public function dataVersions()
185 * Tests getLatestCompatibleVersion() when there is only one server confgiured
189 public function testGetLatestCompatibleVersionWithSingleServer()
191 $GLOBALS['cfg']['Servers'] = [
195 $mockVersionInfo = $this->getMockBuilder('PhpMyAdmin\VersionInformation')
196 ->setMethods(['evaluateVersionCondition'])
199 $mockVersionInfo->expects($this->at(0))
200 ->method('evaluateVersionCondition')
201 ->with('PHP', '>=5.3')
202 ->will($this->returnValue(true));
204 $mockVersionInfo->expects($this->at(1))
205 ->method('evaluateVersionCondition')
206 ->with('PHP', '<7.1')
207 ->will($this->returnValue(true));
209 $mockVersionInfo->expects($this->at(2))
210 ->method('evaluateVersionCondition')
211 ->with('MySQL', '>=5.5')
212 ->will($this->returnValue(true));
214 $compatible = $mockVersionInfo
215 ->getLatestCompatibleVersion($this->_releases
);
216 $this->assertEquals('4.4.14.1', $compatible['version']);
220 * Tests getLatestCompatibleVersion() when there are multiple servers configured
224 public function testGetLatestCompatibleVersionWithMultipleServers()
226 $GLOBALS['cfg']['Servers'] = [
231 $mockVersionInfo = $this->getMockBuilder('PhpMyAdmin\VersionInformation')
232 ->setMethods(['evaluateVersionCondition'])
235 $mockVersionInfo->expects($this->at(0))
236 ->method('evaluateVersionCondition')
237 ->with('PHP', '>=5.3')
238 ->will($this->returnValue(true));
240 $mockVersionInfo->expects($this->at(1))
241 ->method('evaluateVersionCondition')
242 ->with('PHP', '<7.1')
243 ->will($this->returnValue(true));
245 $compatible = $mockVersionInfo
246 ->getLatestCompatibleVersion($this->_releases
);
247 $this->assertEquals('4.4.14.1', $compatible['version']);
251 * Tests getLatestCompatibleVersion() with an old PHP version
255 public function testGetLatestCompatibleVersionWithOldPHPVersion()
257 $GLOBALS['cfg']['Servers'] = [
262 $mockVersionInfo = $this->getMockBuilder('PhpMyAdmin\VersionInformation')
263 ->setMethods(['evaluateVersionCondition'])
266 $mockVersionInfo->expects($this->at(0))
267 ->method('evaluateVersionCondition')
268 ->with('PHP', '>=5.3')
269 ->will($this->returnValue(false));
271 $mockVersionInfo->expects($this->at(1))
272 ->method('evaluateVersionCondition')
273 ->with('PHP', '>=5.3')
274 ->will($this->returnValue(false));
276 $mockVersionInfo->expects($this->at(2))
277 ->method('evaluateVersionCondition')
278 ->with('PHP', '>=5.2')
279 ->will($this->returnValue(true));
281 $mockVersionInfo->expects($this->at(3))
282 ->method('evaluateVersionCondition')
283 ->with('PHP', '<5.3')
284 ->will($this->returnValue(true));
286 $compatible = $mockVersionInfo
287 ->getLatestCompatibleVersion($this->_releases
);
288 $this->assertEquals('4.0.10.10', $compatible['version']);
293 * Tests getLatestCompatibleVersion() with an new PHP version
295 * @dataProvider dataProviderVersionConditions
296 * @param array[] $versions The versions to use
297 * @param array[] $conditions The conditions that will be executed
298 * @param string|null $matchedLastVersion The version that will be matched
301 public function testGetLatestCompatibleVersionWithNewPHPVersion(array $versions, array $conditions, ?
string $matchedLastVersion): void
303 $GLOBALS['cfg']['Servers'] = [];
305 $mockVersionInfo = $this->getMockBuilder(VersionInformation
::class)
306 ->setMethods(['evaluateVersionCondition'])
310 foreach ($conditions as $conditionArray) {
315 $mockVersionInfo->expects($this->at($i))
316 ->method('evaluateVersionCondition')
317 ->with('PHP', $condition)
318 ->will($this->returnValue($returnValue));
321 /** @var VersionInformation $mockVersionInfo */
322 $compatible = $mockVersionInfo->getLatestCompatibleVersion($versions);
323 $this->assertEquals($matchedLastVersion, $compatible['version'] ??
null);
327 * Provider for testGetLatestCompatibleVersionWithNewPHPVersion
328 * Returns the conditions to be used for mocks
331 public function dataProviderVersionConditions(): array
337 'date' => '2019-12-26',
338 'php_versions' => '>=5.5,<8.0',
339 'version' => '4.9.3',
340 'mysql_versions' => '>=5.5',
343 'date' => '2019-12-26',
344 'php_versions' => '>=7.1,<8.0',
345 'version' => '5.0.0',
346 'mysql_versions' => '>=5.5',
372 'date' => '2019-12-26',
373 'php_versions' => '>=5.5,<7.0',
374 'version' => '6.0.0',
375 'mysql_versions' => '>=5.5',
378 'date' => '2019-12-26',
379 'php_versions' => '>=7.1,<8.0',
380 'version' => '5.0.0',
381 'mysql_versions' => '>=5.5',
403 'date' => '2019-12-26',
404 'php_versions' => '>=5.5,<7.0',
405 'version' => '6.0.0-rc1',
406 'mysql_versions' => '>=5.5',
409 'date' => '2019-12-26',
410 'php_versions' => '>=7.1,<8.0',
411 'version' => '6.0.0-rc2',
412 'mysql_versions' => '>=5.5',
434 'date' => '2019-12-26',
435 'php_versions' => '>=5.5,<7.0',
436 'version' => '6.0.0',
437 'mysql_versions' => '>=5.5',
440 'date' => '2019-12-26',
441 'php_versions' => '>=7.1,<8.0',
442 'version' => '5.0.0',
443 'mysql_versions' => '>=5.5',
465 'date' => '2019-12-26',
466 'php_versions' => '>=5.5,<7.0',
467 'version' => '6.0.0',
468 'mysql_versions' => '>=5.5',
471 'date' => '2019-12-26',
472 'php_versions' => '>=7.1,<8.0',
473 'version' => '5.0.0',
474 'mysql_versions' => '>=5.5',
496 'date' => '2019-12-26',
497 'php_versions' => '>=5.5,<8.0',
498 'version' => '4.9.3',
499 'mysql_versions' => '>=5.5',
502 'date' => '2019-12-26',
503 'php_versions' => '>=7.1,<8.0',
504 'version' => '5.0.0',
505 'mysql_versions' => '>=5.5',
531 'date' => '2019-12-26',
532 'php_versions' => '>=7.1,<8.0',
533 'version' => '5.0.0',
534 'mysql_versions' => '>=5.5',
537 'date' => '2019-12-26',
538 'php_versions' => '>=5.5,<8.0',
539 'version' => '4.9.3',
540 'mysql_versions' => '>=5.5',
567 * Tests evaluateVersionCondition() method
571 public function testEvaluateVersionCondition()
573 $mockVersionInfo = $this->getMockBuilder('PhpMyAdmin\VersionInformation')
574 ->setMethods(['getPHPVersion'])
577 $mockVersionInfo->expects($this->any())
578 ->method('getPHPVersion')
579 ->will($this->returnValue('5.2.4'));
581 $this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '<=5.3'));
582 $this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '<5.3'));
583 $this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '>=5.2'));
584 $this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '>5.2'));
585 $this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '!=5.3'));
587 $this->assertFalse($mockVersionInfo->evaluateVersionCondition('PHP', '<=5.2'));
588 $this->assertFalse($mockVersionInfo->evaluateVersionCondition('PHP', '<5.2'));
589 $this->assertFalse($mockVersionInfo->evaluateVersionCondition('PHP', '>=7.0'));
590 $this->assertFalse($mockVersionInfo->evaluateVersionCondition('PHP', '>7.0'));
591 $this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '!=5.2'));