4 * @covers ComposerVersionNormalizer
9 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
11 class ComposerVersionNormalizerTest
extends PHPUnit_Framework_TestCase
{
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() {
28 array( new stdClass() ),
34 * @dataProvider simpleVersionProvider
36 public function testGivenSimpleVersion_normalizeSuffixReturnsAsIs( $simpleVersion ) {
37 $this->assertRemainsUnchanged( $simpleVersion );
40 protected function assertRemainsUnchanged( $version ) {
41 $normalizer = new ComposerVersionNormalizer();
45 $normalizer->normalizeSuffix( $version )
49 public function simpleVersionProvider() {
55 array( '123.321.456.654' ),
60 * @dataProvider complexVersionProvider
62 public function testGivenComplexVersionWithoutDash_normalizeSuffixAddsDash( $withoutDash, $withDash ) {
63 $normalizer = new ComposerVersionNormalizer();
67 $normalizer->normalizeSuffix( $withoutDash )
71 public function complexVersionProvider() {
73 array( '1.22.0alpha', '1.22.0-alpha' ),
74 array( '1.22.0RC', '1.22.0-RC' ),
75 array( '1.19beta', '1.19-beta' ),
76 array( '1.9RC4', '1.9-RC4' ),
77 array( '1.9.1.2RC4', '1.9.1.2-RC4' ),
78 array( '1.9.1.2RC', '1.9.1.2-RC' ),
79 array( '123.321.456.654RC9001', '123.321.456.654-RC9001' ),
84 * @dataProvider complexVersionProvider
86 public function testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs( $withoutDash, $withDash ) {
87 $this->assertRemainsUnchanged( $withDash );
91 * @dataProvider fourLevelVersionsProvider
93 public function testGivenFourLevels_levelCountNormalizationDoesNothing( $version ) {
94 $normalizer = new ComposerVersionNormalizer();
98 $normalizer->normalizeLevelCount( $version )
102 public function fourLevelVersionsProvider() {
108 array( '123.321.456.654' ),
109 array( '123.321.456.654RC4' ),
110 array( '123.321.456.654-RC4' ),
115 * @dataProvider levelNormalizationProvider
117 public function testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels( $expected, $version ) {
118 $normalizer = new ComposerVersionNormalizer();
122 $normalizer->normalizeLevelCount( $version )
126 public function levelNormalizationProvider() {
128 array( '1.22.0.0', '1.22' ),
129 array( '1.22.0.0', '1.22.0' ),
130 array( '1.19.2.0', '1.19.2' ),
131 array( '12345.0.0.0', '12345' ),
132 array( '12345.0.0.0-RC4', '12345-RC4' ),
133 array( '12345.0.0.0-alpha', '12345-alpha' ),
138 * @dataProvider invalidVersionProvider
140 public function testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion ) {
141 $this->assertRemainsUnchanged( $invalidVersion );
144 public function invalidVersionProvider() {