MediaWiki REL1_32
NameTableStoreFactoryTest.php
Go to the documentation of this file.
1<?php
2
4
12
21 private function getMockLoadBalancer( $localDomain ) {
22 $mock = $this->getMockBuilder( ILoadBalancer::class )
23 ->disableOriginalConstructor()->getMock();
24
25 $mock->expects( $this->any() )
26 ->method( 'getLocalDomainID' )
27 ->willReturn( $localDomain );
28
29 return $mock;
30 }
31
35 private function getMockLoadBalancerFactory( $expectedWiki ) {
36 $mock = $this->getMockBuilder( ILBFactory::class )
37 ->disableOriginalConstructor()->getMock();
38
39 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
40 $localDomain = $lbFactory->getLocalDomainID();
41
42 $mock->expects( $this->any() )->method( 'getLocalDomainID' )->willReturn( $localDomain );
43
44 $mock->expects( $this->once() )
45 ->method( 'getMainLB' )
46 ->with( $this->equalTo( $expectedWiki ) )
47 ->willReturnCallback( function ( $domain ) use ( $localDomain ) {
48 return $this->getMockLoadBalancer( $localDomain );
49 } );
50
51 return $mock;
52 }
53
54 public static function provideTestGet() {
55 return [
56 [
57 'change_tag_def',
58 false,
59 false,
60 ],
61 [
62 'content_models',
63 false,
64 false,
65 ],
66 [
67 'slot_roles',
68 false,
69 false,
70 ],
71 [
72 'change_tag_def',
73 'test7245',
74 'test7245',
75 ],
76 ];
77 }
78
80 public function testGet( $tableName, $wiki, $expectedWiki ) {
82 $wiki2 = ( $wiki === false )
83 ? $services->getDBLoadBalancerFactory()->getLocalDomainID()
84 : $wiki;
85 $names = new NameTableStoreFactory(
86 $this->getMockLoadBalancerFactory( $expectedWiki ),
87 $services->getMainWANObjectCache(),
88 LoggerFactory::getInstance( 'NameTableStoreFactory' )
89 );
90
91 $table = $names->get( $tableName, $wiki );
92 $table2 = $names->get( $tableName, $wiki2 );
93 $this->assertSame( $table, $table2 );
94 $this->assertInstanceOf( NameTableStore::class, $table );
95 }
96
97 /*
98 * The next three integration tests verify that the schema information is correct by loading
99 * the relevant information from the database.
100 */
101
104 $factory = $services->getNameTableStoreFactory();
105 $store = $factory->getChangeTagDef();
106 $this->assertType( 'array', $store->getMap() );
107 }
108
111 $factory = $services->getNameTableStoreFactory();
112 $store = $factory->getContentModels();
113 $this->assertType( 'array', $store->getMap() );
114 }
115
116 public function testIntegratedGetSlotRoles() {
118 $factory = $services->getNameTableStoreFactory();
119 $store = $factory->getSlotRoles();
120 $this->assertType( 'array', $store->getMap() );
121 }
122}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
assertType( $type, $actual, $message='')
Asserts the type of the provided value.
PSR-3 logger instance factory.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getInstance()
Returns the global default instance of the top level service locator.
MediaWiki\Storage\NameTableStoreFactory Database.
testGet( $tableName, $wiki, $expectedWiki)
provideTestGet
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition hooks.txt:2335
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
An interface for generating database load balancers.
Database cluster connection, tracking, load balancing, and transaction manager interface.