rdbms: add IDatabase::lockForUpdate() convenience method
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / RevisionStoreFactoryTest.php
1 <?php
2
3 namespace MediaWiki\Tests\Storage;
4
5 use ActorMigration;
6 use CommentStore;
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;
13 use WANObjectCache;
14 use Wikimedia\Rdbms\LoadBalancer;
15 use Wikimedia\TestingAccessWrapper;
16
17 class RevisionStoreFactoryTest extends MediaWikiTestCase {
18
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(),
27 MIGRATION_OLD,
28 ActorMigration::newMigration(),
29 LoggerFactory::getInstance( 'someInstance' ),
30 true
31 );
32 $this->assertTrue( true );
33 }
34
35 public function provideWikiIds() {
36 yield [ true ];
37 yield [ false ];
38 yield [ 'somewiki' ];
39 yield [ 'somewiki', MIGRATION_OLD , false ];
40 yield [ 'somewiki', MIGRATION_NEW , true ];
41 }
42
43 /**
44 * @dataProvider provideWikiIds
45 */
46 public function testGetRevisionStore(
47 $wikiId,
48 $mcrMigrationStage = MIGRATION_OLD,
49 $contentHandlerUseDb = true
50 ) {
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' );
59
60 $factory = new RevisionStoreFactory(
61 $lb,
62 $blobStore,
63 $cache,
64 $commentStore,
65 $contentModelStore,
66 $slotRoleStore,
67 $mcrMigrationStage,
68 $actorMigration,
69 $logger,
70 $contentHandlerUseDb
71 );
72
73 $store = $factory->getRevisionStore( $wikiId );
74 $wrapper = TestingAccessWrapper::newFromObject( $store );
75
76 // ensure the correct object type is returned
77 $this->assertInstanceOf( RevisionStore::class, $store );
78
79 // ensure the RevisionStore is for the given wikiId
80 $this->assertSame( $wikiId, $wrapper->wikiId );
81
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() );
93 }
94
95 /**
96 * @return \PHPUnit_Framework_MockObject_MockObject|NameTableStore
97 */
98 private function getMockNameTableStore() {
99 return $this->getMockBuilder( NameTableStore::class )
100 ->disableOriginalConstructor()->getMock();
101 }
102
103 /**
104 * @return \PHPUnit_Framework_MockObject_MockObject|LoadBalancer
105 */
106 private function getMockLoadBalancer() {
107 return $this->getMockBuilder( LoadBalancer::class )
108 ->disableOriginalConstructor()->getMock();
109 }
110
111 /**
112 * @return \PHPUnit_Framework_MockObject_MockObject|SqlBlobStore
113 */
114 private function getMockSqlBlobStore() {
115 return $this->getMockBuilder( SqlBlobStore::class )
116 ->disableOriginalConstructor()->getMock();
117 }
118
119 /**
120 * @return \PHPUnit_Framework_MockObject_MockObject|CommentStore
121 */
122 private function getMockCommentStore() {
123 return $this->getMockBuilder( CommentStore::class )
124 ->disableOriginalConstructor()->getMock();
125 }
126
127 private function getHashWANObjectCache() {
128 return new WANObjectCache( [ 'cache' => new \HashBagOStuff() ] );
129 }
130
131 }