MediaWiki REL1_33
RevisionStoreFactoryTest.php
Go to the documentation of this file.
1<?php
2
4
17use Psr\Log\LoggerInterface;
18use Psr\Log\NullLogger;
22use Wikimedia\TestingAccessWrapper;
23
25
35 $this->getHashWANObjectCache(),
36 $this->getMockCommentStore(),
39 $this->getMockLoggerSpi(),
40 true
41 );
42 $this->assertTrue( true );
43 }
44
45 public function provideWikiIds() {
46 yield [ true ];
47 yield [ false ];
48 yield [ 'somewiki' ];
49 yield [ 'somewiki', MIGRATION_OLD , false ];
50 yield [ 'somewiki', MIGRATION_NEW , true ];
51 }
52
57 public function testGetRevisionStore(
58 $wikiId,
59 $mcrMigrationStage = MIGRATION_OLD,
60 $contentHandlerUseDb = true
61 ) {
62 $lbFactory = $this->getMockLoadBalancerFactory();
63 $blobStoreFactory = $this->getMockBlobStoreFactory();
64 $nameTableStoreFactory = $this->getNameTableStoreFactory();
65 $slotRoleRegistry = $this->getMockSlotRoleRegistry();
67 $commentStore = $this->getMockCommentStore();
68 $actorMigration = ActorMigration::newMigration();
69 $loggerProvider = $this->getMockLoggerSpi();
70
71 $factory = new RevisionStoreFactory(
72 $lbFactory,
73 $blobStoreFactory,
74 $nameTableStoreFactory,
75 $slotRoleRegistry,
76 $cache,
77 $commentStore,
78 $actorMigration,
79 $mcrMigrationStage,
80 $loggerProvider,
81 $contentHandlerUseDb
82 );
83
84 $store = $factory->getRevisionStore( $wikiId );
85 $wrapper = TestingAccessWrapper::newFromObject( $store );
86
87 // ensure the correct object type is returned
88 $this->assertInstanceOf( RevisionStore::class, $store );
89
90 // ensure the RevisionStore is for the given wikiId
91 $this->assertSame( $wikiId, $wrapper->wikiId );
92
93 // ensure all other required services are correctly set
94 $this->assertSame( $cache, $wrapper->cache );
95 $this->assertSame( $commentStore, $wrapper->commentStore );
96 $this->assertSame( $mcrMigrationStage, $wrapper->mcrMigrationStage );
97 $this->assertSame( $actorMigration, $wrapper->actorMigration );
98 $this->assertSame( $contentHandlerUseDb, $store->getContentHandlerUseDB() );
99
100 $this->assertInstanceOf( ILoadBalancer::class, $wrapper->loadBalancer );
101 $this->assertInstanceOf( BlobStore::class, $wrapper->blobStore );
102 $this->assertInstanceOf( NameTableStore::class, $wrapper->contentModelStore );
103 $this->assertInstanceOf( NameTableStore::class, $wrapper->slotRoleStore );
104 $this->assertInstanceOf( LoggerInterface::class, $wrapper->logger );
105 }
106
110 private function getMockLoadBalancer() {
111 return $this->getMockBuilder( ILoadBalancer::class )
112 ->disableOriginalConstructor()->getMock();
113 }
114
118 private function getMockLoadBalancerFactory() {
119 $mock = $this->getMockBuilder( ILBFactory::class )
120 ->disableOriginalConstructor()->getMock();
121
122 $mock->method( 'getMainLB' )
123 ->willReturnCallback( function () {
124 return $this->getMockLoadBalancer();
125 } );
126
127 return $mock;
128 }
129
133 private function getMockSqlBlobStore() {
134 return $this->getMockBuilder( SqlBlobStore::class )
135 ->disableOriginalConstructor()->getMock();
136 }
137
141 private function getMockBlobStoreFactory() {
142 $mock = $this->getMockBuilder( BlobStoreFactory::class )
143 ->disableOriginalConstructor()->getMock();
144
145 $mock->method( 'newSqlBlobStore' )
146 ->willReturnCallback( function () {
147 return $this->getMockSqlBlobStore();
148 } );
149
150 return $mock;
151 }
152
156 private function getMockSlotRoleRegistry() {
157 $mock = $this->getMockBuilder( SlotRoleRegistry::class )
158 ->disableOriginalConstructor()->getMock();
159
160 return $mock;
161 }
162
166 private function getNameTableStoreFactory() {
167 return new NameTableStoreFactory(
169 $this->getHashWANObjectCache(),
170 new NullLogger() );
171 }
172
176 private function getMockCommentStore() {
177 return $this->getMockBuilder( CommentStore::class )
178 ->disableOriginalConstructor()->getMock();
179 }
180
181 private function getHashWANObjectCache() {
182 return new WANObjectCache( [ 'cache' => new \HashBagOStuff() ] );
183 }
184
188 private function getMockLoggerSpi() {
189 $mock = $this->getMock( LoggerSpi::class );
190
191 $mock->method( 'getLogger' )
192 ->willReturn( new NullLogger() );
193
194 return $mock;
195 }
196
197}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This class handles the logic for the actor table migration.
static newMigration()
Static constructor.
CommentStore handles storage of comments (edit summaries, log reasons, etc) in the database.
Simple store for keeping values in an associative array for the current process.
Factory service for RevisionStore instances.
Service for looking up page revisions.
A registry service for SlotRoleHandlers, used to define which slot roles are available on which page.
Service for instantiating BlobStores.
Service for storing and loading Content objects.
testValidConstruction_doesntCauseErrors()
\MediaWiki\Revision\RevisionStoreFactory::__construct
testGetRevisionStore( $wikiId, $mcrMigrationStage=MIGRATION_OLD, $contentHandlerUseDb=true)
provideWikiIds \MediaWiki\Revision\RevisionStoreFactory::getRevisionStore
Multi-datacenter aware caching interface.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const MIGRATION_NEW
Definition Defines.php:327
const MIGRATION_OLD
Definition Defines.php:324
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:2004
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
Service provider interface for \Psr\Log\LoggerInterface implementation libraries.
Definition Spi.php:36
Service for loading and storing data blobs.
Definition BlobStore.php:33
An interface for generating database load balancers.
Database cluster connection, tracking, load balancing, and transaction manager interface.
$cache
Definition mcc.php:33