<?php
use MediaWiki\MediaWikiServices;
-use MediaWiki\Services\DestructibleService;
-use MediaWiki\Services\SalvageableService;
-use MediaWiki\Services\ServiceDisabledException;
+use Wikimedia\Services\DestructibleService;
+use Wikimedia\Services\SalvageableService;
+use Wikimedia\Services\ServiceDisabledException;
/**
* @covers MediaWiki\MediaWikiServices
* @group MediaWiki
*/
class MediaWikiServicesTest extends MediaWikiTestCase {
+ private $deprecatedServices = [];
/**
* @return Config
'Test',
function () use ( &$serviceCounter ) {
$serviceCounter++;
- $service = $this->createMock( MediaWiki\Services\DestructibleService::class );
+ $service = $this->createMock( Wikimedia\Services\DestructibleService::class );
$service->expects( $this->once() )->method( 'destroy' );
return $service;
}
$services->defineService(
'Test',
function () {
- $service = $this->createMock( MediaWiki\Services\DestructibleService::class );
+ $service = $this->createMock( Wikimedia\Services\DestructibleService::class );
$service->expects( $this->never() )->method( 'destroy' );
return $service;
}
$getterCases[$name] = [
'get' . $service,
$class,
+ in_array( $service, $this->deprecatedServices )
];
}
/**
* @dataProvider provideGetters
*/
- public function testGetters( $getter, $type ) {
+ public function testGetters( $getter, $type, $isDeprecated = false ) {
+ if ( $isDeprecated ) {
+ $this->hideDeprecated( MediaWikiServices::class . "::$getter" );
+ }
+
// Test against the default instance, since the dummy will not know the default services.
$services = MediaWikiServices::getInstance();
$service = $services->$getter();
throw new MWException( 'All service callbacks must have a return type defined, ' .
"none found for $name" );
}
- $ret[$name] = [ $name, $fun->getReturnType()->__toString() ];
+
+ $returnType = $fun->getReturnType();
+
+ // ReflectionType::__toString() generates deprecation notices in PHP 7.4 and above
+ // TODO: T228342 - remove this check after MediaWiki only supports PHP 7.1+
+ if ( is_callable( [ $returnType, 'getName' ] ) ) {
+ $ret[$name] = [ $name, $returnType->getName() ];
+ } else {
+ $ret[$name] = [ $name, $fun->getReturnType()->__toString() ];
+ }
}
return $ret;
}
} ) );
$sortedNames = $names;
- sort( $sortedNames );
+ natcasesort( $sortedNames );
$this->assertSame( $sortedNames, $names,
'Please keep service getters sorted alphabetically' );