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