MediaWiki  1.28.0
ComposerVersionNormalizerTest.php
Go to the documentation of this file.
1 <?php
2 
10 class ComposerVersionNormalizerTest extends PHPUnit_Framework_TestCase {
11 
16  $normalizer = new ComposerVersionNormalizer();
17 
18  $this->setExpectedException( 'InvalidArgumentException' );
19  $normalizer->normalizeSuffix( $nonString );
20  }
21 
22  public function nonStringProvider() {
23  return [
24  [ null ],
25  [ 42 ],
26  [ [] ],
27  [ new stdClass() ],
28  [ true ],
29  ];
30  }
31 
35  public function testGivenSimpleVersion_normalizeSuffixReturnsAsIs( $simpleVersion ) {
36  $this->assertRemainsUnchanged( $simpleVersion );
37  }
38 
39  protected function assertRemainsUnchanged( $version ) {
40  $normalizer = new ComposerVersionNormalizer();
41 
42  $this->assertEquals(
43  $version,
44  $normalizer->normalizeSuffix( $version )
45  );
46  }
47 
48  public function simpleVersionProvider() {
49  return [
50  [ '1.22.0' ],
51  [ '1.19.2' ],
52  [ '1.19.2.0' ],
53  [ '1.9' ],
54  [ '123.321.456.654' ],
55  ];
56  }
57 
62  $withoutDash, $withDash
63  ) {
64  $normalizer = new ComposerVersionNormalizer();
65 
66  $this->assertEquals(
67  $withDash,
68  $normalizer->normalizeSuffix( $withoutDash )
69  );
70  }
71 
72  public function complexVersionProvider() {
73  return [
74  [ '1.22.0alpha', '1.22.0-alpha' ],
75  [ '1.22.0RC', '1.22.0-RC' ],
76  [ '1.19beta', '1.19-beta' ],
77  [ '1.9RC4', '1.9-RC4' ],
78  [ '1.9.1.2RC4', '1.9.1.2-RC4' ],
79  [ '1.9.1.2RC', '1.9.1.2-RC' ],
80  [ '123.321.456.654RC9001', '123.321.456.654-RC9001' ],
81  ];
82  }
83 
88  $withoutDash, $withDash
89  ) {
90  $this->assertRemainsUnchanged( $withDash );
91  }
92 
97  $normalizer = new ComposerVersionNormalizer();
98 
99  $this->assertEquals(
100  $version,
101  $normalizer->normalizeLevelCount( $version )
102  );
103  }
104 
105  public function fourLevelVersionsProvider() {
106  return [
107  [ '1.22.0.0' ],
108  [ '1.19.2.4' ],
109  [ '1.19.2.0' ],
110  [ '1.9.0.1' ],
111  [ '123.321.456.654' ],
112  [ '123.321.456.654RC4' ],
113  [ '123.321.456.654-RC4' ],
114  ];
115  }
116 
121  $expected, $version
122  ) {
123  $normalizer = new ComposerVersionNormalizer();
124 
125  $this->assertEquals(
126  $expected,
127  $normalizer->normalizeLevelCount( $version )
128  );
129  }
130 
131  public function levelNormalizationProvider() {
132  return [
133  [ '1.22.0.0', '1.22' ],
134  [ '1.22.0.0', '1.22.0' ],
135  [ '1.19.2.0', '1.19.2' ],
136  [ '12345.0.0.0', '12345' ],
137  [ '12345.0.0.0-RC4', '12345-RC4' ],
138  [ '12345.0.0.0-alpha', '12345-alpha' ],
139  ];
140  }
141 
145  public function testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion ) {
146  $this->assertRemainsUnchanged( $invalidVersion );
147  }
148 
149  public function invalidVersionProvider() {
150  return [
151  [ '1.221-a' ],
152  [ '1.221-' ],
153  [ '1.22rc4a' ],
154  [ 'a1.22rc' ],
155  [ '.1.22rc' ],
156  [ 'a' ],
157  [ 'alpha42' ],
158  ];
159  }
160 }
testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels($expected, $version)
levelNormalizationProvider
testGivenFourLevels_levelCountNormalizationDoesNothing($version)
fourLevelVersionsProvider
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:1936
testGivenInvalidVersion_normalizeSuffixReturnsAsIs($invalidVersion)
invalidVersionProvider
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
testGivenComplexVersionWithoutDash_normalizeSuffixAddsDash($withoutDash, $withDash)
complexVersionProvider
testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs($withoutDash, $withDash)
complexVersionProvider
testGivenSimpleVersion_normalizeSuffixReturnsAsIs($simpleVersion)
simpleVersionProvider
testGivenNonString_normalizeThrowsInvalidArgumentException($nonString)
nonStringProvider