2 use MediaWiki\MediaWikiServices
;
5 * @covers MediaWiki\MediaWikiServices
9 class MediaWikiServicesTest
extends PHPUnit_Framework_TestCase
{
11 public function testGetInstance() {
12 $services = MediaWikiServices
::getInstance();
13 $this->assertInstanceOf( 'MediaWiki\\MediaWikiServices', $services );
16 public function provideGetters() {
17 // NOTE: This should list all service getters defined in MediaWikiServices.
18 // NOTE: For every test case defined here there should be a corresponding
19 // test case defined in provideGetService().
21 'BootstrapConfig' => [ 'getBootstrapConfig', Config
::class ],
22 'ConfigFactory' => [ 'getConfigFactory', ConfigFactory
::class ],
23 'MainConfig' => [ 'getMainConfig', Config
::class ],
24 'SiteStore' => [ 'getSiteStore', SiteStore
::class ],
25 'SiteLookup' => [ 'getSiteLookup', SiteLookup
::class ],
30 * @dataProvider provideGetters
32 public function testGetters( $getter, $type ) {
33 // Test against the default instance, since the dummy will not know the default services.
34 $services = MediaWikiServices
::getInstance();
35 $service = $services->$getter();
36 $this->assertInstanceOf( $type, $service );
39 public function provideGetService() {
40 // NOTE: This should list all service getters defined in ServiceWiring.php.
41 // NOTE: For every test case defined here there should be a corresponding
42 // test case defined in provideGetters().
44 'BootstrapConfig' => [ 'BootstrapConfig', Config
::class ],
45 'ConfigFactory' => [ 'ConfigFactory', ConfigFactory
::class ],
46 'MainConfig' => [ 'MainConfig', Config
::class ],
47 'SiteStore' => [ 'SiteStore', SiteStore
::class ],
48 'SiteLookup' => [ 'SiteLookup', SiteLookup
::class ],
53 * @dataProvider provideGetService
55 public function testGetService( $name, $type ) {
56 // Test against the default instance, since the dummy will not know the default services.
57 $services = MediaWikiServices
::getInstance();
59 $service = $services->getService( $name );
60 $this->assertInstanceOf( $type, $service );
63 public function testDefaultServiceInstantiation() {
64 // Check all services in the default instance, not a dummy instance!
65 // Note that we instantiate all services here, including any that
66 // were registered by extensions.
67 $services = MediaWikiServices
::getInstance();
68 $names = $services->getServiceNames();
70 foreach ( $names as $name ) {
71 $this->assertTrue( $services->hasService( $name ) );
72 $service = $services->getService( $name );
73 $this->assertInternalType( 'object', $service );