Merge "Catch JobQueue errors in SiteStats::jobs"
[lhc/web/wiklou.git] / tests / phpunit / includes / MediaWikiServicesTest.php
1 <?php
2 use Liuggio\StatsdClient\Factory\StatsdDataFactory;
3 use MediaWiki\MediaWikiServices;
4
5 /**
6 * @covers MediaWiki\MediaWikiServices
7 *
8 * @group MediaWiki
9 */
10 class MediaWikiServicesTest extends PHPUnit_Framework_TestCase {
11
12 public function testGetInstance() {
13 $services = MediaWikiServices::getInstance();
14 $this->assertInstanceOf( 'MediaWiki\\MediaWikiServices', $services );
15 }
16
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().
21 return [
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 ];
29 }
30
31 /**
32 * @dataProvider provideGetters
33 */
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 );
39 }
40
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().
45 return [
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 ],
52 ];
53 }
54
55 /**
56 * @dataProvider provideGetService
57 */
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();
61
62 $service = $services->getService( $name );
63 $this->assertInstanceOf( $type, $service );
64 }
65
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();
72
73 foreach ( $names as $name ) {
74 $this->assertTrue( $services->hasService( $name ) );
75 $service = $services->getService( $name );
76 $this->assertInternalType( 'object', $service );
77 }
78 }
79
80 }