4 * @covers ComposerVersionNormalizer
8 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
10 class ComposerVersionNormalizerTest
extends PHPUnit_Framework_TestCase
{
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() {
27 array( new stdClass() ),
33 * @dataProvider simpleVersionProvider
35 public function testGivenSimpleVersion_normalizeSuffixReturnsAsIs( $simpleVersion ) {
36 $this->assertRemainsUnchanged( $simpleVersion );
39 protected function assertRemainsUnchanged( $version ) {
40 $normalizer = new ComposerVersionNormalizer();
44 $normalizer->normalizeSuffix( $version )
48 public function simpleVersionProvider() {
54 array( '123.321.456.654' ),
59 * @dataProvider complexVersionProvider
61 public function testGivenComplexVersionWithoutDash_normalizeSuffixAddsDash(
62 $withoutDash, $withDash
64 $normalizer = new ComposerVersionNormalizer();
68 $normalizer->normalizeSuffix( $withoutDash )
72 public function complexVersionProvider() {
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' ),
85 * @dataProvider complexVersionProvider
87 public function testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs(
88 $withoutDash, $withDash
90 $this->assertRemainsUnchanged( $withDash );
94 * @dataProvider fourLevelVersionsProvider
96 public function testGivenFourLevels_levelCountNormalizationDoesNothing( $version ) {
97 $normalizer = new ComposerVersionNormalizer();
101 $normalizer->normalizeLevelCount( $version )
105 public function fourLevelVersionsProvider() {
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(
123 $normalizer = new ComposerVersionNormalizer();
127 $normalizer->normalizeLevelCount( $version )
131 public function levelNormalizationProvider() {
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() {