MediaWiki REL1_32
RevisionStoreFactoryTest.php
Go to the documentation of this file.
1<?php
2
4
7use MediaWiki\Logger\Spi as LoggerSpi;
16use Psr\Log\LoggerInterface;
17use Psr\Log\NullLogger;
21use Wikimedia\TestingAccessWrapper;
22
24
30 $this->getHashWANObjectCache(),
31 $this->getMockCommentStore(),
34 $this->getMockLoggerSpi(),
35 true
36 );
37 $this->assertTrue( true );
38 }
39
40 public function provideWikiIds() {
41 yield [ true ];
42 yield [ false ];
43 yield [ 'somewiki' ];
44 yield [ 'somewiki', MIGRATION_OLD , false ];
45 yield [ 'somewiki', MIGRATION_NEW , true ];
46 }
47
51 public function testGetRevisionStore(
52 $wikiId,
53 $mcrMigrationStage = MIGRATION_OLD,
54 $contentHandlerUseDb = true
55 ) {
56 $lbFactory = $this->getMockLoadBalancerFactory();
57 $blobStoreFactory = $this->getMockBlobStoreFactory();
58 $nameTableStoreFactory = $this->getNameTableStoreFactory();
60 $commentStore = $this->getMockCommentStore();
61 $actorMigration = ActorMigration::newMigration();
62 $loggerProvider = $this->getMockLoggerSpi();
63
64 $factory = new RevisionStoreFactory(
65 $lbFactory,
66 $blobStoreFactory,
67 $nameTableStoreFactory,
68 $cache,
69 $commentStore,
70 $actorMigration,
71 $mcrMigrationStage,
72 $loggerProvider,
73 $contentHandlerUseDb
74 );
75
76 $store = $factory->getRevisionStore( $wikiId );
77 $wrapper = TestingAccessWrapper::newFromObject( $store );
78
79 // ensure the correct object type is returned
80 $this->assertInstanceOf( RevisionStore::class, $store );
81
82 // ensure the RevisionStore is for the given wikiId
83 $this->assertSame( $wikiId, $wrapper->wikiId );
84
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() );
91
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 );
97 }
98
102 private function getMockLoadBalancer() {
103 return $this->getMockBuilder( ILoadBalancer::class )
104 ->disableOriginalConstructor()->getMock();
105 }
106
110 private function getMockLoadBalancerFactory() {
111 $mock = $this->getMockBuilder( ILBFactory::class )
112 ->disableOriginalConstructor()->getMock();
113
114 $mock->method( 'getMainLB' )
115 ->willReturnCallback( function () {
116 return $this->getMockLoadBalancer();
117 } );
118
119 return $mock;
120 }
121
125 private function getMockSqlBlobStore() {
126 return $this->getMockBuilder( SqlBlobStore::class )
127 ->disableOriginalConstructor()->getMock();
128 }
129
133 private function getMockBlobStoreFactory() {
134 $mock = $this->getMockBuilder( BlobStoreFactory::class )
135 ->disableOriginalConstructor()->getMock();
136
137 $mock->method( 'newSqlBlobStore' )
138 ->willReturnCallback( function () {
139 return $this->getMockSqlBlobStore();
140 } );
141
142 return $mock;
143 }
144
148 private function getNameTableStoreFactory() {
149 return new NameTableStoreFactory(
151 $this->getHashWANObjectCache(),
152 new NullLogger() );
153 }
154
158 private function getMockCommentStore() {
159 return $this->getMockBuilder( CommentStore::class )
160 ->disableOriginalConstructor()->getMock();
161 }
162
163 private function getHashWANObjectCache() {
164 return new WANObjectCache( [ 'cache' => new \HashBagOStuff() ] );
165 }
166
170 private function getMockLoggerSpi() {
171 $mock = $this->getMock( LoggerSpi::class );
172
173 $mock->method( 'getLogger' )
174 ->willReturn( new NullLogger() );
175
176 return $mock;
177 }
178
179}
This class handles the logic for the actor table migration.
static newMigration()
Static constructor.
CommentStore handles storage of comments (edit summaries, log reasons, etc) in the database.
Simple store for keeping values in an associative array for the current process.
Factory service for RevisionStore instances.
Service for looking up page revisions.
Service for instantiating BlobStores.
Service for storing and loading Content objects.
testGetRevisionStore( $wikiId, $mcrMigrationStage=MIGRATION_OLD, $contentHandlerUseDb=true)
provideWikiIds
Multi-datacenter aware caching interface.
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:2055
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
const MIGRATION_NEW
Definition Defines.php:318
const MIGRATION_OLD
Definition Defines.php:315
Service provider interface for \Psr\Log\LoggerInterface implementation libraries.
Definition Spi.php:36
Service for loading and storing data blobs.
Definition BlobStore.php:33
An interface for generating database load balancers.
Database cluster connection, tracking, load balancing, and transaction manager interface.
$cache
Definition mcc.php:33