Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / composer / ComposerVersionNormalizerTest.php
blob2fa11eaf3a03926ab43e0190baa9187099fef260
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 array(
24 array( null ),
25 array( 42 ),
26 array( array() ),
27 array( new stdClass() ),
28 array( 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 array(
50 array( '1.22.0' ),
51 array( '1.19.2' ),
52 array( '1.19.2.0' ),
53 array( '1.9' ),
54 array( '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 array(
74 array( '1.22.0alpha', '1.22.0-alpha' ),
75 array( '1.22.0RC', '1.22.0-RC' ),
76 array( '1.19beta', '1.19-beta' ),
77 array( '1.9RC4', '1.9-RC4' ),
78 array( '1.9.1.2RC4', '1.9.1.2-RC4' ),
79 array( '1.9.1.2RC', '1.9.1.2-RC' ),
80 array( '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 array(
107 array( '1.22.0.0' ),
108 array( '1.19.2.4' ),
109 array( '1.19.2.0' ),
110 array( '1.9.0.1' ),
111 array( '123.321.456.654' ),
112 array( '123.321.456.654RC4' ),
113 array( '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 array(
133 array( '1.22.0.0', '1.22' ),
134 array( '1.22.0.0', '1.22.0' ),
135 array( '1.19.2.0', '1.19.2' ),
136 array( '12345.0.0.0', '12345' ),
137 array( '12345.0.0.0-RC4', '12345-RC4' ),
138 array( '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 array(
151 array( '1.221-a' ),
152 array( '1.221-' ),
153 array( '1.22rc4a' ),
154 array( 'a1.22rc' ),
155 array( '.1.22rc' ),
156 array( 'a' ),
157 array( 'alpha42' ),