mediawiki-extensions-Gadgets/tests/phpunit/GadgetTestTrait.php
Umherirrender f6b16d34de Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Ib342f7315b331c18b3f7d9e3c22ff3e4d5d8c7f2
2024-10-20 01:15:50 +02:00

41 lines
1.2 KiB
PHP

<?php
use MediaWiki\Extension\Gadgets\Gadget;
use MediaWiki\Extension\Gadgets\GadgetResourceLoaderModule;
use MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo;
use MediaWiki\Revision\RevisionLookup;
use Wikimedia\ObjectCache\HashBagOStuff;
use Wikimedia\ObjectCache\WANObjectCache;
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 );
$srvCache = new HashBagOStuff();
$repo = new MediaWikiGadgetsDefinitionRepo( $dbProvider, $wanCache, $revLookup, $srvCache );
return $repo->newFromDefinition( $line, 'misc' );
}
public function makeGadgetModule( Gadget $g ) {
$module = TestingAccessWrapper::newFromObject(
new GadgetResourceLoaderModule( [ 'id' => null ] )
);
$module->gadget = $g;
return $module;
}
}