Merge "Allow wildcard searching in wiki IDs for interwiki user rights logs"
[lhc/web/wiklou.git] / tests / phpunit / includes / composer / ComposerVersionNormalizerTest.php
1 <?php
2
3 /**
4 * @covers ComposerVersionNormalizer
5 *
6 * @group ComposerHooks
7 *
8 * @licence GNU GPL v2+
9 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
10 */
11 class ComposerVersionNormalizerTest extends PHPUnit_Framework_TestCase {
12
13 /**
14 * @dataProvider nonStringProvider
15 */
16 public function testGivenNonString_normalizeThrowsInvalidArgumentException( $nonString ) {
17 $normalizer = new ComposerVersionNormalizer();
18
19 $this->setExpectedException( 'InvalidArgumentException' );
20 $normalizer->normalizeSuffix( $nonString );
21 }
22
23 public function nonStringProvider() {
24 return array(
25 array( null ),
26 array( 42 ),
27 array( array() ),
28 array( new stdClass() ),
29 array( true ),
30 );
31 }
32
33 /**
34 * @dataProvider simpleVersionProvider
35 */
36 public function testGivenSimpleVersion_normalizeSuffixReturnsAsIs( $simpleVersion ) {
37 $this->assertRemainsUnchanged( $simpleVersion );
38 }
39
40 protected function assertRemainsUnchanged( $version ) {
41 $normalizer = new ComposerVersionNormalizer();
42
43 $this->assertEquals(
44 $version,
45 $normalizer->normalizeSuffix( $version )
46 );
47 }
48
49 public function simpleVersionProvider() {
50 return array(
51 array( '1.22.0' ),
52 array( '1.19.2' ),
53 array( '1.19.2.0' ),
54 array( '1.9' ),
55 array( '123.321.456.654' ),
56 );
57 }
58
59 /**
60 * @dataProvider complexVersionProvider
61 */
62 public function testGivenComplexVersionWithoutDash_normalizeSuffixAddsDash(
63 $withoutDash, $withDash
64 ) {
65 $normalizer = new ComposerVersionNormalizer();
66
67 $this->assertEquals(
68 $withDash,
69 $normalizer->normalizeSuffix( $withoutDash )
70 );
71 }
72
73 public function complexVersionProvider() {
74 return array(
75 array( '1.22.0alpha', '1.22.0-alpha' ),
76 array( '1.22.0RC', '1.22.0-RC' ),
77 array( '1.19beta', '1.19-beta' ),
78 array( '1.9RC4', '1.9-RC4' ),
79 array( '1.9.1.2RC4', '1.9.1.2-RC4' ),
80 array( '1.9.1.2RC', '1.9.1.2-RC' ),
81 array( '123.321.456.654RC9001', '123.321.456.654-RC9001' ),
82 );
83 }
84
85 /**
86 * @dataProvider complexVersionProvider
87 */
88 public function testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs(
89 $withoutDash, $withDash
90 ) {
91 $this->assertRemainsUnchanged( $withDash );
92 }
93
94 /**
95 * @dataProvider fourLevelVersionsProvider
96 */
97 public function testGivenFourLevels_levelCountNormalizationDoesNothing( $version ) {
98 $normalizer = new ComposerVersionNormalizer();
99
100 $this->assertEquals(
101 $version,
102 $normalizer->normalizeLevelCount( $version )
103 );
104 }
105
106 public function fourLevelVersionsProvider() {
107 return array(
108 array( '1.22.0.0' ),
109 array( '1.19.2.4' ),
110 array( '1.19.2.0' ),
111 array( '1.9.0.1' ),
112 array( '123.321.456.654' ),
113 array( '123.321.456.654RC4' ),
114 array( '123.321.456.654-RC4' ),
115 );
116 }
117
118 /**
119 * @dataProvider levelNormalizationProvider
120 */
121 public function testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels(
122 $expected, $version
123 ) {
124 $normalizer = new ComposerVersionNormalizer();
125
126 $this->assertEquals(
127 $expected,
128 $normalizer->normalizeLevelCount( $version )
129 );
130 }
131
132 public function levelNormalizationProvider() {
133 return array(
134 array( '1.22.0.0', '1.22' ),
135 array( '1.22.0.0', '1.22.0' ),
136 array( '1.19.2.0', '1.19.2' ),
137 array( '12345.0.0.0', '12345' ),
138 array( '12345.0.0.0-RC4', '12345-RC4' ),
139 array( '12345.0.0.0-alpha', '12345-alpha' ),
140 );
141 }
142
143 /**
144 * @dataProvider invalidVersionProvider
145 */
146 public function testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion ) {
147 $this->assertRemainsUnchanged( $invalidVersion );
148 }
149
150 public function invalidVersionProvider() {
151 return array(
152 array( '1.221-a' ),
153 array( '1.221-' ),
154 array( '1.22rc4a' ),
155 array( 'a1.22rc' ),
156 array( '.1.22rc' ),
157 array( 'a' ),
158 array( 'alpha42' ),
159 );
160 }
161 }