comparison vendor/phar-io/version/tests/Integration/VersionConstraintParserTest.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\VersionConstraintParser
17 */
18 class VersionConstraintParserTest extends TestCase {
19 /**
20 * @dataProvider versionStringProvider
21 *
22 * @param string $versionString
23 * @param VersionConstraint $expectedConstraint
24 */
25 public function testReturnsExpectedConstraint($versionString, VersionConstraint $expectedConstraint) {
26 $parser = new VersionConstraintParser;
27
28 $this->assertEquals($expectedConstraint, $parser->parse($versionString));
29 }
30
31 /**
32 * @dataProvider unsupportedVersionStringProvider
33 *
34 * @param string $versionString
35 */
36 public function testThrowsExceptionIfVersionStringIsNotSupported($versionString) {
37 $parser = new VersionConstraintParser;
38
39 $this->expectException(UnsupportedVersionConstraintException::class);
40
41 $parser->parse($versionString);
42 }
43
44 /**
45 * @return array
46 */
47 public function versionStringProvider() {
48 return [
49 ['1.0.2', new ExactVersionConstraint('1.0.2')],
50 [
51 '~4.6',
52 new AndVersionConstraintGroup(
53 '~4.6',
54 [
55 new GreaterThanOrEqualToVersionConstraint('~4.6', new Version('4.6')),
56 new SpecificMajorVersionConstraint('~4.6', 4)
57 ]
58 )
59 ],
60 [
61 '~4.6.2',
62 new AndVersionConstraintGroup(
63 '~4.6.2',
64 [
65 new GreaterThanOrEqualToVersionConstraint('~4.6.2', new Version('4.6.2')),
66 new SpecificMajorAndMinorVersionConstraint('~4.6.2', 4, 6)
67 ]
68 )
69 ],
70 [
71 '^2.6.1',
72 new AndVersionConstraintGroup(
73 '^2.6.1',
74 [
75 new GreaterThanOrEqualToVersionConstraint('^2.6.1', new Version('2.6.1')),
76 new SpecificMajorVersionConstraint('^2.6.1', 2)
77 ]
78 )
79 ],
80 ['5.1.*', new SpecificMajorAndMinorVersionConstraint('5.1.*', 5, 1)],
81 ['5.*', new SpecificMajorVersionConstraint('5.*', 5)],
82 ['*', new AnyVersionConstraint()],
83 [
84 '1.0.2 || 1.0.5',
85 new OrVersionConstraintGroup(
86 '1.0.2 || 1.0.5',
87 [
88 new ExactVersionConstraint('1.0.2'),
89 new ExactVersionConstraint('1.0.5')
90 ]
91 )
92 ],
93 [
94 '^5.6 || ^7.0',
95 new OrVersionConstraintGroup(
96 '^5.6 || ^7.0',
97 [
98 new AndVersionConstraintGroup(
99 '^5.6', [
100 new GreaterThanOrEqualToVersionConstraint('^5.6', new Version('5.6')),
101 new SpecificMajorVersionConstraint('^5.6', 5)
102 ]
103 ),
104 new AndVersionConstraintGroup(
105 '^7.0', [
106 new GreaterThanOrEqualToVersionConstraint('^7.0', new Version('7.0')),
107 new SpecificMajorVersionConstraint('^7.0', 7)
108 ]
109 )
110 ]
111 )
112 ]
113 ];
114 }
115
116 public function unsupportedVersionStringProvider() {
117 return [
118 ['foo'],
119 ['+1.0.2'],
120 ['>=2.0'],
121 ['^5.6 || >= 7.0'],
122 ['2.0 || foo']
123 ];
124 }
125 }