4 * @covers VersionChecker
6 class VersionCheckerTest
extends MediaWikiUnitTestCase
{
9 * @dataProvider provideMediaWikiCheck
11 public function testMediaWikiCheck( $coreVersion, $constraint, $expected ) {
12 $checker = new VersionChecker( $coreVersion, '7.0.0', [] );
13 $this->assertEquals( $expected, !(bool)$checker->checkArray( [
15 'MediaWiki' => $constraint,
20 public static function provideMediaWikiCheck() {
22 // [ $wgVersion, constraint, expected ]
23 [ '1.25alpha', '>= 1.26', false ],
24 [ '1.25.0', '>= 1.26', false ],
25 [ '1.26alpha', '>= 1.26', true ],
26 [ '1.26alpha', '>= 1.26.0', true ],
27 [ '1.26alpha', '>= 1.26.0-stable', false ],
28 [ '1.26.0', '>= 1.26.0-stable', true ],
29 [ '1.26.1', '>= 1.26.0-stable', true ],
30 [ '1.27.1', '>= 1.26.0-stable', true ],
31 [ '1.26alpha', '>= 1.26.1', false ],
32 [ '1.26alpha', '>= 1.26alpha', true ],
33 [ '1.26alpha', '>= 1.25', true ],
34 [ '1.26.0-alpha.14', '>= 1.26.0-alpha.15', false ],
35 [ '1.26.0-alpha.14', '>= 1.26.0-alpha.10', true ],
36 [ '1.26.1', '>= 1.26.2, <=1.26.0', false ],
37 [ '1.26.1', '^1.26.2', false ],
38 // Accept anything for un-parsable version strings
39 [ '1.26mwf14', '== 1.25alpha', true ],
40 [ 'totallyinvalid', '== 1.0', true ],
45 * @dataProvider providePhpValidCheck
47 public function testPhpValidCheck( $phpVersion, $constraint, $expected ) {
48 $checker = new VersionChecker( '1.0.0', $phpVersion, [] );
49 $this->assertEquals( $expected, !(bool)$checker->checkArray( [
58 public static function providePhpValidCheck() {
60 // [ phpVersion, constraint, expected ]
61 [ '7.0.23', '>= 7.0.0', true ],
62 [ '7.0.23', '^7.1.0', false ],
63 [ '7.0.23', '7.0.23', true ],
68 * @expectedException UnexpectedValueException
70 public function testPhpInvalidConstraint() {
71 $checker = new VersionChecker( '1.0.0', '7.0.0', [] );
72 $checker->checkArray( [
75 'php' => 'totallyinvalid',
82 * @dataProvider providePhpInvalidVersion
83 * @expectedException UnexpectedValueException
85 public function testPhpInvalidVersion( $phpVersion ) {
86 $checker = new VersionChecker( '1.0.0', $phpVersion, [] );
89 public static function providePhpInvalidVersion() {
98 * @dataProvider provideType
100 public function testType( $given, $expected ) {
101 $checker = new VersionChecker(
104 [ 'phpLoadedExtension' ],
106 'presentAbility' => true,
107 'presentAbilityWithMessage' => true,
108 'missingAbility' => false,
109 'missingAbilityWithMessage' => false,
112 'presentAbilityWithMessage' => 'Present.',
113 'missingAbilityWithMessage' => 'Missing.',
116 $checker->setLoadedExtensionsAndSkins( [
117 'FakeDependency' => [
118 'version' => '1.0.0',
120 'NoVersionGiven' => [],
122 $this->assertEquals( $expected, $checker->checkArray( [
123 'FakeExtension' => $given,
127 public static function provideType() {
133 'FakeDependency' => '1.0.0',
140 'MediaWiki' => '1.0.0',
147 'NoVersionGiven' => '*',
155 'NoVersionGiven' => '1.0',
160 'incompatible' => 'FakeExtension',
161 'type' => 'incompatible-extensions',
162 'msg' => 'NoVersionGiven does not expose its version, but FakeExtension requires: 1.0.',
174 'missing' => 'Missing',
175 'type' => 'missing-extensions',
176 'msg' => 'FakeExtension requires Missing to be installed.',
183 'FakeDependency' => '2.0.0',
188 'incompatible' => 'FakeExtension',
189 'type' => 'incompatible-extensions',
190 // phpcs:ignore Generic.Files.LineLength.TooLong
191 'msg' => 'FakeExtension is not compatible with the current installed version of FakeDependency (1.0.0), it requires: 2.0.0.',
203 'missing' => 'FakeSkin',
204 'type' => 'missing-skins',
205 'msg' => 'FakeExtension requires FakeSkin to be installed.',
212 'ext-phpLoadedExtension' => '*',
220 'ext-phpMissingExtension' => '*',
225 'missing' => 'phpMissingExtension',
226 'type' => 'missing-phpExtension',
227 // phpcs:ignore Generic.Files.LineLength.TooLong
228 'msg' => 'FakeExtension requires phpMissingExtension PHP extension to be installed.',
235 'ability-presentAbility' => true,
243 'ability-presentAbilityWithMessage' => true,
251 'ability-presentAbility' => false,
259 'ability-presentAbilityWithMessage' => false,
267 'ability-missingAbility' => true,
272 'missing' => 'missingAbility',
273 'type' => 'missing-ability',
274 'msg' => 'FakeExtension requires "missingAbility" ability',
281 'ability-missingAbilityWithMessage' => true,
286 'missing' => 'missingAbilityWithMessage',
287 'type' => 'missing-ability',
288 // phpcs:ignore Generic.Files.LineLength.TooLong
289 'msg' => 'FakeExtension requires "missingAbilityWithMessage" ability: Missing.',
296 'ability-missingAbility' => false,
304 'ability-missingAbilityWithMessage' => false,
313 * Check, if a non-parsable version constraint does not throw an exception or
314 * returns any error message.
316 public function testInvalidConstraint() {
317 $checker = new VersionChecker( '1.0.0', '7.0.0', [] );
318 $checker->setLoadedExtensionsAndSkins( [
319 'FakeDependency' => [
320 'version' => 'not really valid',
323 $this->assertEquals( [
325 'type' => 'invalid-version',
326 'msg' => "FakeDependency does not have a valid version string.",
328 ], $checker->checkArray( [
331 'FakeDependency' => '1.24.3',
336 $checker = new VersionChecker( '1.0.0', '7.0.0', [] );
337 $checker->setLoadedExtensionsAndSkins( [
338 'FakeDependency' => [
339 'version' => '1.24.3',
343 $this->setExpectedException( UnexpectedValueException
::class );
344 $checker->checkArray( [
346 'FakeDependency' => 'not really valid',
351 public function provideInvalidDependency() {
357 'undefinedPlatformDependency' => '*',
361 'undefinedPlatformDependency',
367 'phpLoadedExtension' => '*',
371 'phpLoadedExtension',
377 'ability-invalidAbility' => true,
381 'ability-invalidAbility',
387 'presentAbility' => true,
396 'undefinedDependencyType' => '*',
399 'undefinedDependencyType',
416 * @dataProvider provideInvalidDependency
418 public function testInvalidDependency( $depencency, $type ) {
419 $checker = new VersionChecker(
422 [ 'phpLoadedExtension' ],
424 'presentAbility' => true,
425 'missingAbility' => false,
428 $this->setExpectedException(
429 UnexpectedValueException
::class,
430 "Dependency type $type unknown in FakeExtension"
432 $checker->checkArray( $depencency );
435 public function testInvalidPhpExtensionConstraint() {
436 $checker = new VersionChecker( '1.0.0', '7.0.0', [ 'phpLoadedExtension' ] );
437 $this->setExpectedException(
438 UnexpectedValueException
::class,
439 'Version constraints for PHP extensions are not supported in FakeExtension'
441 $checker->checkArray( [
444 'ext-phpLoadedExtension' => '1.0.0',
451 * @dataProvider provideInvalidAbilityType
453 public function testInvalidAbilityType( $value ) {
454 $checker = new VersionChecker( '1.0.0', '7.0.0', [], [ 'presentAbility' => true ] );
455 $this->setExpectedException(
456 UnexpectedValueException
::class,
457 'Only booleans are allowed to to indicate the presence of abilities in FakeExtension'
459 $checker->checkArray( [
462 'ability-presentAbility' => $value,
468 public function provideInvalidAbilityType() {