Debian Codegraph @

tests/phpunit/unit/includes/parser/ParserCacheFactoryTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Parser;
4
5 use MediaWiki\Config\ServiceOptions;
6 use MediaWiki\Json\JsonCodec;
7 use MediaWiki\MainConfigNames;
8 use MediaWiki\MainConfigSchema;
9 use MediaWiki\Page\WikiPageFactory;
10 use MediaWiki\Parser\ParserCache;
11 use MediaWiki\Parser\ParserCacheFactory;
12 use MediaWiki\Parser\RevisionOutputCache;
13 use MediaWiki\Title\TitleFactory;
14 use MediaWikiUnitTestCase;
15 use Psr\Log\NullLogger;
16 use Wikimedia\ObjectCache\HashBagOStuff;
17 use Wikimedia\ObjectCache\WANObjectCache;
18 use Wikimedia\Stats\StatsFactory;
19 use Wikimedia\UUID\GlobalIdGenerator;
20
21 /**
22 * @covers \MediaWiki\Parser\ParserCacheFactory
23 */
24 class ParserCacheFactoryTest extends MediaWikiUnitTestCase {
25
26 /**
27 * @return ParserCacheFactory
28 */
29 private function newParserCacheFactory() {
30 $options = new ServiceOptions( ParserCacheFactory::CONSTRUCTOR_OPTIONS, [
31 MainConfigNames::CacheEpoch => '20200202112233',
32 MainConfigNames::OldRevisionParserCacheExpireTime => 60,
33 MainConfigNames::ParserCacheFilterConfig
34 => MainConfigSchema::getDefaultValue( MainConfigNames::ParserCacheFilterConfig ),
35 ] );
36
37 return new ParserCacheFactory(
38 new HashBagOStuff(),
39 new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
40 $this->createHookContainer(),
41 new JsonCodec(),
42 StatsFactory::newNull(),
43 new NullLogger(),
44 $options,
45 $this->createNoOpMock( TitleFactory::class ),
46 $this->createNoOpMock( WikiPageFactory::class ),
47 $this->createNoOpMock( GlobalIdGenerator::class )
48 );
49 }
50
51 public function testGetParserCache() {
52 $factory = $this->newParserCacheFactory();
53
54 $a = $factory->getParserCache( 'test' );
55 $this->assertInstanceOf( ParserCache::class, $a );
56
57 $b = $factory->getParserCache( 'test' );
58 $this->assertSame( $a, $b );
59
60 $c = $factory->getParserCache( 'xyzzy' );
61 $this->assertNotSame( $a, $c );
62 }
63
64 public function testGetRevisionOutputCache() {
65 $factory = $this->newParserCacheFactory();
66
67 $a = $factory->getRevisionOutputCache( 'test' );
68 $this->assertInstanceOf( RevisionOutputCache::class, $a );
69
70 $b = $factory->getRevisionOutputCache( 'test' );
71 $this->assertSame( $a, $b );
72
73 $c = $factory->getRevisionOutputCache( 'xyzzy' );
74 $this->assertNotSame( $a, $c );
75 }
76
77 }