MediaWiki  1.31.0
VersionCheckerTest.php
Go to the documentation of this file.
1 <?php
2 
6 class VersionCheckerTest extends PHPUnit\Framework\TestCase {
7 
8  use MediaWikiCoversValidator;
9  use PHPUnit4And6Compat;
10 
14  public function testCheck( $coreVersion, $constraint, $expected ) {
15  $checker = new VersionChecker( $coreVersion );
16  $this->assertEquals( $expected, !(bool)$checker->checkArray( [
17  'FakeExtension' => [
18  'MediaWiki' => $constraint,
19  ],
20  ] )
21  );
22  }
23 
24  public static function provideCheck() {
25  return [
26  // [ $wgVersion, constraint, expected ]
27  [ '1.25alpha', '>= 1.26', false ],
28  [ '1.25.0', '>= 1.26', false ],
29  [ '1.26alpha', '>= 1.26', true ],
30  [ '1.26alpha', '>= 1.26.0', true ],
31  [ '1.26alpha', '>= 1.26.0-stable', false ],
32  [ '1.26.0', '>= 1.26.0-stable', true ],
33  [ '1.26.1', '>= 1.26.0-stable', true ],
34  [ '1.27.1', '>= 1.26.0-stable', true ],
35  [ '1.26alpha', '>= 1.26.1', false ],
36  [ '1.26alpha', '>= 1.26alpha', true ],
37  [ '1.26alpha', '>= 1.25', true ],
38  [ '1.26.0-alpha.14', '>= 1.26.0-alpha.15', false ],
39  [ '1.26.0-alpha.14', '>= 1.26.0-alpha.10', true ],
40  [ '1.26.1', '>= 1.26.2, <=1.26.0', false ],
41  [ '1.26.1', '^1.26.2', false ],
42  // Accept anything for un-parsable version strings
43  [ '1.26mwf14', '== 1.25alpha', true ],
44  [ 'totallyinvalid', '== 1.0', true ],
45  ];
46  }
47 
51  public function testType( $given, $expected ) {
52  $checker = new VersionChecker( '1.0.0' );
53  $checker
54  ->setLoadedExtensionsAndSkins( [
55  'FakeDependency' => [
56  'version' => '1.0.0',
57  ],
58  'NoVersionGiven' => [],
59  ] );
60  $this->assertEquals( $expected, $checker->checkArray( [
61  'FakeExtension' => $given,
62  ] )
63  );
64  }
65 
66  public static function provideType() {
67  return [
68  // valid type
69  [
70  [
71  'extensions' => [
72  'FakeDependency' => '1.0.0'
73  ]
74  ],
75  []
76  ],
77  [
78  [
79  'MediaWiki' => '1.0.0'
80  ],
81  []
82  ],
83  [
84  [
85  'extensions' => [
86  'NoVersionGiven' => '*'
87  ]
88  ],
89  [],
90  ],
91  [
92  [
93  'extensions' => [
94  'NoVersionGiven' => '1.0',
95  ]
96  ],
97  [ [
98  'incompatible' => 'FakeExtension',
99  'type' => 'incompatible-extensions',
100  'msg' => 'NoVersionGiven does not expose its version, but FakeExtension requires: 1.0.'
101  ] ],
102  ],
103  [
104  [
105  'extensions' => [
106  'Missing' => '*',
107  ]
108  ],
109  [ [
110  'missing' => 'Missing',
111  'type' => 'missing-extensions',
112  'msg' => 'FakeExtension requires Missing to be installed.',
113  ] ],
114  ],
115  [
116  [
117  'extensions' => [
118  'FakeDependency' => '2.0.0',
119  ]
120  ],
121  [ [
122  'incompatible' => 'FakeExtension',
123  'type' => 'incompatible-extensions',
124  // phpcs:ignore Generic.Files.LineLength.TooLong
125  'msg' => 'FakeExtension is not compatible with the current installed version of FakeDependency (1.0.0), it requires: 2.0.0.'
126  ] ],
127  ]
128  ];
129  }
130 
135  public function testInvalidConstraint() {
136  $checker = new VersionChecker( '1.0.0' );
137  $checker
138  ->setLoadedExtensionsAndSkins( [
139  'FakeDependency' => [
140  'version' => 'not really valid',
141  ],
142  ] );
143  $this->assertEquals(
144  [ [
145  'type' => 'invalid-version',
146  'msg' => "FakeDependency does not have a valid version string."
147  ] ],
148  $checker->checkArray( [
149  'FakeExtension' => [
150  'extensions' => [
151  'FakeDependency' => '1.24.3',
152  ],
153  ],
154  ] )
155  );
156 
157  $checker = new VersionChecker( '1.0.0' );
158  $checker
159  ->setLoadedExtensionsAndSkins( [
160  'FakeDependency' => [
161  'version' => '1.24.3',
162  ],
163  ] );
164 
165  $this->setExpectedException( UnexpectedValueException::class );
166  $checker->checkArray( [
167  'FakeExtension' => [
168  'FakeDependency' => 'not really valid',
169  ]
170  ] );
171  }
172 }
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
VersionCheckerTest\testCheck
testCheck( $coreVersion, $constraint, $expected)
provideCheck
Definition: VersionCheckerTest.php:14
VersionCheckerTest\testType
testType( $given, $expected)
provideType
Definition: VersionCheckerTest.php:51
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
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
VersionCheckerTest\provideType
static provideType()
Definition: VersionCheckerTest.php:66
VersionCheckerTest
VersionChecker.
Definition: VersionCheckerTest.php:6
VersionChecker
Provides functions to check a set of extensions with dependencies against a set of loaded extensions ...
Definition: VersionChecker.php:32
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:1987
VersionCheckerTest\testInvalidConstraint
testInvalidConstraint()
Check, if a non-parsable version constraint does not throw an exception or returns any error message.
Definition: VersionCheckerTest.php:135
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
VersionCheckerTest\provideCheck
static provideCheck()
Definition: VersionCheckerTest.php:24