use PHPUnit4And6Compat;
/**
- * @dataProvider provideCheck
+ * @dataProvider provideMediaWikiCheck
*/
- public function testCheck( $coreVersion, $constraint, $expected ) {
- $checker = new VersionChecker( $coreVersion );
+ public function testMediaWikiCheck( $coreVersion, $constraint, $expected ) {
+ $checker = new VersionChecker( $coreVersion, '7.0.0', [] );
$this->assertEquals( $expected, !(bool)$checker->checkArray( [
'FakeExtension' => [
'MediaWiki' => $constraint,
] ) );
}
- public static function provideCheck() {
+ public static function provideMediaWikiCheck() {
return [
// [ $wgVersion, constraint, expected ]
[ '1.25alpha', '>= 1.26', false ],
];
}
+ /**
+ * @dataProvider providePhpValidCheck
+ */
+ public function testPhpValidCheck( $phpVersion, $constraint, $expected ) {
+ $checker = new VersionChecker( '1.0.0', $phpVersion, [] );
+ $this->assertEquals( $expected, !(bool)$checker->checkArray( [
+ 'FakeExtension' => [
+ 'platform' => [
+ 'php' => $constraint,
+ ],
+ ],
+ ] ) );
+ }
+
+ public static function providePhpValidCheck() {
+ return [
+ // [ phpVersion, constraint, expected ]
+ [ '7.0.23', '>= 7.0.0', true ],
+ [ '7.0.23', '^7.1.0', false ],
+ [ '7.0.23', '7.0.23', true ],
+ ];
+ }
+
+ /**
+ * @expectedException UnexpectedValueException
+ */
+ public function testPhpInvalidConstraint() {
+ $checker = new VersionChecker( '1.0.0', '7.0.0', [] );
+ $checker->checkArray( [
+ 'FakeExtension' => [
+ 'platform' => [
+ 'php' => 'totallyinvalid',
+ ],
+ ],
+ ] );
+ }
+
+ /**
+ * @dataProvider providePhpInvalidVersion
+ * @expectedException UnexpectedValueException
+ */
+ public function testPhpInvalidVersion( $phpVersion ) {
+ $checker = new VersionChecker( '1.0.0', $phpVersion, [] );
+ }
+
+ public static function providePhpInvalidVersion() {
+ return [
+ // [ phpVersion ]
+ [ '7.abc' ],
+ [ '5.a.x' ],
+ ];
+ }
+
/**
* @dataProvider provideType
*/
public function testType( $given, $expected ) {
- $checker = new VersionChecker( '1.0.0' );
+ $checker = new VersionChecker(
+ '1.0.0',
+ '7.0.0',
+ [ 'phpLoadedExtension' ],
+ [
+ 'presentAbility' => true,
+ 'presentAbilityWithMessage' => true,
+ 'missingAbility' => false,
+ 'missingAbilityWithMessage' => false,
+ ],
+ [
+ 'presentAbilityWithMessage' => 'Present.',
+ 'missingAbilityWithMessage' => 'Missing.',
+ ]
+ );
$checker->setLoadedExtensionsAndSkins( [
'FakeDependency' => [
'version' => '1.0.0',
],
],
],
+ [
+ [
+ 'platform' => [
+ 'ext-phpLoadedExtension' => '*',
+ ],
+ ],
+ [],
+ ],
+ [
+ [
+ 'platform' => [
+ 'ext-phpMissingExtension' => '*',
+ ],
+ ],
+ [
+ [
+ 'missing' => 'phpMissingExtension',
+ 'type' => 'missing-phpExtension',
+ // phpcs:ignore Generic.Files.LineLength.TooLong
+ 'msg' => 'FakeExtension requires phpMissingExtension PHP extension to be installed.',
+ ],
+ ],
+ ],
+ [
+ [
+ 'platform' => [
+ 'ability-presentAbility' => true,
+ ],
+ ],
+ [],
+ ],
+ [
+ [
+ 'platform' => [
+ 'ability-presentAbilityWithMessage' => true,
+ ],
+ ],
+ [],
+ ],
+ [
+ [
+ 'platform' => [
+ 'ability-presentAbility' => false,
+ ],
+ ],
+ [],
+ ],
+ [
+ [
+ 'platform' => [
+ 'ability-presentAbilityWithMessage' => false,
+ ],
+ ],
+ [],
+ ],
+ [
+ [
+ 'platform' => [
+ 'ability-missingAbility' => true,
+ ],
+ ],
+ [
+ [
+ 'missing' => 'missingAbility',
+ 'type' => 'missing-ability',
+ 'msg' => 'FakeExtension requires "missingAbility" ability',
+ ],
+ ],
+ ],
+ [
+ [
+ 'platform' => [
+ 'ability-missingAbilityWithMessage' => true,
+ ],
+ ],
+ [
+ [
+ 'missing' => 'missingAbilityWithMessage',
+ 'type' => 'missing-ability',
+ // phpcs:ignore Generic.Files.LineLength.TooLong
+ 'msg' => 'FakeExtension requires "missingAbilityWithMessage" ability: Missing.',
+ ],
+ ],
+ ],
+ [
+ [
+ 'platform' => [
+ 'ability-missingAbility' => false,
+ ],
+ ],
+ [],
+ ],
+ [
+ [
+ 'platform' => [
+ 'ability-missingAbilityWithMessage' => false,
+ ],
+ ],
+ [],
+ ],
];
}
* returns any error message.
*/
public function testInvalidConstraint() {
- $checker = new VersionChecker( '1.0.0' );
+ $checker = new VersionChecker( '1.0.0', '7.0.0', [] );
$checker->setLoadedExtensionsAndSkins( [
'FakeDependency' => [
'version' => 'not really valid',
],
] ) );
- $checker = new VersionChecker( '1.0.0' );
+ $checker = new VersionChecker( '1.0.0', '7.0.0', [] );
$checker->setLoadedExtensionsAndSkins( [
'FakeDependency' => [
'version' => '1.24.3',
] );
}
+ public function provideInvalidDependency() {
+ return [
+ [
+ [
+ 'FakeExtension' => [
+ 'platform' => [
+ 'undefinedPlatformDependency' => '*',
+ ],
+ ],
+ ],
+ 'undefinedPlatformDependency',
+ ],
+ [
+ [
+ 'FakeExtension' => [
+ 'platform' => [
+ 'phpLoadedExtension' => '*',
+ ],
+ ],
+ ],
+ 'phpLoadedExtension',
+ ],
+ [
+ [
+ 'FakeExtension' => [
+ 'platform' => [
+ 'ability-invalidAbility' => true,
+ ],
+ ],
+ ],
+ 'ability-invalidAbility',
+ ],
+ [
+ [
+ 'FakeExtension' => [
+ 'platform' => [
+ 'presentAbility' => true,
+ ],
+ ],
+ ],
+ 'presentAbility',
+ ],
+ [
+ [
+ 'FakeExtension' => [
+ 'undefinedDependencyType' => '*',
+ ],
+ ],
+ 'undefinedDependencyType',
+ ],
+ // T197478
+ [
+ [
+ 'FakeExtension' => [
+ 'skin' => [
+ 'FakeSkin' => '*',
+ ],
+ ],
+ ],
+ 'skin',
+ ],
+ ];
+ }
+
/**
- * T197478
+ * @dataProvider provideInvalidDependency
*/
- public function testInvalidDependency() {
- $checker = new VersionChecker( '1.0.0' );
- $this->setExpectedException( UnexpectedValueException::class,
- 'Dependency type skin unknown in FakeExtension' );
- $this->assertEquals( [
+ public function testInvalidDependency( $depencency, $type ) {
+ $checker = new VersionChecker(
+ '1.0.0',
+ '7.0.0',
+ [ 'phpLoadedExtension' ],
[
- 'type' => 'invalid-version',
- 'msg' => 'FakeDependency does not have a valid version string.',
+ 'presentAbility' => true,
+ 'missingAbility' => false,
+ ]
+ );
+ $this->setExpectedException(
+ UnexpectedValueException::class,
+ "Dependency type $type unknown in FakeExtension"
+ );
+ $checker->checkArray( $depencency );
+ }
+
+ public function testInvalidPhpExtensionConstraint() {
+ $checker = new VersionChecker( '1.0.0', '7.0.0', [ 'phpLoadedExtension' ] );
+ $this->setExpectedException(
+ UnexpectedValueException::class,
+ 'Version constraints for PHP extensions are not supported in FakeExtension'
+ );
+ $checker->checkArray( [
+ 'FakeExtension' => [
+ 'platform' => [
+ 'ext-phpLoadedExtension' => '1.0.0',
+ ],
],
- ], $checker->checkArray( [
+ ] );
+ }
+
+ /**
+ * @dataProvider provideInvalidAbilityType
+ */
+ public function testInvalidAbilityType( $value ) {
+ $checker = new VersionChecker( '1.0.0', '7.0.0', [], [ 'presentAbility' => true ] );
+ $this->setExpectedException(
+ UnexpectedValueException::class,
+ 'Only booleans are allowed to to indicate the presence of abilities in FakeExtension'
+ );
+ $checker->checkArray( [
'FakeExtension' => [
- 'skin' => [
- 'FakeSkin' => '*',
+ 'platform' => [
+ 'ability-presentAbility' => $value,
],
],
- ] ) );
+ ] );
}
+
+ public function provideInvalidAbilityType() {
+ return [
+ [ null ],
+ [ 1 ],
+ [ '1' ],
+ ];
+ }
+
}