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(
63 $withoutDash, $withDash
65 $normalizer = new ComposerVersionNormalizer();
69 $normalizer->normalizeSuffix( $withoutDash )
73 public function complexVersionProvider() {
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' ),
86 * @dataProvider complexVersionProvider
88 public function testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs(
89 $withoutDash, $withDash
91 $this->assertRemainsUnchanged( $withDash );
95 * @dataProvider fourLevelVersionsProvider
97 public function testGivenFourLevels_levelCountNormalizationDoesNothing( $version ) {
98 $normalizer = new ComposerVersionNormalizer();
102 $normalizer->normalizeLevelCount( $version )
106 public function fourLevelVersionsProvider() {
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(
124 $normalizer = new ComposerVersionNormalizer();
128 $normalizer->normalizeLevelCount( $version )
132 public function levelNormalizationProvider() {
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() {