*/
private $phpVersion = false;
+ /**
+ * @var string[] List of installed PHP extensions
+ */
+ private $phpExtensions = [];
+
/**
* @var array Loaded extensions
*/
/**
* @param string $coreVersion Current version of core
+ * @param string $phpVersion Current PHP version
+ * @param string[] $phpExtensions List of installed PHP extensions
*/
- public function __construct( $coreVersion, $phpVersion ) {
+ public function __construct( $coreVersion, $phpVersion, array $phpExtensions ) {
$this->versionParser = new VersionParser();
$this->setCoreVersion( $coreVersion );
$this->setPhpVersion( $phpVersion );
+ $this->phpExtensions = $phpExtensions;
}
/**
* 'FooBar' => {
* 'MediaWiki' => '>= 1.25.0',
* 'platform': {
- * 'php': '>= 7.0.0'
+ * 'php': '>= 7.0.0',
+ * 'ext-foo': '*'
* },
* 'extensions' => {
* 'FooBaz' => '>= 1.25.0'
case 'platform':
foreach ( $values as $dependency => $constraint ) {
if ( $dependency === 'php' ) {
+ // PHP version
$phpError = $this->handleDependency(
$this->phpVersion,
$constraint,
'type' => 'incompatible-php',
];
}
+ } elseif ( substr( $dependency, 0, 4 ) === 'ext-' ) {
+ // PHP extensions
+ $phpExtension = substr( $dependency, 4 );
+ if ( $constraint !== '*' ) {
+ throw new UnexpectedValueException( 'Version constraints for '
+ . 'PHP extensions are not supported in ' . $extension );
+ }
+ if ( !in_array( $phpExtension, $this->phpExtensions, true ) ) {
+ $errors[] = [
+ 'msg' =>
+ "{$extension} requires {$phpExtension} PHP extension "
+ . "to be installed."
+ ,
+ 'type' => 'missing-phpExtension',
+ 'missing' => $phpExtension,
+ ];
+ }
} else {
// add other platform dependencies here
throw new UnexpectedValueException( 'Dependency type ' . $dependency .
* @dataProvider provideMediaWikiCheck
*/
public function testMediaWikiCheck( $coreVersion, $constraint, $expected ) {
- $checker = new VersionChecker( $coreVersion, '7.0.0' );
+ $checker = new VersionChecker( $coreVersion, '7.0.0', [] );
$this->assertEquals( $expected, !(bool)$checker->checkArray( [
'FakeExtension' => [
'MediaWiki' => $constraint,
* @dataProvider providePhpValidCheck
*/
public function testPhpValidCheck( $phpVersion, $constraint, $expected ) {
- $checker = new VersionChecker( '1.0.0', $phpVersion );
+ $checker = new VersionChecker( '1.0.0', $phpVersion, [] );
$this->assertEquals( $expected, !(bool)$checker->checkArray( [
'FakeExtension' => [
'platform' => [
* @expectedException UnexpectedValueException
*/
public function testPhpInvalidConstraint() {
- $checker = new VersionChecker( '1.0.0', '7.0.0' );
+ $checker = new VersionChecker( '1.0.0', '7.0.0', [] );
$checker->checkArray( [
'FakeExtension' => [
'platform' => [
* @expectedException UnexpectedValueException
*/
public function testPhpInvalidVersion( $phpVersion ) {
- $checker = new VersionChecker( '1.0.0', $phpVersion );
+ $checker = new VersionChecker( '1.0.0', $phpVersion, [] );
}
public static function providePhpInvalidVersion() {
* @dataProvider provideType
*/
public function testType( $given, $expected ) {
- $checker = new VersionChecker( '1.0.0', '7.0.0' );
+ $checker = new VersionChecker( '1.0.0', '7.0.0', [ 'phpLoadedExtension' ] );
$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.',
+ ],
+ ],
+ ],
];
}
* returns any error message.
*/
public function testInvalidConstraint() {
- $checker = new VersionChecker( '1.0.0', '7.0.0' );
+ $checker = new VersionChecker( '1.0.0', '7.0.0', [] );
$checker->setLoadedExtensionsAndSkins( [
'FakeDependency' => [
'version' => 'not really valid',
],
] ) );
- $checker = new VersionChecker( '1.0.0', '7.0.0' );
+ $checker = new VersionChecker( '1.0.0', '7.0.0', [] );
$checker->setLoadedExtensionsAndSkins( [
'FakeDependency' => [
'version' => '1.24.3',
],
'undefinedPlatformDependency',
],
+ [
+ [
+ 'FakeExtension' => [
+ 'platform' => [
+ 'phpLoadedExtension' => '*',
+ ],
+ ],
+ ],
+ 'phpLoadedExtension',
+ ],
[
[
'FakeExtension' => [
* @dataProvider provideInvalidDependency
*/
public function testInvalidDependency( $depencency, $type ) {
- $checker = new VersionChecker( '1.0.0', '7.0.0' );
+ $checker = new VersionChecker( '1.0.0', '7.0.0', [ 'phpLoadedExtension' ] );
$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',
+ ],
+ ],
+ ] );
+ }
}