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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
<?php
/**
* @covers ComposerVersionNormalizer
*
* @group ComposerHooks
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class ComposerVersionNormalizerTest extends PHPUnit_Framework_TestCase {
/**
* @dataProvider nonStringProvider
*/
public function testGivenNonString_normalizeThrowsInvalidArgumentException( $nonString ) {
$normalizer = new ComposerVersionNormalizer();
$this->setExpectedException( 'InvalidArgumentException' );
$normalizer->normalizeSuffix( $nonString );
}
public function nonStringProvider() {
return array(
array( null ),
array( 42 ),
array( array() ),
array( new stdClass() ),
array( true ),
);
}
/**
* @dataProvider simpleVersionProvider
*/
public function testGivenSimpleVersion_normalizeSuffixReturnsAsIs( $simpleVersion ) {
$this->assertRemainsUnchanged( $simpleVersion );
}
protected function assertRemainsUnchanged( $version ) {
$normalizer = new ComposerVersionNormalizer();
$this->assertEquals(
$version,
$normalizer->normalizeSuffix( $version )
);
}
public function simpleVersionProvider() {
return array(
array( '1.22.0' ),
array( '1.19.2' ),
array( '1.19.2.0' ),
array( '1.9' ),
array( '123.321.456.654' ),
);
}
/**
* @dataProvider complexVersionProvider
*/
public function testGivenComplexVersionWithoutDash_normalizeSuffixAddsDash(
$withoutDash, $withDash
) {
$normalizer = new ComposerVersionNormalizer();
$this->assertEquals(
$withDash,
$normalizer->normalizeSuffix( $withoutDash )
);
}
public function complexVersionProvider() {
return array(
array( '1.22.0alpha', '1.22.0-alpha' ),
array( '1.22.0RC', '1.22.0-RC' ),
array( '1.19beta', '1.19-beta' ),
array( '1.9RC4', '1.9-RC4' ),
array( '1.9.1.2RC4', '1.9.1.2-RC4' ),
array( '1.9.1.2RC', '1.9.1.2-RC' ),
array( '123.321.456.654RC9001', '123.321.456.654-RC9001' ),
);
}
/**
* @dataProvider complexVersionProvider
*/
public function testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs(
$withoutDash, $withDash
) {
$this->assertRemainsUnchanged( $withDash );
}
/**
* @dataProvider fourLevelVersionsProvider
*/
public function testGivenFourLevels_levelCountNormalizationDoesNothing( $version ) {
$normalizer = new ComposerVersionNormalizer();
$this->assertEquals(
$version,
$normalizer->normalizeLevelCount( $version )
);
}
public function fourLevelVersionsProvider() {
return array(
array( '1.22.0.0' ),
array( '1.19.2.4' ),
array( '1.19.2.0' ),
array( '1.9.0.1' ),
array( '123.321.456.654' ),
array( '123.321.456.654RC4' ),
array( '123.321.456.654-RC4' ),
);
}
/**
* @dataProvider levelNormalizationProvider
*/
public function testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels(
$expected, $version
) {
$normalizer = new ComposerVersionNormalizer();
$this->assertEquals(
$expected,
$normalizer->normalizeLevelCount( $version )
);
}
public function levelNormalizationProvider() {
return array(
array( '1.22.0.0', '1.22' ),
array( '1.22.0.0', '1.22.0' ),
array( '1.19.2.0', '1.19.2' ),
array( '12345.0.0.0', '12345' ),
array( '12345.0.0.0-RC4', '12345-RC4' ),
array( '12345.0.0.0-alpha', '12345-alpha' ),
);
}
/**
* @dataProvider invalidVersionProvider
*/
public function testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion ) {
$this->assertRemainsUnchanged( $invalidVersion );
}
public function invalidVersionProvider() {
return array(
array( '1.221-a' ),
array( '1.221-' ),
array( '1.22rc4a' ),
array( 'a1.22rc' ),
array( '.1.22rc' ),
array( 'a' ),
array( 'alpha42' ),
);
}
}
|