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