2 use Liuggio\StatsdClient\Factory\StatsdDataFactory
;
3 use MediaWiki\MediaWikiServices
;
6 * @covers MediaWiki\MediaWikiServices
10 class MediaWikiServicesTest
extends PHPUnit_Framework_TestCase
{
12 public function testGetInstance() {
13 $services = MediaWikiServices
::getInstance();
14 $this->assertInstanceOf( 'MediaWiki\\MediaWikiServices', $services );
17 public function provideGetters() {
18 // NOTE: This should list all service getters defined in MediaWikiServices.
19 // NOTE: For every test case defined here there should be a corresponding
20 // test case defined in provideGetService().
22 'BootstrapConfig' => [ 'getBootstrapConfig', Config
::class ],
23 'ConfigFactory' => [ 'getConfigFactory', ConfigFactory
::class ],
24 'MainConfig' => [ 'getMainConfig', Config
::class ],
25 'SiteStore' => [ 'getSiteStore', SiteStore
::class ],
26 'SiteLookup' => [ 'getSiteLookup', SiteLookup
::class ],
27 'StatsdDataFactory' => [ 'getStatsdDataFactory', StatsdDataFactory
::class ],
28 'EventRelayerGroup' => [ 'getEventRelayerGroup', EventRelayerGroup
::class ],
29 'SearchEngine' => [ 'newSearchEngine', SearchEngine
::class ],
30 'SearchEngineFactory' => [ 'getSearchEngineFactory', SearchEngineFactory
::class ],
31 'SearchEngineConfig' => [ 'getSearchEngineConfig', SearchEngineConfig
::class ],
36 * @dataProvider provideGetters
38 public function testGetters( $getter, $type ) {
39 // Test against the default instance, since the dummy will not know the default services.
40 $services = MediaWikiServices
::getInstance();
41 $service = $services->$getter();
42 $this->assertInstanceOf( $type, $service );
45 public function provideGetService() {
46 // NOTE: This should list all service getters defined in ServiceWiring.php.
47 // NOTE: For every test case defined here there should be a corresponding
48 // test case defined in provideGetters().
50 'BootstrapConfig' => [ 'BootstrapConfig', Config
::class ],
51 'ConfigFactory' => [ 'ConfigFactory', ConfigFactory
::class ],
52 'MainConfig' => [ 'MainConfig', Config
::class ],
53 'SiteStore' => [ 'SiteStore', SiteStore
::class ],
54 'SiteLookup' => [ 'SiteLookup', SiteLookup
::class ],
55 'StatsdDataFactory' => [ 'StatsdDataFactory', StatsdDataFactory
::class ],
56 'EventRelayerGroup' => [ 'EventRelayerGroup', EventRelayerGroup
::class ],
57 'SearchEngineFactory' => [ 'SearchEngineFactory', SearchEngineFactory
::class ],
58 'SearchEngineConfig' => [ 'SearchEngineConfig', SearchEngineConfig
::class ],
63 * @dataProvider provideGetService
65 public function testGetService( $name, $type ) {
66 // Test against the default instance, since the dummy will not know the default services.
67 $services = MediaWikiServices
::getInstance();
69 $service = $services->getService( $name );
70 $this->assertInstanceOf( $type, $service );
73 public function testDefaultServiceInstantiation() {
74 // Check all services in the default instance, not a dummy instance!
75 // Note that we instantiate all services here, including any that
76 // were registered by extensions.
77 $services = MediaWikiServices
::getInstance();
78 $names = $services->getServiceNames();
80 foreach ( $names as $name ) {
81 $this->assertTrue( $services->hasService( $name ) );
82 $service = $services->getService( $name );
83 $this->assertInternalType( 'object', $service );