https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen > Given all called methods are de-facto and liberally claimed, and > that we keep the coverage limited to the subject class, it maintains > the spirit and intent by listing the class explicitly instead. > > PHPUnit offers a more precise tool when you need it (i.e. when testing > legacy monster/god classes), but for well-written code, the > class-wide tag is exactly what you want. > > We lose useful coverage and waste valuable time on keeping tags > accurate through refactors (or worse, forget to do so). > Tracking tiny per-method details wastes time in realizing (and > fixing) when people inevitably don't keep them in sync, and time > lost in finding uncovered code to write tests to realize it was > already covered but "not yet claimed". While at it, also fix PHPUnit warnings in CssContentHandlerIntegrationTest and JavaScriptContentHandlerIntegrationTest about not having any `@covers` annotations. Change-Id: I5afd9fe0bca0fa86cc096f6e5e79f2ba1cfbfa77
88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Content\CssContentHandler;
|
|
use MediaWiki\Content\JavaScriptContentHandler;
|
|
use MediaWiki\Content\JsonContentHandler;
|
|
use MediaWiki\Content\TextContentHandler;
|
|
use MediaWiki\MainConfigNames;
|
|
|
|
/**
|
|
* @group ContentHandlerFactory
|
|
* @covers \MediaWiki\MediaWikiServices::getContentHandlerFactory
|
|
*/
|
|
class RegistrationContentHandlerFactoryToMediaWikiServicesTest extends MediaWikiIntegrationTestCase {
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$this->overrideConfigValue(
|
|
MainConfigNames::ContentHandlers,
|
|
[
|
|
CONTENT_MODEL_WIKITEXT => [
|
|
'class' => WikitextContentHandler::class,
|
|
'services' => [
|
|
'TitleFactory',
|
|
'ParserFactory',
|
|
'GlobalIdGenerator',
|
|
'LanguageNameUtils',
|
|
'LinkRenderer',
|
|
'MagicWordFactory',
|
|
'ParsoidParserFactory',
|
|
],
|
|
],
|
|
CONTENT_MODEL_JAVASCRIPT => JavaScriptContentHandler::class,
|
|
CONTENT_MODEL_JSON => JsonContentHandler::class,
|
|
CONTENT_MODEL_CSS => CssContentHandler::class,
|
|
CONTENT_MODEL_TEXT => TextContentHandler::class,
|
|
'testing' => DummyContentHandlerForTesting::class,
|
|
'testing-callbacks' => static function ( $modelId ) {
|
|
return new DummyContentHandlerForTesting( $modelId );
|
|
},
|
|
]
|
|
);
|
|
}
|
|
|
|
public function testCallFromService_get_ok(): void {
|
|
$this->assertInstanceOf(
|
|
\MediaWiki\Content\IContentHandlerFactory::class,
|
|
$this->getServiceContainer()->getContentHandlerFactory()
|
|
);
|
|
|
|
$this->assertSame(
|
|
[
|
|
'wikitext',
|
|
'javascript',
|
|
'json',
|
|
'css',
|
|
'text',
|
|
'testing',
|
|
'testing-callbacks',
|
|
],
|
|
$this->getServiceContainer()->getContentHandlerFactory()->getContentModels()
|
|
);
|
|
}
|
|
|
|
public function testCallFromService_second_same(): void {
|
|
$this->assertSame(
|
|
$this->getServiceContainer()->getContentHandlerFactory(),
|
|
$this->getServiceContainer()->getContentHandlerFactory()
|
|
);
|
|
}
|
|
|
|
public function testCallFromService_afterCustomDefine_same(): void {
|
|
$factory = $this->getServiceContainer()->getContentHandlerFactory();
|
|
$factory->defineContentHandler(
|
|
'model name',
|
|
DummyContentHandlerForTesting::class
|
|
);
|
|
$this->assertTrue(
|
|
$this->getServiceContainer()
|
|
->getContentHandlerFactory()
|
|
->isDefinedModel( 'model name' )
|
|
);
|
|
$this->assertSame(
|
|
$factory,
|
|
$this->getServiceContainer()->getContentHandlerFactory()
|
|
);
|
|
}
|
|
}
|