MediaWiki  1.33.0
RevisionStoreFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
4 
7 use MediaWiki\Logger\Spi as LoggerSpi;
17 use Psr\Log\LoggerInterface;
18 use Psr\Log\NullLogger;
22 use Wikimedia\TestingAccessWrapper;
23 
25 
32  $this->getMockBlobStoreFactory(),
33  $this->getNameTableStoreFactory(),
34  $this->getMockSlotRoleRegistry(),
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();
66  $cache = $this->getHashWANObjectCache();
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 }
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\testGetRevisionStore
testGetRevisionStore( $wikiId, $mcrMigrationStage=MIGRATION_OLD, $contentHandlerUseDb=true)
provideWikiIds \MediaWiki\Revision\RevisionStoreFactory::getRevisionStore
Definition: RevisionStoreFactoryTest.php:57
MediaWiki\Tests\Revision\RevisionStoreFactoryTest
Definition: RevisionStoreFactoryTest.php:24
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getMockLoadBalancer
getMockLoadBalancer()
Definition: RevisionStoreFactoryTest.php:110
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getMockCommentStore
getMockCommentStore()
Definition: RevisionStoreFactoryTest.php:176
HashBagOStuff
Simple store for keeping values in an associative array for the current process.
Definition: HashBagOStuff.php:31
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\testValidConstruction_doesntCauseErrors
testValidConstruction_doesntCauseErrors()
\MediaWiki\Revision\RevisionStoreFactory::__construct
Definition: RevisionStoreFactoryTest.php:29
Revision\RevisionStore
Service for looking up page revisions.
Definition: RevisionStore.php:76
MediaWiki\Storage\SqlBlobStore
Service for storing and loading Content objects.
Definition: SqlBlobStore.php:49
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getMockSqlBlobStore
getMockSqlBlobStore()
Definition: RevisionStoreFactoryTest.php:133
MediaWiki\Tests\Revision
Definition: FallbackSlotRoleHandlerTest.php:3
MIGRATION_NEW
const MIGRATION_NEW
Definition: Defines.php:318
CommentStore
CommentStore handles storage of comments (edit summaries, log reasons, etc) in the database.
Definition: CommentStore.php:31
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getMockLoadBalancerFactory
getMockLoadBalancerFactory()
Definition: RevisionStoreFactoryTest.php:118
ActorMigration
This class handles the logic for the actor table migration.
Definition: ActorMigration.php:35
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getNameTableStoreFactory
getNameTableStoreFactory()
Definition: RevisionStoreFactoryTest.php:166
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:111
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
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getMockSlotRoleRegistry
getMockSlotRoleRegistry()
Definition: RevisionStoreFactoryTest.php:156
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getMockBlobStoreFactory
getMockBlobStoreFactory()
Definition: RevisionStoreFactoryTest.php:141
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\Storage\BlobStoreFactory
Service for instantiating BlobStores.
Definition: BlobStoreFactory.php:35
MIGRATION_OLD
const MIGRATION_OLD
Definition: Defines.php:315
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getHashWANObjectCache
getHashWANObjectCache()
Definition: RevisionStoreFactoryTest.php:181
WANObjectCache
Multi-datacenter aware caching interface.
Definition: WANObjectCache.php:116
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\provideWikiIds
provideWikiIds()
Definition: RevisionStoreFactoryTest.php:45
MediaWiki\Storage\NameTableStore
Definition: NameTableStore.php:35
Revision\RevisionStoreFactory
Factory service for RevisionStore instances.
Definition: RevisionStoreFactory.php:49
MediaWiki\Storage\BlobStore
Service for loading and storing data blobs.
Definition: BlobStore.php:33
$cache
$cache
Definition: mcc.php:33
as
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
Definition: distributors.txt:9
true
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:1985
MediaWiki\Storage\NameTableStoreFactory
Definition: NameTableStoreFactory.php:26
Revision\SlotRoleRegistry
A registry service for SlotRoleHandlers, used to define which slot roles are available on which page.
Definition: SlotRoleRegistry.php:48
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
MediaWiki\Logger\Spi
Service provider interface for \Psr\Log\LoggerInterface implementation libraries.
Definition: Spi.php:36
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\Revision\RevisionStoreFactoryTest\getMockLoggerSpi
getMockLoggerSpi()
Definition: RevisionStoreFactoryTest.php:188