ParserOptions not updated cause they depend on Title::getLanguage implementation. Tests converted to not require a DB anymore. Can't be proper unit tests yet due to globals in ParserOptions and fake time hacks, but exec time does go down from 70 seconds to 9 seconds. Page content model is still emitted in the metrics since it was considered useful. Should be removed when we get something like a page type concept. Change-Id: Ib16fd0b5b87ffc3cb4d21f4aa43d1203cb7206d2
64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Config\ServiceOptions;
|
|
use MediaWiki\Json\JsonCodec;
|
|
use MediaWiki\Page\WikiPageFactory;
|
|
use MediaWiki\Parser\ParserCacheFactory;
|
|
use MediaWiki\Parser\RevisionOutputCache;
|
|
use Psr\Log\NullLogger;
|
|
|
|
/**
|
|
* @covers \MediaWiki\Parser\ParserCacheFactory
|
|
*/
|
|
class ParserCacheFactoryTest extends MediaWikiUnitTestCase {
|
|
|
|
/**
|
|
* @return ParserCacheFactory
|
|
*/
|
|
private function newParserCacheFactory() {
|
|
$options = new ServiceOptions( ParserCacheFactory::CONSTRUCTOR_OPTIONS, [
|
|
'ParserCacheUseJson' => true,
|
|
'CacheEpoch' => '20200202112233',
|
|
'OldRevisionParserCacheExpireTime' => 60,
|
|
] );
|
|
|
|
return new ParserCacheFactory(
|
|
new HashBagOStuff(),
|
|
new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
|
|
$this->createHookContainer(),
|
|
new JsonCodec(),
|
|
new NullStatsdDataFactory(),
|
|
new NullLogger(),
|
|
$options,
|
|
$this->createNoOpMock( TitleFactory::class ),
|
|
$this->createNoOpMock( WikiPageFactory::class )
|
|
);
|
|
}
|
|
|
|
public function testGetParserCache() {
|
|
$factory = $this->newParserCacheFactory();
|
|
|
|
$a = $factory->getParserCache( 'test' );
|
|
$this->assertInstanceOf( ParserCache::class, $a );
|
|
|
|
$b = $factory->getParserCache( 'test' );
|
|
$this->assertSame( $a, $b );
|
|
|
|
$c = $factory->getParserCache( 'xyzzy' );
|
|
$this->assertNotSame( $a, $c );
|
|
}
|
|
|
|
public function testGetRevisionOutputCache() {
|
|
$factory = $this->newParserCacheFactory();
|
|
|
|
$a = $factory->getRevisionOutputCache( 'test' );
|
|
$this->assertInstanceOf( RevisionOutputCache::class, $a );
|
|
|
|
$b = $factory->getRevisionOutputCache( 'test' );
|
|
$this->assertSame( $a, $b );
|
|
|
|
$c = $factory->getRevisionOutputCache( 'xyzzy' );
|
|
$this->assertNotSame( $a, $c );
|
|
}
|
|
|
|
}
|