4 * @covers ComposerVersionNormalizer
8 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
10 class ComposerVersionNormalizerTest
extends PHPUnit\Framework\TestCase
{
12 use MediaWikiCoversValidator
;
13 use PHPUnit4And6Compat
;
16 * @dataProvider nonStringProvider
18 public function testGivenNonString_normalizeThrowsInvalidArgumentException( $nonString ) {
19 $normalizer = new ComposerVersionNormalizer();
21 $this->setExpectedException( InvalidArgumentException
::class );
22 $normalizer->normalizeSuffix( $nonString );
25 public function nonStringProvider() {
36 * @dataProvider simpleVersionProvider
38 public function testGivenSimpleVersion_normalizeSuffixReturnsAsIs( $simpleVersion ) {
39 $this->assertRemainsUnchanged( $simpleVersion );
42 protected function assertRemainsUnchanged( $version ) {
43 $normalizer = new ComposerVersionNormalizer();
47 $normalizer->normalizeSuffix( $version )
51 public function simpleVersionProvider() {
57 [ '123.321.456.654' ],
62 * @dataProvider complexVersionProvider
64 public function testGivenComplexVersionWithoutDash_normalizeSuffixAddsDash(
65 $withoutDash, $withDash
67 $normalizer = new ComposerVersionNormalizer();
71 $normalizer->normalizeSuffix( $withoutDash )
75 public function complexVersionProvider() {
77 [ '1.22.0alpha', '1.22.0-alpha' ],
78 [ '1.22.0RC', '1.22.0-RC' ],
79 [ '1.19beta', '1.19-beta' ],
80 [ '1.9RC4', '1.9-RC4' ],
81 [ '1.9.1.2RC4', '1.9.1.2-RC4' ],
82 [ '1.9.1.2RC', '1.9.1.2-RC' ],
83 [ '123.321.456.654RC9001', '123.321.456.654-RC9001' ],
88 * @dataProvider complexVersionProvider
90 public function testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs(
91 $withoutDash, $withDash
93 $this->assertRemainsUnchanged( $withDash );
97 * @dataProvider fourLevelVersionsProvider
99 public function testGivenFourLevels_levelCountNormalizationDoesNothing( $version ) {
100 $normalizer = new ComposerVersionNormalizer();
104 $normalizer->normalizeLevelCount( $version )
108 public function fourLevelVersionsProvider() {
114 [ '123.321.456.654' ],
115 [ '123.321.456.654RC4' ],
116 [ '123.321.456.654-RC4' ],
121 * @dataProvider levelNormalizationProvider
123 public function testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels(
126 $normalizer = new ComposerVersionNormalizer();
130 $normalizer->normalizeLevelCount( $version )
134 public function levelNormalizationProvider() {
136 [ '1.22.0.0', '1.22' ],
137 [ '1.22.0.0', '1.22.0' ],
138 [ '1.19.2.0', '1.19.2' ],
139 [ '12345.0.0.0', '12345' ],
140 [ '12345.0.0.0-RC4', '12345-RC4' ],
141 [ '12345.0.0.0-alpha', '12345-alpha' ],
146 * @dataProvider invalidVersionProvider
148 public function testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion ) {
149 $this->assertRemainsUnchanged( $invalidVersion );
152 public function invalidVersionProvider() {