2015-10-12 08:05:45 +00:00
|
|
|
<?php
|
2016-04-11 18:28:17 +00:00
|
|
|
use Liuggio\StatsdClient\Factory\StatsdDataFactory;
|
2015-10-12 08:05:45 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers MediaWiki\MediaWikiServices
|
|
|
|
|
*
|
|
|
|
|
* @group MediaWiki
|
|
|
|
|
*/
|
|
|
|
|
class MediaWikiServicesTest extends PHPUnit_Framework_TestCase {
|
|
|
|
|
|
|
|
|
|
public function testGetInstance() {
|
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$this->assertInstanceOf( 'MediaWiki\\MediaWikiServices', $services );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetters() {
|
2016-04-11 20:37:32 +00:00
|
|
|
// NOTE: This should list all service getters defined in MediaWikiServices.
|
|
|
|
|
// NOTE: For every test case defined here there should be a corresponding
|
|
|
|
|
// test case defined in provideGetService().
|
|
|
|
|
return [
|
|
|
|
|
'BootstrapConfig' => [ 'getBootstrapConfig', Config::class ],
|
|
|
|
|
'ConfigFactory' => [ 'getConfigFactory', ConfigFactory::class ],
|
|
|
|
|
'MainConfig' => [ 'getMainConfig', Config::class ],
|
|
|
|
|
'SiteStore' => [ 'getSiteStore', SiteStore::class ],
|
|
|
|
|
'SiteLookup' => [ 'getSiteLookup', SiteLookup::class ],
|
2016-04-11 18:28:17 +00:00
|
|
|
'StatsdDataFactory' => [ 'getStatsdDataFactory', StatsdDataFactory::class ],
|
2016-04-23 00:09:14 +00:00
|
|
|
'EventRelayerGroup' => [ 'getEventRelayerGroup', EventRelayerGroup::class ],
|
2016-04-03 08:37:11 +00:00
|
|
|
'SearchEngine' => [ 'newSearchEngine', SearchEngine::class ],
|
|
|
|
|
'SearchEngineFactory' => [ 'getSearchEngineFactory', SearchEngineFactory::class ],
|
|
|
|
|
'SearchEngineConfig' => [ 'getSearchEngineConfig', SearchEngineConfig::class ],
|
2016-04-19 11:55:23 +00:00
|
|
|
'SkinFactory' => [ 'getSkinFactory', SkinFactory::class ],
|
2016-04-11 20:37:32 +00:00
|
|
|
];
|
2015-10-12 08:05:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetters
|
|
|
|
|
*/
|
|
|
|
|
public function testGetters( $getter, $type ) {
|
|
|
|
|
// Test against the default instance, since the dummy will not know the default services.
|
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$service = $services->$getter();
|
|
|
|
|
$this->assertInstanceOf( $type, $service );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetService() {
|
|
|
|
|
// NOTE: This should list all service getters defined in ServiceWiring.php.
|
|
|
|
|
// NOTE: For every test case defined here there should be a corresponding
|
|
|
|
|
// test case defined in provideGetters().
|
|
|
|
|
return [
|
|
|
|
|
'BootstrapConfig' => [ 'BootstrapConfig', Config::class ],
|
|
|
|
|
'ConfigFactory' => [ 'ConfigFactory', ConfigFactory::class ],
|
|
|
|
|
'MainConfig' => [ 'MainConfig', Config::class ],
|
|
|
|
|
'SiteStore' => [ 'SiteStore', SiteStore::class ],
|
|
|
|
|
'SiteLookup' => [ 'SiteLookup', SiteLookup::class ],
|
2016-04-11 18:28:17 +00:00
|
|
|
'StatsdDataFactory' => [ 'StatsdDataFactory', StatsdDataFactory::class ],
|
2016-04-23 00:09:14 +00:00
|
|
|
'EventRelayerGroup' => [ 'EventRelayerGroup', EventRelayerGroup::class ],
|
2016-04-03 08:37:11 +00:00
|
|
|
'SearchEngineFactory' => [ 'SearchEngineFactory', SearchEngineFactory::class ],
|
|
|
|
|
'SearchEngineConfig' => [ 'SearchEngineConfig', SearchEngineConfig::class ],
|
2016-04-19 11:55:23 +00:00
|
|
|
'SkinFactory' => [ 'SkinFactory', SkinFactory::class ],
|
2015-10-12 08:05:45 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetService
|
|
|
|
|
*/
|
|
|
|
|
public function testGetService( $name, $type ) {
|
|
|
|
|
// Test against the default instance, since the dummy will not know the default services.
|
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
|
|
|
|
|
$service = $services->getService( $name );
|
|
|
|
|
$this->assertInstanceOf( $type, $service );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDefaultServiceInstantiation() {
|
|
|
|
|
// Check all services in the default instance, not a dummy instance!
|
|
|
|
|
// Note that we instantiate all services here, including any that
|
|
|
|
|
// were registered by extensions.
|
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$names = $services->getServiceNames();
|
|
|
|
|
|
|
|
|
|
foreach ( $names as $name ) {
|
|
|
|
|
$this->assertTrue( $services->hasService( $name ) );
|
|
|
|
|
$service = $services->getService( $name );
|
|
|
|
|
$this->assertInternalType( 'object', $service );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|