MediaWiki REL1_32
RevisionStoreFactoryTest.php
Go to the documentation of this file.
1<?php
2
4
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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const MIGRATION_NEW
Definition Defines.php:318
const MIGRATION_OLD
Definition Defines.php:315
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
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
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