mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 14:36:51 +00:00
More simple and consistent @covers and @license tags
Same arguments as in Iafa2412. The one reason to use more detailled per-method @covers annotations is to avoid "accidental coverage" where code is marked as being covered by tests that don't assert anything that would be meaningful for this code. This is especially a problem with older, bigger classes with lots of side effects. But all the new classes we introduced over the years are small, with predictable, local effects. That's also why we keep the more detailled @covers annotations for the original Cite class. Bug: T353227 Bug: T353269 Change-Id: I69850f4d740d8ad5a7c2368b9068dc91e47cc797
This commit is contained in:
parent
d0d5fbbee6
commit
4377f0923d
|
@ -1,6 +1,14 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset>
|
||||
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki" />
|
||||
|
||||
<rule ref="MediaWiki.Commenting.ClassLevelLicense">
|
||||
<properties>
|
||||
<property name="license" value="GPL-2.0-or-later" />
|
||||
</properties>
|
||||
<exclude-pattern>/src/ResourceLoader/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<file>.</file>
|
||||
<arg name="extensions" value="php" />
|
||||
<arg name="encoding" value="UTF-8" />
|
||||
|
|
|
@ -31,6 +31,9 @@ use MediaWiki\Parser\Sanitizer;
|
|||
use Parser;
|
||||
use StatusValue;
|
||||
|
||||
/**
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class Cite {
|
||||
|
||||
public const DEFAULT_GROUP = '';
|
||||
|
|
|
@ -19,6 +19,7 @@ use MediaWiki\Title\Title;
|
|||
use MediaWiki\User\Options\UserOptionsLookup;
|
||||
|
||||
/**
|
||||
* @license GPL-2.0-or-later
|
||||
* @phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
|
||||
*/
|
||||
class CiteHooks implements
|
||||
|
|
|
@ -9,6 +9,8 @@ use MessageSpecifier;
|
|||
|
||||
/**
|
||||
* Interface abstracts everything a Cite needs to do with languages.
|
||||
*
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class ReferenceMessageLocalizer implements MessageLocalizer {
|
||||
|
||||
|
|
|
@ -5,6 +5,9 @@ namespace Cite;
|
|||
use MediaWiki\Parser\Sanitizer;
|
||||
use StatusValue;
|
||||
|
||||
/**
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class Validator {
|
||||
|
||||
private ReferenceStack $referenceStack;
|
||||
|
|
|
@ -7,6 +7,7 @@ use LanguageQqx;
|
|||
|
||||
/**
|
||||
* @covers \Cite\ReferenceMessageLocalizer
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class ReferenceMessageLocalizerTest extends \MediaWikiIntegrationTestCase {
|
||||
|
||||
|
|
|
@ -9,8 +9,7 @@ use Message;
|
|||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Cite\AnchorFormatter
|
||||
*
|
||||
* @covers \Cite\AnchorFormatter
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class AnchorFormatterTest extends \MediaWikiIntegrationTestCase {
|
||||
|
@ -20,10 +19,6 @@ class AnchorFormatterTest extends \MediaWikiIntegrationTestCase {
|
|||
$this->overrideConfigValue( 'FragmentMode', [ 'html5' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::refKey
|
||||
* @covers ::backLink
|
||||
*/
|
||||
public function testRefKey() {
|
||||
$mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
|
||||
$mockMessageLocalizer->method( 'msg' )->willReturnCallback(
|
||||
|
@ -43,10 +38,6 @@ class AnchorFormatterTest extends \MediaWikiIntegrationTestCase {
|
|||
$formatter->backLink( 'key', '2' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getReferencesKey
|
||||
* @covers ::jumpLink
|
||||
*/
|
||||
public function testGetReferencesKey() {
|
||||
$mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
|
||||
$mockMessageLocalizer->method( 'msg' )->willReturnCallback(
|
||||
|
@ -64,8 +55,6 @@ class AnchorFormatterTest extends \MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::normalizeKey
|
||||
* @covers ::__construct
|
||||
* @dataProvider provideKeyNormalizations
|
||||
*/
|
||||
public function testNormalizeKey( $key, $expected ) {
|
||||
|
|
|
@ -17,7 +17,6 @@ use Wikimedia\TestingAccessWrapper;
|
|||
|
||||
/**
|
||||
* @coversDefaultClass \Cite\Cite
|
||||
*
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class CiteTest extends \MediaWikiIntegrationTestCase {
|
||||
|
|
|
@ -11,13 +11,12 @@ use Parser;
|
|||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Cite\FootnoteMarkFormatter
|
||||
* @covers \Cite\FootnoteMarkFormatter
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class FootnoteMarkFormatterTest extends \MediaWikiIntegrationTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::linkRef
|
||||
* @covers ::__construct
|
||||
* @dataProvider provideLinkRef
|
||||
*/
|
||||
public function testLinkRef( string $group, array $ref, string $expectedOutput ) {
|
||||
|
@ -132,8 +131,6 @@ class FootnoteMarkFormatterTest extends \MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::getLinkLabel
|
||||
*
|
||||
* @dataProvider provideGetLinkLabel
|
||||
*/
|
||||
public function testGetLinkLabel( $expectedLabel, $offset, $group, $labelList ) {
|
||||
|
|
|
@ -9,7 +9,6 @@ use Wikimedia\TestingAccessWrapper;
|
|||
|
||||
/**
|
||||
* @covers \Cite\Validator
|
||||
*
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class ValidatorTest extends \MediaWikiIntegrationTestCase {
|
||||
|
|
|
@ -8,7 +8,6 @@ use Message;
|
|||
|
||||
/**
|
||||
* @covers \Cite\ResourceLoader\CitationToolDefinition
|
||||
*
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class CitationToolDefinitionTest extends \MediaWikiUnitTestCase {
|
||||
|
|
|
@ -8,7 +8,6 @@ use MediaWiki\User\Options\StaticUserOptionsLookup;
|
|||
|
||||
/**
|
||||
* @covers \Cite\Hooks\CiteHooks
|
||||
*
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class CiteHooksUnitTest extends \MediaWikiUnitTestCase {
|
||||
|
|
|
@ -10,15 +10,11 @@ use ParserOutput;
|
|||
use StripState;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Cite\Hooks\CiteParserHooks
|
||||
*
|
||||
* @covers \Cite\Hooks\CiteParserHooks
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class CiteParserHooksTest extends \MediaWikiUnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::onParserFirstCallInit
|
||||
*/
|
||||
public function testOnParserFirstCallInit() {
|
||||
$parser = $this->createNoOpMock( Parser::class, [ 'setHook' ] );
|
||||
$expectedTags = [ 'ref' => true, 'references' => true ];
|
||||
|
@ -33,9 +29,6 @@ class CiteParserHooksTest extends \MediaWikiUnitTestCase {
|
|||
$citeParserHooks->onParserFirstCallInit( $parser );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::onParserClearState
|
||||
*/
|
||||
public function testOnParserClearState() {
|
||||
$parser = $this->createParser();
|
||||
$parser->extCite = $this->createMock( Cite::class );
|
||||
|
@ -46,9 +39,6 @@ class CiteParserHooksTest extends \MediaWikiUnitTestCase {
|
|||
$this->assertObjectNotHasProperty( 'extCite', $parser );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::onParserCloned
|
||||
*/
|
||||
public function testOnParserCloned() {
|
||||
$parser = $this->createParser();
|
||||
$parser->extCite = $this->createMock( Cite::class );
|
||||
|
@ -59,9 +49,6 @@ class CiteParserHooksTest extends \MediaWikiUnitTestCase {
|
|||
$this->assertObjectNotHasProperty( 'extCite', $parser );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::onParserAfterParse
|
||||
*/
|
||||
public function testAfterParseHooks() {
|
||||
$cite = $this->createMock( Cite::class );
|
||||
$cite->expects( $this->once() )
|
||||
|
|
|
@ -9,15 +9,11 @@ use ParserOutput;
|
|||
use PPFrame;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Cite\Hooks\CiteParserTagHooks
|
||||
*
|
||||
* @covers \Cite\Hooks\CiteParserTagHooks
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class CiteParserTagHooksTest extends \MediaWikiUnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::register
|
||||
*/
|
||||
public function testRegister() {
|
||||
$parser = $this->createNoOpMock( Parser::class, [ 'setHook' ] );
|
||||
$expectedTags = [ 'ref' => true, 'references' => true ];
|
||||
|
@ -31,9 +27,6 @@ class CiteParserTagHooksTest extends \MediaWikiUnitTestCase {
|
|||
CiteParserTagHooks::register( $parser );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::ref
|
||||
*/
|
||||
public function testRef_fails() {
|
||||
$cite = $this->createMock( Cite::class );
|
||||
$cite->method( 'ref' )
|
||||
|
@ -48,10 +41,6 @@ class CiteParserTagHooksTest extends \MediaWikiUnitTestCase {
|
|||
$this->assertSame( '<ref></ref>', $html );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::citeForParser
|
||||
* @covers ::ref
|
||||
*/
|
||||
public function testRef() {
|
||||
$cite = $this->createMock( Cite::class );
|
||||
$cite->expects( $this->once() )
|
||||
|
@ -75,9 +64,6 @@ class CiteParserTagHooksTest extends \MediaWikiUnitTestCase {
|
|||
$this->assertSame( '<HTML>', $html );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::references
|
||||
*/
|
||||
public function testReferences_fails() {
|
||||
$cite = $this->createMock( Cite::class );
|
||||
$cite->method( 'references' )
|
||||
|
@ -92,10 +78,6 @@ class CiteParserTagHooksTest extends \MediaWikiUnitTestCase {
|
|||
$this->assertSame( '<references/>', $html );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::citeForParser
|
||||
* @covers ::references
|
||||
*/
|
||||
public function testReferences() {
|
||||
$cite = $this->createMock( Cite::class );
|
||||
$cite->expects( $this->once() )
|
||||
|
|
|
@ -11,7 +11,6 @@ use ParserOptions;
|
|||
|
||||
/**
|
||||
* @covers \Cite\ErrorReporter
|
||||
*
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class ErrorReporterTest extends \MediaWikiUnitTestCase {
|
||||
|
|
|
@ -6,14 +6,11 @@ use Cite\ReferenceMessageLocalizer;
|
|||
use Language;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Cite\ReferenceMessageLocalizer
|
||||
* @covers \Cite\ReferenceMessageLocalizer
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class ReferenceMessageLocalizerUnitTest extends \MediaWikiUnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::localizeSeparators
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testLocalizeSeparators() {
|
||||
$mockLanguage = $this->createNoOpMock( Language::class, [ 'separatorTransformTable' ] );
|
||||
$mockLanguage->method( 'separatorTransformTable' )->willReturn( [ '.' => ',', '0' => '' ] );
|
||||
|
@ -21,9 +18,6 @@ class ReferenceMessageLocalizerUnitTest extends \MediaWikiUnitTestCase {
|
|||
$this->assertSame( '10,0', $messageLocalizer->localizeSeparators( '10.0' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::localizeDigits
|
||||
*/
|
||||
public function testLocalizeDigits() {
|
||||
$mockLanguage = $this->createNoOpMock( Language::class, [ 'formatNumNoSeparators' ] );
|
||||
$mockLanguage->method( 'formatNumNoSeparators' )->willReturnArgument( 0 );
|
||||
|
|
|
@ -10,16 +10,11 @@ use StripState;
|
|||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Cite\ReferenceStack
|
||||
*
|
||||
* @covers \Cite\ReferenceStack
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::pushInvalidRef
|
||||
*/
|
||||
public function testPushInvalidRef() {
|
||||
$stack = $this->newStack();
|
||||
|
||||
|
@ -29,7 +24,6 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::pushRef
|
||||
* @dataProvider providePushRef
|
||||
*/
|
||||
public function testPushRefs(
|
||||
|
@ -824,8 +818,6 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::rollbackRefs
|
||||
* @covers ::rollbackRef
|
||||
* @dataProvider provideRollbackRefs
|
||||
*/
|
||||
public function testRollbackRefs(
|
||||
|
@ -982,9 +974,6 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::rollbackRef
|
||||
*/
|
||||
public function testRollbackRefs_extends() {
|
||||
$stack = $this->newStack();
|
||||
|
||||
|
@ -1003,9 +992,6 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
$this->assertSame( 0, $stack->extendsCount['foo']['a'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::popGroup
|
||||
*/
|
||||
public function testRemovals() {
|
||||
$stack = $this->newStack();
|
||||
$stack->refs = [ 'group1' => [], 'group2' => [] ];
|
||||
|
@ -1014,9 +1000,6 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
$this->assertSame( [ 'group2' => [] ], $stack->refs );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getGroups
|
||||
*/
|
||||
public function testGetGroups() {
|
||||
$stack = $this->newStack();
|
||||
$stack->refs = [ 'havenot' => [], 'have' => [ [ 'ref etc' ] ] ];
|
||||
|
@ -1024,9 +1007,6 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
$this->assertSame( [ 'have' ], $stack->getGroups() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::hasGroup
|
||||
*/
|
||||
public function testHasGroup() {
|
||||
$stack = $this->newStack();
|
||||
$stack->refs = [ 'present' => [ [ 'ref etc' ] ], 'empty' => [] ];
|
||||
|
@ -1036,9 +1016,6 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
$this->assertFalse( $stack->hasGroup( 'empty' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getGroupRefs
|
||||
*/
|
||||
public function testGetGroupRefs() {
|
||||
$stack = $this->newStack();
|
||||
$stack->refs = [ 'present' => [ [ 'ref etc' ] ], 'empty' => [] ];
|
||||
|
@ -1048,9 +1025,6 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
$this->assertSame( [], $stack->getGroupRefs( 'empty' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::appendText
|
||||
*/
|
||||
public function testAppendText() {
|
||||
$stack = $this->newStack();
|
||||
|
||||
|
|
|
@ -11,16 +11,12 @@ use Parser;
|
|||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Cite\ReferencesFormatter
|
||||
*
|
||||
* @covers \Cite\ReferencesFormatter
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class ReferencesFormatterTest extends \MediaWikiUnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::formatReferences
|
||||
* @covers ::formatRefsList
|
||||
* @dataProvider provideFormatReferences
|
||||
*/
|
||||
public function testFormatReferences( array $refs, string $expectedOutput ) {
|
||||
|
@ -160,7 +156,6 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::closeIndention
|
||||
* @dataProvider provideCloseIndention
|
||||
*/
|
||||
public function testCloseIndention( $closingLi, $expectedOutput ) {
|
||||
|
@ -184,7 +179,6 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::formatListItem
|
||||
* @dataProvider provideFormatListItem
|
||||
*/
|
||||
public function testFormatListItem(
|
||||
|
@ -290,7 +284,6 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::referenceText
|
||||
* @dataProvider provideReferenceText
|
||||
*/
|
||||
public function testReferenceText(
|
||||
|
@ -346,7 +339,6 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::referencesFormatEntryAlternateBacklinkLabel
|
||||
* @dataProvider provideReferencesFormatEntryAlternateBacklinkLabel
|
||||
*/
|
||||
public function testReferencesFormatEntryAlternateBacklinkLabel(
|
||||
|
@ -386,7 +378,6 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::referencesFormatEntryNumericBacklinkLabel
|
||||
* @dataProvider provideReferencesFormatEntryNumericBacklinkLabel
|
||||
*/
|
||||
public function testReferencesFormatEntryNumericBacklinkLabel(
|
||||
|
@ -416,7 +407,6 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::listToText
|
||||
* @dataProvider provideLists
|
||||
*/
|
||||
public function testListToText( array $list, $expected ) {
|
||||
|
|
Loading…
Reference in a new issue