MediaWiki  master
RevisionStoreFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
4 
23 
25 
32  $this->getMockBlobStoreFactory(),
33  $this->getNameTableStoreFactory(),
34  $this->getMockSlotRoleRegistry(),
35  $this->getHashWANObjectCache(),
36  $this->getMockCommentStore(),
39  $this->getMockLoggerSpi(),
40  true
41  );
42  $this->assertTrue( true );
43  }
44 
45  public function provideWikiIds() {
46  yield [ true ];
47  yield [ false ];
48  yield [ 'somewiki' ];
49  yield [ 'somewiki', MIGRATION_OLD , false ];
50  yield [ 'somewiki', MIGRATION_NEW , true ];
51  }
52 
57  public function testGetRevisionStore(
58  $wikiId,
59  $mcrMigrationStage = MIGRATION_OLD,
60  $contentHandlerUseDb = true
61  ) {
62  $lbFactory = $this->getMockLoadBalancerFactory();
63  $blobStoreFactory = $this->getMockBlobStoreFactory();
64  $nameTableStoreFactory = $this->getNameTableStoreFactory();
65  $slotRoleRegistry = $this->getMockSlotRoleRegistry();
66  $cache = $this->getHashWANObjectCache();
67  $commentStore = $this->getMockCommentStore();
68  $actorMigration = ActorMigration::newMigration();
69  $loggerProvider = $this->getMockLoggerSpi();
70 
71  $factory = new RevisionStoreFactory(
72  $lbFactory,
73  $blobStoreFactory,
74  $nameTableStoreFactory,
75  $slotRoleRegistry,
76  $cache,
77  $commentStore,
78  $actorMigration,
79  $mcrMigrationStage,
80  $loggerProvider,
81  $contentHandlerUseDb
82  );
83 
84  $store = $factory->getRevisionStore( $wikiId );
85  $wrapper = TestingAccessWrapper::newFromObject( $store );
86 
87  // ensure the correct object type is returned
88  $this->assertInstanceOf( RevisionStore::class, $store );
89 
90  // ensure the RevisionStore is for the given wikiId
91  $this->assertSame( $wikiId, $wrapper->wikiId );
92 
93  // ensure all other required services are correctly set
94  $this->assertSame( $cache, $wrapper->cache );
95  $this->assertSame( $commentStore, $wrapper->commentStore );
96  $this->assertSame( $mcrMigrationStage, $wrapper->mcrMigrationStage );
97  $this->assertSame( $actorMigration, $wrapper->actorMigration );
98  $this->assertSame( $contentHandlerUseDb, $store->getContentHandlerUseDB() );
99 
100  $this->assertInstanceOf( ILoadBalancer::class, $wrapper->loadBalancer );
101  $this->assertInstanceOf( BlobStore::class, $wrapper->blobStore );
102  $this->assertInstanceOf( NameTableStore::class, $wrapper->contentModelStore );
103  $this->assertInstanceOf( NameTableStore::class, $wrapper->slotRoleStore );
104  $this->assertInstanceOf( LoggerInterface::class, $wrapper->logger );
105  }
106 
110  private function getMockLoadBalancer() {
111  return $this->getMockBuilder( ILoadBalancer::class )
112  ->disableOriginalConstructor()->getMock();
113  }
114 
118  private function getMockLoadBalancerFactory() {
119  $mock = $this->getMockBuilder( ILBFactory::class )
120  ->disableOriginalConstructor()->getMock();
121 
122  $mock->method( 'getMainLB' )
123  ->willReturnCallback( function () {
124  return $this->getMockLoadBalancer();
125  } );
126 
127  return $mock;
128  }
129 
133  private function getMockSqlBlobStore() {
134  return $this->getMockBuilder( SqlBlobStore::class )
135  ->disableOriginalConstructor()->getMock();
136  }
137 
141  private function getMockBlobStoreFactory() {
142  $mock = $this->getMockBuilder( BlobStoreFactory::class )
143  ->disableOriginalConstructor()->getMock();
144 
145  $mock->method( 'newSqlBlobStore' )
146  ->willReturnCallback( function () {
147  return $this->getMockSqlBlobStore();
148  } );
149 
150  return $mock;
151  }
152 
156  private function getMockSlotRoleRegistry() {
157  return $this->createMock( SlotRoleRegistry::class );
158  }
159 
163  private function getNameTableStoreFactory() {
164  return new NameTableStoreFactory(
166  $this->getHashWANObjectCache(),
167  new NullLogger() );
168  }
169 
173  private function getMockCommentStore() {
174  return $this->getMockBuilder( CommentStore::class )
175  ->disableOriginalConstructor()->getMock();
176  }
177 
178  private function getHashWANObjectCache() {
179  return new WANObjectCache( [ 'cache' => new \HashBagOStuff() ] );
180  }
181 
185  private function getMockLoggerSpi() {
186  $mock = $this->getMock( LoggerSpi::class );
187 
188  $mock->method( 'getLogger' )
189  ->willReturn( new NullLogger() );
190 
191  return $mock;
192  }
193 
194 }
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Factory service for RevisionStore instances.
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:1982
testGetRevisionStore( $wikiId, $mcrMigrationStage=MIGRATION_OLD, $contentHandlerUseDb=true)
provideWikiIds \MediaWiki\Revision\RevisionStoreFactory::getRevisionStore
static newMigration()
Static constructor.
const MIGRATION_OLD
Definition: Defines.php:311
$cache
Definition: mcc.php:33
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
Definition: distributors.txt:9
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:35
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
const MIGRATION_NEW
Definition: Defines.php:314
testValidConstruction_doesntCauseErrors()
\MediaWiki\Revision\RevisionStoreFactory::__construct