4 * @covers VersionChecker
6 class VersionCheckerTest
extends PHPUnit\Framework\TestCase
{
8 use MediaWikiCoversValidator
;
9 use PHPUnit4And6Compat
;
12 * @dataProvider provideCheck
14 public function testCheck( $coreVersion, $constraint, $expected ) {
15 $checker = new VersionChecker( $coreVersion );
16 $this->assertEquals( $expected, !(bool)$checker->checkArray( [
18 'MediaWiki' => $constraint,
24 public static function provideCheck() {
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 ],
49 * @dataProvider provideType
51 public function testType( $given, $expected ) {
52 $checker = new VersionChecker( '1.0.0' );
54 ->setLoadedExtensionsAndSkins( [
58 'NoVersionGiven' => [],
60 $this->assertEquals( $expected, $checker->checkArray( [
61 'FakeExtension' => $given,
66 public static function provideType() {
72 'FakeDependency' => '1.0.0'
79 'MediaWiki' => '1.0.0'
86 'NoVersionGiven' => '*'
94 'NoVersionGiven' => '1.0',
97 [ 'NoVersionGiven does not expose its version, but FakeExtension requires: 1.0.' ],
105 [ 'FakeExtension requires Missing to be installed.' ],
110 'FakeDependency' => '2.0.0',
113 // phpcs:ignore Generic.Files.LineLength.TooLong
114 [ 'FakeExtension is not compatible with the current installed version of FakeDependency (1.0.0), it requires: 2.0.0.' ],
120 * Check, if a non-parsable version constraint does not throw an exception or
121 * returns any error message.
123 public function testInvalidConstraint() {
124 $checker = new VersionChecker( '1.0.0' );
126 ->setLoadedExtensionsAndSkins( [
127 'FakeDependency' => [
128 'version' => 'not really valid',
131 $this->assertEquals( [ "FakeDependency does not have a valid version string." ],
132 $checker->checkArray( [
135 'FakeDependency' => '1.24.3',
141 $checker = new VersionChecker( '1.0.0' );
143 ->setLoadedExtensionsAndSkins( [
144 'FakeDependency' => [
145 'version' => '1.24.3',
149 $this->setExpectedException( UnexpectedValueException
::class );
150 $checker->checkArray( [
152 'FakeDependency' => 'not really valid',