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