MediaWiki  1.29.2
VersionCheckerTest.php
Go to the documentation of this file.
1 <?php
2 
6 class VersionCheckerTest extends PHPUnit_Framework_TestCase {
10  public function testCheck( $coreVersion, $constraint, $expected ) {
11  $checker = new VersionChecker( $coreVersion );
12  $this->assertEquals( $expected, !(bool)$checker->checkArray( [
13  'FakeExtension' => [
14  'MediaWiki' => $constraint,
15  ],
16  ] )
17  );
18  }
19 
20  public static function provideCheck() {
21  return [
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 ],
41  ];
42  }
43 
47  public function testType( $given, $expected ) {
48  $checker = new VersionChecker( '1.0.0' );
49  $checker
50  ->setLoadedExtensionsAndSkins( [
51  'FakeDependency' => [
52  'version' => '1.0.0',
53  ],
54  ] );
55  $this->assertEquals( $expected, $checker->checkArray( [
56  'FakeExtension' => $given,
57  ] )
58  );
59  }
60 
61  public static function provideType() {
62  return [
63  // valid type
64  [
65  [
66  'extensions' => [
67  'FakeDependency' => '1.0.0'
68  ]
69  ],
70  []
71  ],
72  [
73  [
74  'MediaWiki' => '1.0.0'
75  ],
76  []
77  ],
78  ];
79  }
80 
85  public function testInvalidConstraint() {
86  $checker = new VersionChecker( '1.0.0' );
87  $checker
88  ->setLoadedExtensionsAndSkins( [
89  'FakeDependency' => [
90  'version' => 'not really valid',
91  ],
92  ] );
93  $this->assertEquals( [ "FakeDependency does not have a valid version string." ],
94  $checker->checkArray( [
95  'FakeExtension' => [
96  'extensions' => [
97  'FakeDependency' => '1.24.3',
98  ],
99  ],
100  ] )
101  );
102 
103  $checker = new VersionChecker( '1.0.0' );
104  $checker
105  ->setLoadedExtensionsAndSkins( [
106  'FakeDependency' => [
107  'version' => '1.24.3',
108  ],
109  ] );
110 
111  $this->setExpectedException( 'UnexpectedValueException' );
112  $checker->checkArray( [
113  'FakeExtension' => [
114  'FakeDependency' => 'not really valid',
115  ]
116  ] );
117  }
118 }
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
VersionCheckerTest\testCheck
testCheck( $coreVersion, $constraint, $expected)
provideCheck
Definition: VersionCheckerTest.php:10
VersionCheckerTest\testType
testType( $given, $expected)
provideType
Definition: VersionCheckerTest.php:47
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:61
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:1956
VersionCheckerTest\testInvalidConstraint
testInvalidConstraint()
Check, if a non-parsable version constraint does not throw an exception or returns any error message.
Definition: VersionCheckerTest.php:85
VersionCheckerTest\provideCheck
static provideCheck()
Definition: VersionCheckerTest.php:20