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\NameTableStoreFactory
;
12 use MediaWiki\Storage\RevisionStore
;
13 use MediaWiki\Storage\RevisionStoreFactory
;
14 use MediaWiki\Storage\SqlBlobStore
;
15 use MediaWikiTestCase
;
16 use Psr\Log\LoggerInterface
;
17 use Psr\Log\NullLogger
;
19 use Wikimedia\Rdbms\ILBFactory
;
20 use Wikimedia\Rdbms\ILoadBalancer
;
21 use Wikimedia\TestingAccessWrapper
;
23 class RevisionStoreFactoryTest
extends MediaWikiTestCase
{
25 public function testValidConstruction_doesntCauseErrors() {
26 new RevisionStoreFactory(
27 $this->getMockLoadBalancerFactory(),
28 $this->getMockBlobStoreFactory(),
29 $this->getNameTableStoreFactory(),
30 $this->getHashWANObjectCache(),
31 $this->getMockCommentStore(),
32 ActorMigration
::newMigration(),
34 $this->getMockLoggerSpi(),
37 $this->assertTrue( true );
40 public function provideWikiIds() {
44 yield
[ 'somewiki', MIGRATION_OLD
, false ];
45 yield
[ 'somewiki', MIGRATION_NEW
, true ];
49 * @dataProvider provideWikiIds
51 public function testGetRevisionStore(
53 $mcrMigrationStage = MIGRATION_OLD
,
54 $contentHandlerUseDb = true
56 $lbFactory = $this->getMockLoadBalancerFactory();
57 $blobStoreFactory = $this->getMockBlobStoreFactory();
58 $nameTableStoreFactory = $this->getNameTableStoreFactory();
59 $cache = $this->getHashWANObjectCache();
60 $commentStore = $this->getMockCommentStore();
61 $actorMigration = ActorMigration
::newMigration();
62 $loggerProvider = $this->getMockLoggerSpi();
64 $factory = new RevisionStoreFactory(
67 $nameTableStoreFactory,
76 $store = $factory->getRevisionStore( $wikiId );
77 $wrapper = TestingAccessWrapper
::newFromObject( $store );
79 // ensure the correct object type is returned
80 $this->assertInstanceOf( RevisionStore
::class, $store );
82 // ensure the RevisionStore is for the given wikiId
83 $this->assertSame( $wikiId, $wrapper->wikiId
);
85 // ensure all other required services are correctly set
86 $this->assertSame( $cache, $wrapper->cache
);
87 $this->assertSame( $commentStore, $wrapper->commentStore
);
88 $this->assertSame( $mcrMigrationStage, $wrapper->mcrMigrationStage
);
89 $this->assertSame( $actorMigration, $wrapper->actorMigration
);
90 $this->assertSame( $contentHandlerUseDb, $store->getContentHandlerUseDB() );
92 $this->assertInstanceOf( ILoadBalancer
::class, $wrapper->loadBalancer
);
93 $this->assertInstanceOf( BlobStore
::class, $wrapper->blobStore
);
94 $this->assertInstanceOf( NameTableStore
::class, $wrapper->contentModelStore
);
95 $this->assertInstanceOf( NameTableStore
::class, $wrapper->slotRoleStore
);
96 $this->assertInstanceOf( LoggerInterface
::class, $wrapper->logger
);
100 * @return \PHPUnit_Framework_MockObject_MockObject|ILoadBalancer
102 private function getMockLoadBalancer() {
103 return $this->getMockBuilder( ILoadBalancer
::class )
104 ->disableOriginalConstructor()->getMock();
108 * @return \PHPUnit_Framework_MockObject_MockObject|ILBFactory
110 private function getMockLoadBalancerFactory() {
111 $mock = $this->getMockBuilder( ILBFactory
::class )
112 ->disableOriginalConstructor()->getMock();
114 $mock->method( 'getMainLB' )
115 ->willReturnCallback( function () {
116 return $this->getMockLoadBalancer();
123 * @return \PHPUnit_Framework_MockObject_MockObject|SqlBlobStore
125 private function getMockSqlBlobStore() {
126 return $this->getMockBuilder( SqlBlobStore
::class )
127 ->disableOriginalConstructor()->getMock();
131 * @return \PHPUnit_Framework_MockObject_MockObject|BlobStoreFactory
133 private function getMockBlobStoreFactory() {
134 $mock = $this->getMockBuilder( BlobStoreFactory
::class )
135 ->disableOriginalConstructor()->getMock();
137 $mock->method( 'newSqlBlobStore' )
138 ->willReturnCallback( function () {
139 return $this->getMockSqlBlobStore();
146 * @return NameTableStoreFactory
148 private function getNameTableStoreFactory() {
149 return new NameTableStoreFactory(
150 $this->getMockLoadBalancerFactory(),
151 $this->getHashWANObjectCache(),
156 * @return \PHPUnit_Framework_MockObject_MockObject|CommentStore
158 private function getMockCommentStore() {
159 return $this->getMockBuilder( CommentStore
::class )
160 ->disableOriginalConstructor()->getMock();
163 private function getHashWANObjectCache() {
164 return new WANObjectCache( [ 'cache' => new \
HashBagOStuff() ] );
168 * @return \PHPUnit_Framework_MockObject_MockObject|LoggerSpi
170 private function getMockLoggerSpi() {
171 $mock = $this->getMock( LoggerSpi
::class );
173 $mock->method( 'getLogger' )
174 ->willReturn( new NullLogger() );