4 * @covers ComposerVersionNormalizer
8 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
10 class ComposerVersionNormalizerTest
extends PHPUnit_Framework_TestCase
{
12 use MediaWikiCoversValidator
;
15 * @dataProvider nonStringProvider
17 public function testGivenNonString_normalizeThrowsInvalidArgumentException( $nonString ) {
18 $normalizer = new ComposerVersionNormalizer();
20 $this->setExpectedException( 'InvalidArgumentException' );
21 $normalizer->normalizeSuffix( $nonString );
24 public function nonStringProvider() {
35 * @dataProvider simpleVersionProvider
37 public function testGivenSimpleVersion_normalizeSuffixReturnsAsIs( $simpleVersion ) {
38 $this->assertRemainsUnchanged( $simpleVersion );
41 protected function assertRemainsUnchanged( $version ) {
42 $normalizer = new ComposerVersionNormalizer();
46 $normalizer->normalizeSuffix( $version )
50 public function simpleVersionProvider() {
56 [ '123.321.456.654' ],
61 * @dataProvider complexVersionProvider
63 public function testGivenComplexVersionWithoutDash_normalizeSuffixAddsDash(
64 $withoutDash, $withDash
66 $normalizer = new ComposerVersionNormalizer();
70 $normalizer->normalizeSuffix( $withoutDash )
74 public function complexVersionProvider() {
76 [ '1.22.0alpha', '1.22.0-alpha' ],
77 [ '1.22.0RC', '1.22.0-RC' ],
78 [ '1.19beta', '1.19-beta' ],
79 [ '1.9RC4', '1.9-RC4' ],
80 [ '1.9.1.2RC4', '1.9.1.2-RC4' ],
81 [ '1.9.1.2RC', '1.9.1.2-RC' ],
82 [ '123.321.456.654RC9001', '123.321.456.654-RC9001' ],
87 * @dataProvider complexVersionProvider
89 public function testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs(
90 $withoutDash, $withDash
92 $this->assertRemainsUnchanged( $withDash );
96 * @dataProvider fourLevelVersionsProvider
98 public function testGivenFourLevels_levelCountNormalizationDoesNothing( $version ) {
99 $normalizer = new ComposerVersionNormalizer();
103 $normalizer->normalizeLevelCount( $version )
107 public function fourLevelVersionsProvider() {
113 [ '123.321.456.654' ],
114 [ '123.321.456.654RC4' ],
115 [ '123.321.456.654-RC4' ],
120 * @dataProvider levelNormalizationProvider
122 public function testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels(
125 $normalizer = new ComposerVersionNormalizer();
129 $normalizer->normalizeLevelCount( $version )
133 public function levelNormalizationProvider() {
135 [ '1.22.0.0', '1.22' ],
136 [ '1.22.0.0', '1.22.0' ],
137 [ '1.19.2.0', '1.19.2' ],
138 [ '12345.0.0.0', '12345' ],
139 [ '12345.0.0.0-RC4', '12345-RC4' ],
140 [ '12345.0.0.0-alpha', '12345-alpha' ],
145 * @dataProvider invalidVersionProvider
147 public function testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion ) {
148 $this->assertRemainsUnchanged( $invalidVersion );
151 public function invalidVersionProvider() {