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 ],
32 * @dataProvider provideGetters
34 public function testGetters( $getter, $type ) {
35 // Test against the default instance, since the dummy will not know the default services.
36 $services = MediaWikiServices
::getInstance();
37 $service = $services->$getter();
38 $this->assertInstanceOf( $type, $service );
41 public function provideGetService() {
42 // NOTE: This should list all service getters defined in ServiceWiring.php.
43 // NOTE: For every test case defined here there should be a corresponding
44 // test case defined in provideGetters().
46 'BootstrapConfig' => [ 'BootstrapConfig', Config
::class ],
47 'ConfigFactory' => [ 'ConfigFactory', ConfigFactory
::class ],
48 'MainConfig' => [ 'MainConfig', Config
::class ],
49 'SiteStore' => [ 'SiteStore', SiteStore
::class ],
50 'SiteLookup' => [ 'SiteLookup', SiteLookup
::class ],
51 'StatsdDataFactory' => [ 'StatsdDataFactory', StatsdDataFactory
::class ],
56 * @dataProvider provideGetService
58 public function testGetService( $name, $type ) {
59 // Test against the default instance, since the dummy will not know the default services.
60 $services = MediaWikiServices
::getInstance();
62 $service = $services->getService( $name );
63 $this->assertInstanceOf( $type, $service );
66 public function testDefaultServiceInstantiation() {
67 // Check all services in the default instance, not a dummy instance!
68 // Note that we instantiate all services here, including any that
69 // were registered by extensions.
70 $services = MediaWikiServices
::getInstance();
71 $names = $services->getServiceNames();
73 foreach ( $names as $name ) {
74 $this->assertTrue( $services->hasService( $name ) );
75 $service = $services->getService( $name );
76 $this->assertInternalType( 'object', $service );