MediaWiki  1.32.5
ComposerVersionNormalizerTest.php
Go to the documentation of this file.
1 <?php
2 
10 class ComposerVersionNormalizerTest extends PHPUnit\Framework\TestCase {
11 
12  use MediaWikiCoversValidator;
13  use PHPUnit4And6Compat;
14 
19  $normalizer = new ComposerVersionNormalizer();
20 
21  $this->setExpectedException( InvalidArgumentException::class );
22  $normalizer->normalizeSuffix( $nonString );
23  }
24 
25  public function nonStringProvider() {
26  return [
27  [ null ],
28  [ 42 ],
29  [ [] ],
30  [ new stdClass() ],
31  [ true ],
32  ];
33  }
34 
38  public function testGivenSimpleVersion_normalizeSuffixReturnsAsIs( $simpleVersion ) {
39  $this->assertRemainsUnchanged( $simpleVersion );
40  }
41 
42  protected function assertRemainsUnchanged( $version ) {
43  $normalizer = new ComposerVersionNormalizer();
44 
45  $this->assertEquals(
46  $version,
47  $normalizer->normalizeSuffix( $version )
48  );
49  }
50 
51  public function simpleVersionProvider() {
52  return [
53  [ '1.22.0' ],
54  [ '1.19.2' ],
55  [ '1.19.2.0' ],
56  [ '1.9' ],
57  [ '123.321.456.654' ],
58  ];
59  }
60 
65  $withoutDash, $withDash
66  ) {
67  $normalizer = new ComposerVersionNormalizer();
68 
69  $this->assertEquals(
70  $withDash,
71  $normalizer->normalizeSuffix( $withoutDash )
72  );
73  }
74 
75  public function complexVersionProvider() {
76  return [
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' ],
84  ];
85  }
86 
91  $withoutDash, $withDash
92  ) {
93  $this->assertRemainsUnchanged( $withDash );
94  }
95 
100  $normalizer = new ComposerVersionNormalizer();
101 
102  $this->assertEquals(
103  $version,
104  $normalizer->normalizeLevelCount( $version )
105  );
106  }
107 
108  public function fourLevelVersionsProvider() {
109  return [
110  [ '1.22.0.0' ],
111  [ '1.19.2.4' ],
112  [ '1.19.2.0' ],
113  [ '1.9.0.1' ],
114  [ '123.321.456.654' ],
115  [ '123.321.456.654RC4' ],
116  [ '123.321.456.654-RC4' ],
117  ];
118  }
119 
124  $expected, $version
125  ) {
126  $normalizer = new ComposerVersionNormalizer();
127 
128  $this->assertEquals(
129  $expected,
130  $normalizer->normalizeLevelCount( $version )
131  );
132  }
133 
134  public function levelNormalizationProvider() {
135  return [
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' ],
142  ];
143  }
144 
148  public function testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion ) {
149  $this->assertRemainsUnchanged( $invalidVersion );
150  }
151 
152  public function invalidVersionProvider() {
153  return [
154  [ '1.221-a' ],
155  [ '1.221-' ],
156  [ '1.22rc4a' ],
157  [ 'a1.22rc' ],
158  [ '.1.22rc' ],
159  [ 'a' ],
160  [ 'alpha42' ],
161  ];
162  }
163 }
ComposerVersionNormalizerTest\simpleVersionProvider
simpleVersionProvider()
Definition: ComposerVersionNormalizerTest.php:51
ComposerVersionNormalizerTest\assertRemainsUnchanged
assertRemainsUnchanged( $version)
Definition: ComposerVersionNormalizerTest.php:42
ComposerVersionNormalizerTest\testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs
testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs( $withoutDash, $withDash)
complexVersionProvider
Definition: ComposerVersionNormalizerTest.php:90
ComposerVersionNormalizerTest\testGivenFourLevels_levelCountNormalizationDoesNothing
testGivenFourLevels_levelCountNormalizationDoesNothing( $version)
fourLevelVersionsProvider
Definition: ComposerVersionNormalizerTest.php:99
ComposerVersionNormalizerTest\testGivenComplexVersionWithoutDash_normalizeSuffixAddsDash
testGivenComplexVersionWithoutDash_normalizeSuffixAddsDash( $withoutDash, $withDash)
complexVersionProvider
Definition: ComposerVersionNormalizerTest.php:64
ComposerVersionNormalizerTest\testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels
testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels( $expected, $version)
levelNormalizationProvider
Definition: ComposerVersionNormalizerTest.php:123
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ComposerVersionNormalizerTest\nonStringProvider
nonStringProvider()
Definition: ComposerVersionNormalizerTest.php:25
ComposerVersionNormalizerTest\testGivenSimpleVersion_normalizeSuffixReturnsAsIs
testGivenSimpleVersion_normalizeSuffixReturnsAsIs( $simpleVersion)
simpleVersionProvider
Definition: ComposerVersionNormalizerTest.php:38
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ComposerVersionNormalizerTest\complexVersionProvider
complexVersionProvider()
Definition: ComposerVersionNormalizerTest.php:75
ComposerVersionNormalizerTest\fourLevelVersionsProvider
fourLevelVersionsProvider()
Definition: ComposerVersionNormalizerTest.php:108
ComposerVersionNormalizerTest\testGivenNonString_normalizeThrowsInvalidArgumentException
testGivenNonString_normalizeThrowsInvalidArgumentException( $nonString)
nonStringProvider
Definition: ComposerVersionNormalizerTest.php:18
ComposerVersionNormalizerTest
ComposerVersionNormalizer.
Definition: ComposerVersionNormalizerTest.php:10
ComposerVersionNormalizerTest\testGivenInvalidVersion_normalizeSuffixReturnsAsIs
testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion)
invalidVersionProvider
Definition: ComposerVersionNormalizerTest.php:148
ComposerVersionNormalizerTest\levelNormalizationProvider
levelNormalizationProvider()
Definition: ComposerVersionNormalizerTest.php:134
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:2044
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
ComposerVersionNormalizerTest\invalidVersionProvider
invalidVersionProvider()
Definition: ComposerVersionNormalizerTest.php:152
ComposerVersionNormalizer
Definition: ComposerVersionNormalizer.php:7