Merge "ResourceLoaderStartUpModule: Use hashMtime to detect config changes"
[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( $withoutDash, $withDash ) {
63 $normalizer = new ComposerVersionNormalizer();
64
65 $this->assertEquals(
66 $withDash,
67 $normalizer->normalizeSuffix( $withoutDash )
68 );
69 }
70
71 public function complexVersionProvider() {
72 return array(
73 array( '1.22.0alpha', '1.22.0-alpha' ),
74 array( '1.22.0RC', '1.22.0-RC' ),
75 array( '1.19beta', '1.19-beta' ),
76 array( '1.9RC4', '1.9-RC4' ),
77 array( '1.9.1.2RC4', '1.9.1.2-RC4' ),
78 array( '1.9.1.2RC', '1.9.1.2-RC' ),
79 array( '123.321.456.654RC9001', '123.321.456.654-RC9001' ),
80 );
81 }
82
83 /**
84 * @dataProvider complexVersionProvider
85 */
86 public function testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs( $withoutDash, $withDash ) {
87 $this->assertRemainsUnchanged( $withDash );
88 }
89
90 /**
91 * @dataProvider fourLevelVersionsProvider
92 */
93 public function testGivenFourLevels_levelCountNormalizationDoesNothing( $version ) {
94 $normalizer = new ComposerVersionNormalizer();
95
96 $this->assertEquals(
97 $version,
98 $normalizer->normalizeLevelCount( $version )
99 );
100 }
101
102 public function fourLevelVersionsProvider() {
103 return array(
104 array( '1.22.0.0' ),
105 array( '1.19.2.4' ),
106 array( '1.19.2.0' ),
107 array( '1.9.0.1' ),
108 array( '123.321.456.654' ),
109 array( '123.321.456.654RC4' ),
110 array( '123.321.456.654-RC4' ),
111 );
112 }
113
114 /**
115 * @dataProvider levelNormalizationProvider
116 */
117 public function testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels( $expected, $version ) {
118 $normalizer = new ComposerVersionNormalizer();
119
120 $this->assertEquals(
121 $expected,
122 $normalizer->normalizeLevelCount( $version )
123 );
124 }
125
126 public function levelNormalizationProvider() {
127 return array(
128 array( '1.22.0.0', '1.22' ),
129 array( '1.22.0.0', '1.22.0' ),
130 array( '1.19.2.0', '1.19.2' ),
131 array( '12345.0.0.0', '12345' ),
132 array( '12345.0.0.0-RC4', '12345-RC4' ),
133 array( '12345.0.0.0-alpha', '12345-alpha' ),
134 );
135 }
136
137 /**
138 * @dataProvider invalidVersionProvider
139 */
140 public function testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion ) {
141 $this->assertRemainsUnchanged( $invalidVersion );
142 }
143
144 public function invalidVersionProvider() {
145 return array(
146 array( '1.221-a' ),
147 array( '1.221-' ),
148 array( '1.22rc4a' ),
149 array( 'a1.22rc' ),
150 array( '.1.22rc' ),
151 array( 'a' ),
152 array( 'alpha42' ),
153 );
154 }
155 }