wiki.techinc.nl/tests/phpunit/unit/includes/cache/BacklinkCacheFactoryTest.php
Derick Alangi cb22f7b13b
cache: Dependency inject more args into BacklinkCache
Injecting LinksMigration and ServiceOptions into BacklinkCache.

Change-Id: I2068cccc472e00bc025de771760d289aaaec2831
2023-10-02 19:10:11 +01:00

40 lines
1.2 KiB
PHP

<?php
use MediaWiki\Cache\BacklinkCacheFactory;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Linker\LinksMigration;
use MediaWiki\Page\PageReferenceValue;
use Wikimedia\Rdbms\IConnectionProvider;
/**
* @group Cache
*/
class BacklinkCacheFactoryTest extends MediaWikiUnitTestCase {
/**
* @covers MediaWiki\Cache\BacklinkCacheFactory::getBacklinkCache
*/
public function testGetBacklinkCache() {
$wanCache = new WANObjectCache( [ 'cache' => new EmptyBagOStuff() ] );
$dbProvider = $this->createMock( IConnectionProvider::class );
$page = PageReferenceValue::localReference( NS_CATEGORY, "kittens" );
$factory = new BacklinkCacheFactory(
$this->createMock( ServiceOptions::class ),
$this->createMock( LinksMigration::class ),
$wanCache,
$this->createHookContainer(),
$dbProvider
);
$cache = $factory->getBacklinkCache( $page );
$this->assertTrue( $cache->getPage()->isSamePageAs( $page ) );
$cache2 = $factory->getBacklinkCache( $page );
$this->assertSame( $cache, $cache2 );
$page2 = PageReferenceValue::localReference( NS_CATEGORY, "doggos" );
$cache2 = $factory->getBacklinkCache( $page2 );
$this->assertNotSame( $cache, $cache2 );
$this->assertTrue( $cache2->getPage()->isSamePageAs( $page2 ) );
}
}