MediaWiki REL1_31
ComposerVersionNormalizerTest.php
Go to the documentation of this file.
1<?php
2
10class 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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
testGivenInvalidVersion_normalizeSuffixReturnsAsIs( $invalidVersion)
invalidVersionProvider
testGivenComplexVersionWithoutDash_normalizeSuffixAddsDash( $withoutDash, $withDash)
complexVersionProvider
testGivenSimpleVersion_normalizeSuffixReturnsAsIs( $simpleVersion)
simpleVersionProvider
testGivenFewerLevels_levelCountNormalizationEnsuresFourLevels( $expected, $version)
levelNormalizationProvider
testGivenNonString_normalizeThrowsInvalidArgumentException( $nonString)
nonStringProvider
testGivenFourLevels_levelCountNormalizationDoesNothing( $version)
fourLevelVersionsProvider
testGivenComplexVersionWithDash_normalizeSuffixReturnsAsIs( $withoutDash, $withDash)
complexVersionProvider
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:2006
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:37