3 namespace MediaWiki\Tests\Storage
;
7 use MediaWiki\Logger\Spi
as LoggerSpi
;
8 use MediaWiki\Storage\BlobStore
;
9 use MediaWiki\Storage\BlobStoreFactory
;
10 use MediaWiki\Storage\NameTableStore
;
11 use MediaWiki\Storage\RevisionStore
;
12 use MediaWiki\Storage\RevisionStoreFactory
;
13 use MediaWiki\Storage\SqlBlobStore
;
14 use MediaWikiTestCase
;
15 use Psr\Log\LoggerInterface
;
16 use Psr\Log\NullLogger
;
18 use Wikimedia\Rdbms\ILBFactory
;
19 use Wikimedia\Rdbms\ILoadBalancer
;
20 use Wikimedia\TestingAccessWrapper
;
22 class RevisionStoreFactoryTest
extends MediaWikiTestCase
{
24 public function testValidConstruction_doesntCauseErrors() {
25 new RevisionStoreFactory(
26 $this->getMockLoadBalancerFactory(),
27 $this->getMockBlobStoreFactory(),
28 $this->getHashWANObjectCache(),
29 $this->getMockCommentStore(),
30 ActorMigration
::newMigration(),
32 $this->getMockLoggerSpi(),
35 $this->assertTrue( true );
38 public function provideWikiIds() {
42 yield
[ 'somewiki', MIGRATION_OLD
, false ];
43 yield
[ 'somewiki', MIGRATION_NEW
, true ];
47 * @dataProvider provideWikiIds
49 public function testGetRevisionStore(
51 $mcrMigrationStage = MIGRATION_OLD
,
52 $contentHandlerUseDb = true
54 $lbFactory = $this->getMockLoadBalancerFactory();
55 $blobStoreFactory = $this->getMockBlobStoreFactory();
56 $cache = $this->getHashWANObjectCache();
57 $commentStore = $this->getMockCommentStore();
58 $actorMigration = ActorMigration
::newMigration();
59 $loggerProvider = $this->getMockLoggerSpi();
61 $factory = new RevisionStoreFactory(
72 $store = $factory->getRevisionStore( $wikiId );
73 $wrapper = TestingAccessWrapper
::newFromObject( $store );
75 // ensure the correct object type is returned
76 $this->assertInstanceOf( RevisionStore
::class, $store );
78 // ensure the RevisionStore is for the given wikiId
79 $this->assertSame( $wikiId, $wrapper->wikiId
);
81 // ensure all other required services are correctly set
82 $this->assertSame( $cache, $wrapper->cache
);
83 $this->assertSame( $commentStore, $wrapper->commentStore
);
84 $this->assertSame( $mcrMigrationStage, $wrapper->mcrMigrationStage
);
85 $this->assertSame( $actorMigration, $wrapper->actorMigration
);
86 $this->assertSame( $contentHandlerUseDb, $store->getContentHandlerUseDB() );
88 $this->assertInstanceOf( ILoadBalancer
::class, $wrapper->loadBalancer
);
89 $this->assertInstanceOf( BlobStore
::class, $wrapper->blobStore
);
90 $this->assertInstanceOf( NameTableStore
::class, $wrapper->contentModelStore
);
91 $this->assertInstanceOf( NameTableStore
::class, $wrapper->slotRoleStore
);
92 $this->assertInstanceOf( LoggerInterface
::class, $wrapper->logger
);
96 * @return \PHPUnit_Framework_MockObject_MockObject|ILoadBalancer
98 private function getMockLoadBalancer() {
99 return $this->getMockBuilder( ILoadBalancer
::class )
100 ->disableOriginalConstructor()->getMock();
104 * @return \PHPUnit_Framework_MockObject_MockObject|ILBFactory
106 private function getMockLoadBalancerFactory() {
107 $mock = $this->getMockBuilder( ILBFactory
::class )
108 ->disableOriginalConstructor()->getMock();
110 $mock->method( 'getMainLB' )
111 ->willReturnCallback( function () {
112 return $this->getMockLoadBalancer();
119 * @return \PHPUnit_Framework_MockObject_MockObject|SqlBlobStore
121 private function getMockSqlBlobStore() {
122 return $this->getMockBuilder( SqlBlobStore
::class )
123 ->disableOriginalConstructor()->getMock();
127 * @return \PHPUnit_Framework_MockObject_MockObject|BlobStoreFactory
129 private function getMockBlobStoreFactory() {
130 $mock = $this->getMockBuilder( BlobStoreFactory
::class )
131 ->disableOriginalConstructor()->getMock();
133 $mock->method( 'newSqlBlobStore' )
134 ->willReturnCallback( function () {
135 return $this->getMockSqlBlobStore();
142 * @return \PHPUnit_Framework_MockObject_MockObject|CommentStore
144 private function getMockCommentStore() {
145 return $this->getMockBuilder( CommentStore
::class )
146 ->disableOriginalConstructor()->getMock();
149 private function getHashWANObjectCache() {
150 return new WANObjectCache( [ 'cache' => new \
HashBagOStuff() ] );
154 * @return \PHPUnit_Framework_MockObject_MockObject|LoggerSpi
156 private function getMockLoggerSpi() {
157 $mock = $this->getMock( LoggerSpi
::class );
159 $mock->method( 'getLogger' )
160 ->willReturn( new NullLogger() );