Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / composer / ComposerVersionNormalizerTest.php
blob3f887dc08c1e273a738349eb094e8c85455d9623
1 <?php
3 /**
4 * @covers ComposerVersionNormalizer
6 * @group ComposerHooks
8 * @licence GNU GPL v2+
9 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
11 class ComposerVersionNormalizerTest extends PHPUnit_Framework_TestCase {
13 /**
14 * @dataProvider nonStringProvider
16 public function testGivenNonString_normalizeThrowsInvalidArgumentException( $nonString ) {
17 $normalizer = new ComposerVersionNormalizer();
19 $this->setExpectedException( 'InvalidArgumentException' );
20 $normalizer->normalizeSuffix( $nonString );
23 public function nonStringProvider() {
24 return array(
25 array( null ),
26 array( 42 ),
27 array( array() ),
28 array( new stdClass() ),
29 array( true ),
33 /**
34 * @dataProvider simpleVersionProvider
36 public function testGivenSimpleVersion_normalizeSuffixReturnsAsIs( $simpleVersion ) {
37 $this->assertRemainsUnchanged( $simpleVersion );
40 protected function assertRemainsUnchanged( $version ) {
41 $normalizer = new ComposerVersionNormalizer();
43 $this->assertEquals(
44 $version,
45 $normalizer->normalizeSuffix( $version )
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' ),
59 /**
60 * @dataProvider complexVersionProvider
62 public function testGivenComplexVersionWithoutDash_normalizeSuffixAddsDash(
63 $withoutDash, $withDash
64 ) {
65 $normalizer = new ComposerVersionNormalizer();
67 $this->assertEquals(
68 $withDash,
69 $normalizer->normalizeSuffix( $withoutDash )
73 public function complexVersionProvider() {
74 return array(
75 array( '1.22.0alpha', '1.22.0-alpha' ),
76 array( '1.22.0RC', '1.22.0-RC' ),
77 array( '1.19beta', '1.19-beta' ),
78 array( '1.9RC4', '1.9-RC4' ),
79 array( '1.9.1.2RC4', '1.9.1.2-RC4' ),
80 array( '1.9.1.2RC', '1.9.1.2-RC' ),
81 array( '123.321.456.654RC9001', '123.321.456.654-RC9001' ),
85 /**
86 * @dataProvider complexVersionProvider
88 public function testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs(
89 $withoutDash, $withDash
90 ) {
91 $this->assertRemainsUnchanged( $withDash );
94 /**
95 * @dataProvider fourLevelVersionsProvider
97 public function testGivenFourLevels_levelCountNormalizationDoesNothing( $version ) {
98 $normalizer = new ComposerVersionNormalizer();
100 $this->assertEquals(
101 $version,
102 $normalizer->normalizeLevelCount( $version )
106 public function fourLevelVersionsProvider() {
107 return array(
108 array( '1.22.0.0' ),
109 array( '1.19.2.4' ),
110 array( '1.19.2.0' ),
111 array( '1.9.0.1' ),
112 array( '123.321.456.654' ),
113 array( '123.321.456.654RC4' ),
114 array( '123.321.456.654-RC4' ),
119 * @dataProvider levelNormalizationProvider
121 public function testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels(
122 $expected, $version
124 $normalizer = new ComposerVersionNormalizer();
126 $this->assertEquals(
127 $expected,
128 $normalizer->normalizeLevelCount( $version )
132 public function levelNormalizationProvider() {
133 return array(
134 array( '1.22.0.0', '1.22' ),
135 array( '1.22.0.0', '1.22.0' ),
136 array( '1.19.2.0', '1.19.2' ),
137 array( '12345.0.0.0', '12345' ),
138 array( '12345.0.0.0-RC4', '12345-RC4' ),
139 array( '12345.0.0.0-alpha', '12345-alpha' ),
144 * @dataProvider invalidVersionProvider
146 public function testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion ) {
147 $this->assertRemainsUnchanged( $invalidVersion );
150 public function invalidVersionProvider() {
151 return array(
152 array( '1.221-a' ),
153 array( '1.221-' ),
154 array( '1.22rc4a' ),
155 array( 'a1.22rc' ),
156 array( '.1.22rc' ),
157 array( 'a' ),
158 array( 'alpha42' ),