Debian Codegraph @

tests/phpunit/unit/includes/Revision/RevisionStoreFactoryTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Unit\Revision;
4
5 use MediaWiki\CommentStore\CommentStore;
6 use MediaWiki\Content\IContentHandlerFactory;
7 use MediaWiki\Page\PageStore;
8 use MediaWiki\Page\PageStoreFactory;
9 use MediaWiki\Revision\RevisionStore;
10 use MediaWiki\Revision\RevisionStoreFactory;
11 use MediaWiki\Revision\SlotRoleRegistry;
12 use MediaWiki\Storage\BlobStore;
13 use MediaWiki\Storage\BlobStoreFactory;
14 use MediaWiki\Storage\NameTableStore;
15 use MediaWiki\Storage\NameTableStoreFactory;
16 use MediaWiki\Storage\SqlBlobStore;
17 use MediaWiki\Title\TitleFactory;
18 use MediaWiki\User\ActorStore;
19 use MediaWiki\User\ActorStoreFactory;
20 use MediaWiki\User\UserIdentityLookup;
21 use MediaWikiUnitTestCase;
22 use PHPUnit\Framework\MockObject\MockObject;
23 use Psr\Log\LoggerInterface;
24 use Psr\Log\NullLogger;
25 use Wikimedia\ObjectCache\HashBagOStuff;
26 use Wikimedia\ObjectCache\WANObjectCache;
27 use Wikimedia\Rdbms\ILBFactory;
28 use Wikimedia\Rdbms\ILoadBalancer;
29 use Wikimedia\TestingAccessWrapper;
30
31 /**
32 * @covers \MediaWiki\Revision\RevisionStoreFactory
33 */
34 class RevisionStoreFactoryTest extends MediaWikiUnitTestCase {
35
36 public function testValidConstruction_doesntCauseErrors() {
37 new RevisionStoreFactory(
38 $this->getMockLoadBalancerFactory(),
39 $this->getMockBlobStoreFactory(),
40 $this->getNameTableStoreFactory(),
41 $this->createMock( SlotRoleRegistry::class ),
42 $this->getHashWANObjectCache(),
43 new HashBagOStuff(),
44 $this->createMock( CommentStore::class ),
45 $this->getMockActorStoreFactory(),
46 new NullLogger(),
47 $this->createMock( IContentHandlerFactory::class ),
48 $this->getPageStoreFactory(),
49 $this->createMock( TitleFactory::class ),
50 $this->createHookContainer()
51 );
52 $this->assertTrue( true );
53 }
54
55 public static function provideWikiIds() {
56 yield [ false ];
57 yield [ 'somewiki' ];
58 }
59
60 /**
61 * @dataProvider provideWikiIds
62 */
63 public function testGetRevisionStore( $wikiId ) {
64 $cache = $this->getHashWANObjectCache();
65 $commentStore = $this->createMock( CommentStore::class );
66
67 $factory = new RevisionStoreFactory(
68 $this->getMockLoadBalancerFactory(),
69 $this->getMockBlobStoreFactory(),
70 $this->getNameTableStoreFactory(),
71 $this->createMock( SlotRoleRegistry::class ),
72 $cache,
73 new HashBagOStuff(),
74 $commentStore,
75 $this->getMockActorStoreFactory(),
76 new NullLogger(),
77 $this->createMock( IContentHandlerFactory::class ),
78 $this->getPageStoreFactory(),
79 $this->createMock( TitleFactory::class ),
80 $this->createHookContainer()
81 );
82
83 $store = $factory->getRevisionStore( $wikiId );
84 $wrapper = TestingAccessWrapper::newFromObject( $store );
85
86 // ensure the correct object type is returned
87 $this->assertInstanceOf( RevisionStore::class, $store );
88
89 // ensure the RevisionStore is for the given wikiId
90 $this->assertSame( $wikiId, $wrapper->wikiId );
91
92 // ensure all other required services are correctly set
93 $this->assertSame( $cache, $wrapper->cache );
94 $this->assertSame( $commentStore, $wrapper->commentStore );
95
96 $this->assertInstanceOf( ILoadBalancer::class, $wrapper->loadBalancer );
97 $this->assertInstanceOf( BlobStore::class, $wrapper->blobStore );
98 $this->assertInstanceOf( NameTableStore::class, $wrapper->contentModelStore );
99 $this->assertInstanceOf( NameTableStore::class, $wrapper->slotRoleStore );
100 $this->assertInstanceOf( LoggerInterface::class, $wrapper->logger );
101 $this->assertInstanceOf( UserIdentityLookup::class, $wrapper->actorStore );
102 }
103
104 /**
105 * @return MockObject|ILBFactory
106 */
107 private function getMockLoadBalancerFactory() {
108 $mock = $this->createMock( ILBFactory::class );
109 $mock->method( 'getMainLB' )
110 ->willReturn( $this->createMock( ILoadBalancer::class ) );
111
112 return $mock;
113 }
114
115 /**
116 * @return MockObject|BlobStoreFactory
117 */
118 private function getMockBlobStoreFactory() {
119 $mock = $this->createMock( BlobStoreFactory::class );
120
121 $mock->method( 'newSqlBlobStore' )
122 ->willReturn( $this->createMock( SqlBlobStore::class ) );
123
124 return $mock;
125 }
126
127 /**
128 * @return PageStoreFactory|MockObject
129 */
130 private function getPageStoreFactory(): PageStoreFactory {
131 $mock = $this->createMock( PageStoreFactory::class );
132
133 $mock->method( 'getPageStore' )
134 ->willReturn( $this->createMock( PageStore::class ) );
135
136 return $mock;
137 }
138
139 /**
140 * @return NameTableStoreFactory
141 */
142 private function getNameTableStoreFactory() {
143 return new NameTableStoreFactory(
144 $this->getMockLoadBalancerFactory(),
145 $this->getHashWANObjectCache(),
146 new NullLogger()
147 );
148 }
149
150 /**
151 * @return WANObjectCache
152 */
153 private function getHashWANObjectCache() {
154 return new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
155 }
156
157 /**
158 * @return ActorStoreFactory|MockObject
159 */
160 private function getMockActorStoreFactory() {
161 $mock = $this->createMock( ActorStoreFactory::class );
162
163 $mock->method( 'getActorStore' )
164 ->willReturn( $this->createMock( ActorStore::class ) );
165
166 return $mock;
167 }
168 }