mediawiki-extensions-Gadgets/tests/phpunit/GadgetTestTrait.php
Siddharth VP 9d05af9df8 Replace uses of deprecated wfGetDB()
Bug: T357642
Change-Id: I868133bca622ad2af851e874b450fe0be53017d2
2024-03-04 18:39:15 +05:30

38 lines
1.1 KiB
PHP

<?php
use MediaWiki\Extension\Gadgets\Gadget;
use MediaWiki\Extension\Gadgets\GadgetResourceLoaderModule;
use MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo;
use MediaWiki\Revision\RevisionLookup;
use Wikimedia\Rdbms\IConnectionProvider;
use Wikimedia\TestingAccessWrapper;
/**
* Utility functions for testing gadgets.
*
* This trait is intended to be used on subclasses of MediaWikiUnitTestCase
* or MediaWikiIntegrationTestCase.
*/
trait GadgetTestTrait {
/**
* @param string $line
* @return Gadget
*/
public function makeGadget( string $line ) {
$dbProvider = $this->createMock( IConnectionProvider::class );
$wanCache = WANObjectCache::newEmpty();
$revLookup = $this->createMock( RevisionLookup::class );
$repo = new MediaWikiGadgetsDefinitionRepo( $dbProvider, $wanCache, $revLookup );
return $repo->newFromDefinition( $line, 'misc' );
}
public function makeGadgetModule( Gadget $g ) {
$module = TestingAccessWrapper::newFromObject(
new GadgetResourceLoaderModule( [ 'id' => null ] )
);
$module->gadget = $g;
return $module;
}
}