comparison vendor/phar-io/version/tests/Unit/VersionTest.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2 /*
3 * This file is part of PharIo\Version.
4 *
5 * (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 namespace PharIo\Version;
12
13 use PHPUnit\Framework\TestCase;
14
15 /**
16 * @covers \PharIo\Version\Version
17 */
18 class VersionTest extends TestCase {
19 /**
20 * @dataProvider versionProvider
21 *
22 * @param string $versionString
23 * @param string $expectedMajor
24 * @param string $expectedMinor
25 * @param string $expectedPatch
26 * @param string $expectedPreReleaseValue
27 * @param int $expectedReleaseCount
28 */
29 public function testParsesVersionNumbers($versionString, $expectedMajor, $expectedMinor, $expectedPatch, $expectedPreReleaseValue = '', $expectedReleaseCount = 0) {
30 $version = new Version($versionString);
31
32 $this->assertSame($expectedMajor, $version->getMajor()->getValue());
33 $this->assertSame($expectedMinor, $version->getMinor()->getValue());
34 $this->assertSame($expectedPatch, $version->getPatch()->getValue());
35 if ($expectedPreReleaseValue !== '') {
36 $this->assertSame($expectedPreReleaseValue, $version->getPreReleaseSuffix()->getValue());
37 }
38 if ($expectedReleaseCount !== 0) {
39 $this->assertSame($expectedReleaseCount, $version->getPreReleaseSuffix()->getNumber());
40 }
41
42 $this->assertSame($versionString, $version->getVersionString());
43 }
44
45 public function versionProvider() {
46 return [
47 ['0.0.1', '0', '0', '1'],
48 ['0.1.2', '0', '1', '2'],
49 ['1.0.0-alpha', '1', '0', '0', 'alpha'],
50 ['3.4.12-dev3', '3', '4', '12', 'dev', 3],
51 ];
52 }
53
54 /**
55 * @dataProvider versionGreaterThanProvider
56 *
57 * @param Version $versionA
58 * @param Version $versionB
59 * @param bool $expectedResult
60 */
61 public function testIsGreaterThan(Version $versionA, Version $versionB, $expectedResult) {
62 $this->assertSame($expectedResult, $versionA->isGreaterThan($versionB));
63 }
64
65 /**
66 * @return array
67 */
68 public function versionGreaterThanProvider() {
69 return [
70 [new Version('1.0.0'), new Version('1.0.1'), false],
71 [new Version('1.0.1'), new Version('1.0.0'), true],
72 [new Version('1.1.0'), new Version('1.0.1'), true],
73 [new Version('1.1.0'), new Version('2.0.1'), false],
74 [new Version('1.1.0'), new Version('1.1.0'), false],
75 [new Version('2.5.8'), new Version('1.6.8'), true],
76 [new Version('2.5.8'), new Version('2.6.8'), false],
77 [new Version('2.5.8'), new Version('3.1.2'), false],
78 ];
79 }
80
81 /**
82 * @dataProvider invalidVersionStringProvider
83 *
84 * @param string $versionString
85 */
86 public function testThrowsExceptionIfVersionStringDoesNotFollowSemVer($versionString)
87 {
88 $this->expectException(InvalidVersionException::class);
89 new Version($versionString);
90 }
91
92 /**
93 * @return array
94 */
95 public function invalidVersionStringProvider()
96 {
97 return [
98 ['foo'],
99 ['0.0.1-dev+ABC', '0', '0', '1', 'dev', 'ABC'],
100 ['1.0.0-x.7.z.92', '1', '0', '0', 'x.7.z.92']
101 ];
102 }
103
104 }