Merge "Improve HTMLSubmitField return value"
[lhc/web/wiklou.git] / tests / phpunit / includes / MediaWikiServicesTest.php
1 <?php
2 use MediaWiki\MediaWikiServices;
3
4 /**
5 * @covers MediaWiki\MediaWikiServices
6 *
7 * @group MediaWiki
8 */
9 class MediaWikiServicesTest extends PHPUnit_Framework_TestCase {
10
11 public function testGetInstance() {
12 $services = MediaWikiServices::getInstance();
13 $this->assertInstanceOf( 'MediaWiki\\MediaWikiServices', $services );
14 }
15
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().
20 return [
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 ],
26 ];
27 }
28
29 /**
30 * @dataProvider provideGetters
31 */
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 );
37 }
38
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().
43 return [
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 ],
49 ];
50 }
51
52 /**
53 * @dataProvider provideGetService
54 */
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();
58
59 $service = $services->getService( $name );
60 $this->assertInstanceOf( $type, $service );
61 }
62
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();
69
70 foreach ( $names as $name ) {
71 $this->assertTrue( $services->hasService( $name ) );
72 $service = $services->getService( $name );
73 $this->assertInternalType( 'object', $service );
74 }
75 }
76
77 }