3 namespace MediaWiki\Tests\Storage
;
7 use MediaWiki\Logger\LoggerFactory
;
8 use MediaWiki\Storage\NameTableStore
;
9 use MediaWiki\Storage\RevisionStore
;
10 use MediaWiki\Storage\RevisionStoreFactory
;
11 use MediaWiki\Storage\SqlBlobStore
;
12 use MediaWikiTestCase
;
14 use Wikimedia\Rdbms\LoadBalancer
;
15 use Wikimedia\TestingAccessWrapper
;
17 class RevisionStoreFactoryTest
extends MediaWikiTestCase
{
19 public function testValidConstruction_doesntCauseErrors() {
20 new RevisionStoreFactory(
21 $this->getMockLoadBalancer(),
22 $this->getMockSqlBlobStore(),
23 $this->getHashWANObjectCache(),
24 $this->getMockCommentStore(),
25 $this->getMockNameTableStore(),
26 $this->getMockNameTableStore(),
28 ActorMigration
::newMigration(),
29 LoggerFactory
::getInstance( 'someInstance' ),
32 $this->assertTrue( true );
35 public function provideWikiIds() {
39 yield
[ 'somewiki', MIGRATION_OLD
, false ];
40 yield
[ 'somewiki', MIGRATION_NEW
, true ];
44 * @dataProvider provideWikiIds
46 public function testGetRevisionStore(
48 $mcrMigrationStage = MIGRATION_OLD
,
49 $contentHandlerUseDb = true
51 $lb = $this->getMockLoadBalancer();
52 $blobStore = $this->getMockSqlBlobStore();
53 $cache = $this->getHashWANObjectCache();
54 $commentStore = $this->getMockCommentStore();
55 $contentModelStore = $this->getMockNameTableStore();
56 $slotRoleStore = $this->getMockNameTableStore();
57 $actorMigration = ActorMigration
::newMigration();
58 $logger = LoggerFactory
::getInstance( 'someInstance' );
60 $factory = new RevisionStoreFactory(
73 $store = $factory->getRevisionStore( $wikiId );
74 $wrapper = TestingAccessWrapper
::newFromObject( $store );
76 // ensure the correct object type is returned
77 $this->assertInstanceOf( RevisionStore
::class, $store );
79 // ensure the RevisionStore is for the given wikiId
80 $this->assertSame( $wikiId, $wrapper->wikiId
);
82 // ensure all other required services are correctly set
83 $this->assertSame( $lb, $wrapper->loadBalancer
);
84 $this->assertSame( $blobStore, $wrapper->blobStore
);
85 $this->assertSame( $cache, $wrapper->cache
);
86 $this->assertSame( $commentStore, $wrapper->commentStore
);
87 $this->assertSame( $contentModelStore, $wrapper->contentModelStore
);
88 $this->assertSame( $slotRoleStore, $wrapper->slotRoleStore
);
89 $this->assertSame( $mcrMigrationStage, $wrapper->mcrMigrationStage
);
90 $this->assertSame( $actorMigration, $wrapper->actorMigration
);
91 $this->assertSame( $logger, $wrapper->logger
);
92 $this->assertSame( $contentHandlerUseDb, $store->getContentHandlerUseDB() );
96 * @return \PHPUnit_Framework_MockObject_MockObject|NameTableStore
98 private function getMockNameTableStore() {
99 return $this->getMockBuilder( NameTableStore
::class )
100 ->disableOriginalConstructor()->getMock();
104 * @return \PHPUnit_Framework_MockObject_MockObject|LoadBalancer
106 private function getMockLoadBalancer() {
107 return $this->getMockBuilder( LoadBalancer
::class )
108 ->disableOriginalConstructor()->getMock();
112 * @return \PHPUnit_Framework_MockObject_MockObject|SqlBlobStore
114 private function getMockSqlBlobStore() {
115 return $this->getMockBuilder( SqlBlobStore
::class )
116 ->disableOriginalConstructor()->getMock();
120 * @return \PHPUnit_Framework_MockObject_MockObject|CommentStore
122 private function getMockCommentStore() {
123 return $this->getMockBuilder( CommentStore
::class )
124 ->disableOriginalConstructor()->getMock();
127 private function getHashWANObjectCache() {
128 return new WANObjectCache( [ 'cache' => new \
HashBagOStuff() ] );