MediaWiki  1.32.5
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 
102  public function testIntegratedGetChangeTagDef() {
104  $factory = $services->getNameTableStoreFactory();
105  $store = $factory->getChangeTagDef();
106  $this->assertType( 'array', $store->getMap() );
107  }
108 
109  public function testIntegratedGetContentModels() {
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 }
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
MediaWiki\Logger\LoggerFactory\getInstance
static getInstance( $channel)
Get a named logger instance from the currently configured logger factory.
Definition: LoggerFactory.php:92
MediaWiki\Tests\Storage\NameTableStoreFactoryTest\testIntegratedGetContentModels
testIntegratedGetContentModels()
Definition: NameTableStoreFactoryTest.php:109
MediaWiki\Tests\Storage\NameTableStoreFactoryTest\testIntegratedGetChangeTagDef
testIntegratedGetChangeTagDef()
Definition: NameTableStoreFactoryTest.php:102
MediaWiki\Tests\Storage\NameTableStoreFactoryTest\testIntegratedGetSlotRoles
testIntegratedGetSlotRoles()
Definition: NameTableStoreFactoryTest.php:116
php
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:35
MediaWiki\Tests\Storage
Definition: BlobStoreFactoryTest.php:3
MediaWiki\Tests\Storage\NameTableStoreFactoryTest\getMockLoadBalancer
getMockLoadBalancer( $localDomain)
Definition: NameTableStoreFactoryTest.php:21
MediaWikiTestCase
Definition: MediaWikiTestCase.php:16
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
MediaWiki\Tests\Storage\NameTableStoreFactoryTest\provideTestGet
static provideTestGet()
Definition: NameTableStoreFactoryTest.php:54
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:120
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition: COPYING.txt:326
MediaWiki\Storage\NameTableStore
Definition: NameTableStore.php:35
MediaWiki\Tests\Storage\NameTableStoreFactoryTest
MediaWiki\Storage\NameTableStoreFactory Database.
Definition: NameTableStoreFactoryTest.php:17
LoggerFactory
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method. MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances. The "Spi" in MediaWiki\Logger\Spi stands for "service provider interface". An SPI is an API intended to be implemented or extended by a third party. This software design pattern is intended to enable framework extension and replaceable components. It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki. The service provider interface allows the backend logging library to be implemented in multiple ways. The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime. This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance. Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
MediaWiki\Storage\NameTableStoreFactory
Definition: NameTableStoreFactory.php:26
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
$services
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:2278
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
MediaWikiTestCase\assertType
assertType( $type, $actual, $message='')
Asserts the type of the provided value.
Definition: MediaWikiTestCase.php:2143
MediaWiki\Storage\NameTableStoreFactory\get
get( $tableName, $wiki=false)
Get a NameTableStore for a specific table.
Definition: NameTableStoreFactory.php:92
MediaWiki\Tests\Storage\NameTableStoreFactoryTest\getMockLoadBalancerFactory
getMockLoadBalancerFactory( $expectedWiki)
Definition: NameTableStoreFactoryTest.php:35
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:78
Wikimedia\Rdbms\ILBFactory
An interface for generating database load balancers.
Definition: ILBFactory.php:33
MediaWiki\Tests\Storage\NameTableStoreFactoryTest\testGet
testGet( $tableName, $wiki, $expectedWiki)
provideTestGet
Definition: NameTableStoreFactoryTest.php:80