wiki.techinc.nl/tests/phpunit/unit/includes/parser/ParserCacheFactoryTest.php
Derick Alangi 483321e601 parser: Remove explicit StatsdDataFactory backward-compat logic
This is a follow-up to: I0b683461212a357c7eb09ddec59c87539e323c65
and I40a8372a76f33c5f62ea73bb1180dd7c47412c89 which explicitly for
backward compatibility reasons supports IBufferingStatsdDataFactory.

Now that we've fully switched to StatsFactory together with the
`copyToStatsdAt()` method, we're fine to fully remove this `instanceof`
logic.

Bug: T356815
Change-Id: I164d82904b6d3fb575cb973c14f9454569bf09ac
2024-03-26 22:53:58 +00:00

77 lines
2.1 KiB
PHP

<?php
namespace MediaWiki\Tests\Parser;
use HashBagOStuff;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Json\JsonCodec;
use MediaWiki\MainConfigNames;
use MediaWiki\MainConfigSchema;
use MediaWiki\Page\WikiPageFactory;
use MediaWiki\Parser\ParserCacheFactory;
use MediaWiki\Parser\RevisionOutputCache;
use MediaWiki\Title\TitleFactory;
use MediaWikiUnitTestCase;
use ParserCache;
use Psr\Log\NullLogger;
use WANObjectCache;
use Wikimedia\Stats\StatsFactory;
use Wikimedia\UUID\GlobalIdGenerator;
/**
* @covers \MediaWiki\Parser\ParserCacheFactory
*/
class ParserCacheFactoryTest extends MediaWikiUnitTestCase {
/**
* @return ParserCacheFactory
*/
private function newParserCacheFactory() {
$options = new ServiceOptions( ParserCacheFactory::CONSTRUCTOR_OPTIONS, [
MainConfigNames::CacheEpoch => '20200202112233',
MainConfigNames::OldRevisionParserCacheExpireTime => 60,
MainConfigNames::ParserCacheFilterConfig
=> MainConfigSchema::getDefaultValue( MainConfigNames::ParserCacheFilterConfig ),
] );
return new ParserCacheFactory(
new HashBagOStuff(),
new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
$this->createHookContainer(),
new JsonCodec(),
StatsFactory::newNull(),
new NullLogger(),
$options,
$this->createNoOpMock( TitleFactory::class ),
$this->createNoOpMock( WikiPageFactory::class ),
$this->createNoOpMock( GlobalIdGenerator::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 );
}
}