Added release notes for 'ContentHandler::runLegacyHooks' removal
[mediawiki.git] / tests / phpunit / includes / composer / ComposerVersionNormalizerTest.php
blob8a2ebaff41a4dccae774d5935cccbea613a346ef
1 <?php
3 /**
4 * @covers ComposerVersionNormalizer
6 * @group ComposerHooks
8 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
9 */
10 class ComposerVersionNormalizerTest extends PHPUnit_Framework_TestCase {
12 /**
13 * @dataProvider nonStringProvider
15 public function testGivenNonString_normalizeThrowsInvalidArgumentException( $nonString ) {
16 $normalizer = new ComposerVersionNormalizer();
18 $this->setExpectedException( 'InvalidArgumentException' );
19 $normalizer->normalizeSuffix( $nonString );
22 public function nonStringProvider() {
23 return [
24 [ null ],
25 [ 42 ],
26 [ [] ],
27 [ new stdClass() ],
28 [ true ],
32 /**
33 * @dataProvider simpleVersionProvider
35 public function testGivenSimpleVersion_normalizeSuffixReturnsAsIs( $simpleVersion ) {
36 $this->assertRemainsUnchanged( $simpleVersion );
39 protected function assertRemainsUnchanged( $version ) {
40 $normalizer = new ComposerVersionNormalizer();
42 $this->assertEquals(
43 $version,
44 $normalizer->normalizeSuffix( $version )
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' ],
58 /**
59 * @dataProvider complexVersionProvider
61 public function testGivenComplexVersionWithoutDash_normalizeSuffixAddsDash(
62 $withoutDash, $withDash
63 ) {
64 $normalizer = new ComposerVersionNormalizer();
66 $this->assertEquals(
67 $withDash,
68 $normalizer->normalizeSuffix( $withoutDash )
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' ],
84 /**
85 * @dataProvider complexVersionProvider
87 public function testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs(
88 $withoutDash, $withDash
89 ) {
90 $this->assertRemainsUnchanged( $withDash );
93 /**
94 * @dataProvider fourLevelVersionsProvider
96 public function testGivenFourLevels_levelCountNormalizationDoesNothing( $version ) {
97 $normalizer = new ComposerVersionNormalizer();
99 $this->assertEquals(
100 $version,
101 $normalizer->normalizeLevelCount( $version )
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' ],
118 * @dataProvider levelNormalizationProvider
120 public function testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels(
121 $expected, $version
123 $normalizer = new ComposerVersionNormalizer();
125 $this->assertEquals(
126 $expected,
127 $normalizer->normalizeLevelCount( $version )
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' ],
143 * @dataProvider invalidVersionProvider
145 public function testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion ) {
146 $this->assertRemainsUnchanged( $invalidVersion );
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' ],