VersionConstraintParserTest.php
4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
use PHPUnit\Framework\TestCase;
/**
* @covers \PharIo\Version\VersionConstraintParser
*/
class VersionConstraintParserTest extends TestCase {
/**
* @dataProvider versionStringProvider
*
* @param string $versionString
* @param VersionConstraint $expectedConstraint
*/
public function testReturnsExpectedConstraint($versionString, VersionConstraint $expectedConstraint) {
$parser = new VersionConstraintParser;
$this->assertEquals($expectedConstraint, $parser->parse($versionString));
}
/**
* @dataProvider unsupportedVersionStringProvider
*
* @param string $versionString
*/
public function testThrowsExceptionIfVersionStringIsNotSupported($versionString) {
$parser = new VersionConstraintParser;
$this->expectException(UnsupportedVersionConstraintException::class);
$parser->parse($versionString);
}
/**
* @return array
*/
public function versionStringProvider() {
return [
['1.0.2', new ExactVersionConstraint('1.0.2')],
[
'~4.6',
new AndVersionConstraintGroup(
'~4.6',
[
new GreaterThanOrEqualToVersionConstraint('~4.6', new Version('4.6')),
new SpecificMajorVersionConstraint('~4.6', 4)
]
)
],
[
'~4.6.2',
new AndVersionConstraintGroup(
'~4.6.2',
[
new GreaterThanOrEqualToVersionConstraint('~4.6.2', new Version('4.6.2')),
new SpecificMajorAndMinorVersionConstraint('~4.6.2', 4, 6)
]
)
],
[
'^2.6.1',
new AndVersionConstraintGroup(
'^2.6.1',
[
new GreaterThanOrEqualToVersionConstraint('^2.6.1', new Version('2.6.1')),
new SpecificMajorVersionConstraint('^2.6.1', 2)
]
)
],
['5.1.*', new SpecificMajorAndMinorVersionConstraint('5.1.*', 5, 1)],
['5.*', new SpecificMajorVersionConstraint('5.*', 5)],
['*', new AnyVersionConstraint()],
[
'1.0.2 || 1.0.5',
new OrVersionConstraintGroup(
'1.0.2 || 1.0.5',
[
new ExactVersionConstraint('1.0.2'),
new ExactVersionConstraint('1.0.5')
]
)
],
[
'^5.6 || ^7.0',
new OrVersionConstraintGroup(
'^5.6 || ^7.0',
[
new AndVersionConstraintGroup(
'^5.6', [
new GreaterThanOrEqualToVersionConstraint('^5.6', new Version('5.6')),
new SpecificMajorVersionConstraint('^5.6', 5)
]
),
new AndVersionConstraintGroup(
'^7.0', [
new GreaterThanOrEqualToVersionConstraint('^7.0', new Version('7.0')),
new SpecificMajorVersionConstraint('^7.0', 7)
]
)
]
)
],
['7.0.28-1', new ExactVersionConstraint('7.0.28-1')],
[
'^3.0.0-alpha1',
new AndVersionConstraintGroup(
'^3.0.0-alpha1',
[
new GreaterThanOrEqualToVersionConstraint('^3.0.0-alpha1', new Version('3.0.0-alpha1')),
new SpecificMajorVersionConstraint('^3.0.0-alpha1', 3)
]
)
],
[
'^3.0.0-alpha.1',
new AndVersionConstraintGroup(
'^3.0.0-alpha.1',
[
new GreaterThanOrEqualToVersionConstraint('^3.0.0-alpha.1', new Version('3.0.0-alpha.1')),
new SpecificMajorVersionConstraint('^3.0.0-alpha.1', 3)
]
)
]
];
}
public function unsupportedVersionStringProvider() {
return [
['foo'],
['+1.0.2'],
['>=2.0'],
['^5.6 || >= 7.0'],
['2.0 || foo']
];
}
}