MediaWiki
REL1_23
|
00001 <?php 00002 00011 class ComposerVersionNormalizerTest extends PHPUnit_Framework_TestCase { 00012 00016 public function testGivenNonString_normalizeThrowsInvalidArgumentException( $nonString ) { 00017 $normalizer = new ComposerVersionNormalizer(); 00018 00019 $this->setExpectedException( 'InvalidArgumentException' ); 00020 $normalizer->normalizeSuffix( $nonString ); 00021 } 00022 00023 public function nonStringProvider() { 00024 return array( 00025 array( null ), 00026 array( 42 ), 00027 array( array() ), 00028 array( new stdClass() ), 00029 array( true ), 00030 ); 00031 } 00032 00036 public function testGivenSimpleVersion_normalizeSuffixReturnsAsIs( $simpleVersion ) { 00037 $this->assertRemainsUnchanged( $simpleVersion ); 00038 } 00039 00040 protected function assertRemainsUnchanged( $version ) { 00041 $normalizer = new ComposerVersionNormalizer(); 00042 00043 $this->assertEquals( 00044 $version, 00045 $normalizer->normalizeSuffix( $version ) 00046 ); 00047 } 00048 00049 public function simpleVersionProvider() { 00050 return array( 00051 array( '1.22.0' ), 00052 array( '1.19.2' ), 00053 array( '1.19.2.0' ), 00054 array( '1.9' ), 00055 array( '123.321.456.654' ), 00056 ); 00057 } 00058 00062 public function testGivenComplexVersionWithoutDash_normalizeSuffixAddsDash( $withoutDash, $withDash ) { 00063 $normalizer = new ComposerVersionNormalizer(); 00064 00065 $this->assertEquals( 00066 $withDash, 00067 $normalizer->normalizeSuffix( $withoutDash ) 00068 ); 00069 } 00070 00071 public function complexVersionProvider() { 00072 return array( 00073 array( '1.22.0alpha', '1.22.0-alpha' ), 00074 array( '1.22.0RC', '1.22.0-RC' ), 00075 array( '1.19beta', '1.19-beta' ), 00076 array( '1.9RC4', '1.9-RC4' ), 00077 array( '1.9.1.2RC4', '1.9.1.2-RC4' ), 00078 array( '1.9.1.2RC', '1.9.1.2-RC' ), 00079 array( '123.321.456.654RC9001', '123.321.456.654-RC9001' ), 00080 ); 00081 } 00082 00086 public function testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs( $withoutDash, $withDash ) { 00087 $this->assertRemainsUnchanged( $withDash ); 00088 } 00089 00093 public function testGivenFourLevels_levelCountNormalizationDoesNothing( $version ) { 00094 $normalizer = new ComposerVersionNormalizer(); 00095 00096 $this->assertEquals( 00097 $version, 00098 $normalizer->normalizeLevelCount( $version ) 00099 ); 00100 } 00101 00102 public function fourLevelVersionsProvider() { 00103 return array( 00104 array( '1.22.0.0' ), 00105 array( '1.19.2.4' ), 00106 array( '1.19.2.0' ), 00107 array( '1.9.0.1' ), 00108 array( '123.321.456.654' ), 00109 array( '123.321.456.654RC4' ), 00110 array( '123.321.456.654-RC4' ), 00111 ); 00112 } 00113 00117 public function testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels( $expected, $version ) { 00118 $normalizer = new ComposerVersionNormalizer(); 00119 00120 $this->assertEquals( 00121 $expected, 00122 $normalizer->normalizeLevelCount( $version ) 00123 ); 00124 } 00125 00126 public function levelNormalizationProvider() { 00127 return array( 00128 array( '1.22.0.0', '1.22' ), 00129 array( '1.22.0.0', '1.22.0' ), 00130 array( '1.19.2.0', '1.19.2' ), 00131 array( '12345.0.0.0', '12345' ), 00132 array( '12345.0.0.0-RC4', '12345-RC4' ), 00133 array( '12345.0.0.0-alpha', '12345-alpha' ), 00134 ); 00135 } 00136 00140 public function testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion ) { 00141 $this->assertRemainsUnchanged( $invalidVersion ); 00142 } 00143 00144 public function invalidVersionProvider() { 00145 return array( 00146 array( '1.221-a' ), 00147 array( '1.221-' ), 00148 array( '1.22rc4a' ), 00149 array( 'a1.22rc' ), 00150 array( '.1.22rc' ), 00151 array( 'a' ), 00152 array( 'alpha42' ), 00153 ); 00154 } 00155 }