MediaWiki  1.32.5
RevisionStoreFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
4 
7 use MediaWiki\Logger\Spi as LoggerSpi;
16 use Psr\Log\LoggerInterface;
17 use Psr\Log\NullLogger;
21 use Wikimedia\TestingAccessWrapper;
22 
24 
28  $this->getMockBlobStoreFactory(),
29  $this->getNameTableStoreFactory(),
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();
59  $cache = $this->getHashWANObjectCache();
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 }
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\testGetRevisionStore
testGetRevisionStore( $wikiId, $mcrMigrationStage=MIGRATION_OLD, $contentHandlerUseDb=true)
provideWikiIds
Definition: RevisionStoreFactoryTest.php:51
MediaWiki\Tests\Revision\RevisionStoreFactoryTest
Definition: RevisionStoreFactoryTest.php:23
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getMockLoadBalancer
getMockLoadBalancer()
Definition: RevisionStoreFactoryTest.php:102
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getMockCommentStore
getMockCommentStore()
Definition: RevisionStoreFactoryTest.php:158
HashBagOStuff
Simple store for keeping values in an associative array for the current process.
Definition: HashBagOStuff.php:31
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\testValidConstruction_doesntCauseErrors
testValidConstruction_doesntCauseErrors()
Definition: RevisionStoreFactoryTest.php:25
Revision\RevisionStore
Service for looking up page revisions.
Definition: RevisionStore.php:76
MediaWiki\Storage\SqlBlobStore
Service for storing and loading Content objects.
Definition: SqlBlobStore.php:50
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getMockSqlBlobStore
getMockSqlBlobStore()
Definition: RevisionStoreFactoryTest.php:125
MediaWiki\Tests\Revision
Definition: McrReadNewRevisionStoreDbTest.php:2
MIGRATION_NEW
const MIGRATION_NEW
Definition: Defines.php:318
CommentStore
CommentStore handles storage of comments (edit summaries, log reasons, etc) in the database.
Definition: CommentStore.php:31
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getMockLoadBalancerFactory
getMockLoadBalancerFactory()
Definition: RevisionStoreFactoryTest.php:110
ActorMigration
This class handles the logic for the actor table migration.
Definition: ActorMigration.php:35
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getNameTableStoreFactory
getNameTableStoreFactory()
Definition: RevisionStoreFactoryTest.php:148
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:111
php
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
MediaWikiTestCase
Definition: MediaWikiTestCase.php:16
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getMockBlobStoreFactory
getMockBlobStoreFactory()
Definition: RevisionStoreFactoryTest.php:133
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
MediaWiki\Storage\BlobStoreFactory
Service for instantiating BlobStores.
Definition: BlobStoreFactory.php:35
MIGRATION_OLD
const MIGRATION_OLD
Definition: Defines.php:315
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getHashWANObjectCache
getHashWANObjectCache()
Definition: RevisionStoreFactoryTest.php:163
WANObjectCache
Multi-datacenter aware caching interface.
Definition: WANObjectCache.php:118
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\provideWikiIds
provideWikiIds()
Definition: RevisionStoreFactoryTest.php:40
MediaWiki\Storage\NameTableStore
Definition: NameTableStore.php:35
Revision\RevisionStoreFactory
Factory service for RevisionStore instances.
Definition: RevisionStoreFactory.php:49
MediaWiki\Storage\BlobStore
Service for loading and storing data blobs.
Definition: BlobStore.php:33
$cache
$cache
Definition: mcc.php:33
as
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
true
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:2044
MediaWiki\Storage\NameTableStoreFactory
Definition: NameTableStoreFactory.php:26
class
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
MediaWiki\Logger\Spi
Service provider interface for \Psr\Log\LoggerInterface implementation libraries.
Definition: Spi.php:36
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:78
Wikimedia\Rdbms\ILBFactory
An interface for generating database load balancers.
Definition: ILBFactory.php:33
MediaWiki\Tests\Revision\RevisionStoreFactoryTest\getMockLoggerSpi
getMockLoggerSpi()
Definition: RevisionStoreFactoryTest.php:170