MediaWiki  REL1_24
ComposerVersionNormalizerTest.php
Go to the documentation of this file.
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(
00063         $withoutDash, $withDash
00064     ) {
00065         $normalizer = new ComposerVersionNormalizer();
00066 
00067         $this->assertEquals(
00068             $withDash,
00069             $normalizer->normalizeSuffix( $withoutDash )
00070         );
00071     }
00072 
00073     public function complexVersionProvider() {
00074         return array(
00075             array( '1.22.0alpha', '1.22.0-alpha' ),
00076             array( '1.22.0RC', '1.22.0-RC' ),
00077             array( '1.19beta', '1.19-beta' ),
00078             array( '1.9RC4', '1.9-RC4' ),
00079             array( '1.9.1.2RC4', '1.9.1.2-RC4' ),
00080             array( '1.9.1.2RC', '1.9.1.2-RC' ),
00081             array( '123.321.456.654RC9001', '123.321.456.654-RC9001' ),
00082         );
00083     }
00084 
00088     public function testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs(
00089         $withoutDash, $withDash
00090     ) {
00091         $this->assertRemainsUnchanged( $withDash );
00092     }
00093 
00097     public function testGivenFourLevels_levelCountNormalizationDoesNothing( $version ) {
00098         $normalizer = new ComposerVersionNormalizer();
00099 
00100         $this->assertEquals(
00101             $version,
00102             $normalizer->normalizeLevelCount( $version )
00103         );
00104     }
00105 
00106     public function fourLevelVersionsProvider() {
00107         return array(
00108             array( '1.22.0.0' ),
00109             array( '1.19.2.4' ),
00110             array( '1.19.2.0' ),
00111             array( '1.9.0.1' ),
00112             array( '123.321.456.654' ),
00113             array( '123.321.456.654RC4' ),
00114             array( '123.321.456.654-RC4' ),
00115         );
00116     }
00117 
00121     public function testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels(
00122         $expected, $version
00123     ) {
00124         $normalizer = new ComposerVersionNormalizer();
00125 
00126         $this->assertEquals(
00127             $expected,
00128             $normalizer->normalizeLevelCount( $version )
00129         );
00130     }
00131 
00132     public function levelNormalizationProvider() {
00133         return array(
00134             array( '1.22.0.0', '1.22' ),
00135             array( '1.22.0.0', '1.22.0' ),
00136             array( '1.19.2.0', '1.19.2' ),
00137             array( '12345.0.0.0', '12345' ),
00138             array( '12345.0.0.0-RC4', '12345-RC4' ),
00139             array( '12345.0.0.0-alpha', '12345-alpha' ),
00140         );
00141     }
00142 
00146     public function testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion ) {
00147         $this->assertRemainsUnchanged( $invalidVersion );
00148     }
00149 
00150     public function invalidVersionProvider() {
00151         return array(
00152             array( '1.221-a' ),
00153             array( '1.221-' ),
00154             array( '1.22rc4a' ),
00155             array( 'a1.22rc' ),
00156             array( '.1.22rc' ),
00157             array( 'a' ),
00158             array( 'alpha42' ),
00159         );
00160     }
00161 }