mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-24 06:54:00 +00:00
Replace all Language and Parser mocks with no-op mocks
Both Language and Parser are extremely complex classes with hundreds of public methods. We really want to make sure we are not depending on anything unexpected from these classes. If calls are made into these classes we want to know exactly what is called. Doing this also showed that some mocked methods are not even needed. Change-Id: Icdfff6c07be78a47bf7cadb1813a72581a51272a
This commit is contained in:
parent
df5484ea25
commit
2aa421a021
|
@ -57,8 +57,8 @@ class CiteIntegrationTest extends \MediaWikiIntegrationTestCase {
|
|||
$spy->referencesFormatter = $referencesFormatter;
|
||||
$spy->isSectionPreview = $isSectionPreview;
|
||||
|
||||
$output = $cite->checkRefsNoReferences(
|
||||
$this->createMock( Parser::class ), $isSectionPreview );
|
||||
$parser = $this->createNoOpMock( Parser::class );
|
||||
$output = $cite->checkRefsNoReferences( $parser, $isSectionPreview );
|
||||
$this->assertSame( $expectedOutput, $output );
|
||||
}
|
||||
|
||||
|
@ -92,15 +92,15 @@ class CiteIntegrationTest extends \MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
private function newCite(): Cite {
|
||||
$language = $this->createNoOpMock( Language::class );
|
||||
|
||||
$mockOptions = $this->createMock( ParserOptions::class );
|
||||
$mockOptions->method( 'getIsPreview' )->willReturn( false );
|
||||
$mockOptions->method( 'getIsSectionPreview' )->willReturn( false );
|
||||
$mockOptions->method( 'getUserLangObj' )->willReturn(
|
||||
$this->createMock( Language::class ) );
|
||||
$mockParser = $this->createMock( Parser::class );
|
||||
|
||||
$mockParser = $this->createNoOpMock( Parser::class, [ 'getOptions', 'getContentLanguage' ] );
|
||||
$mockParser->method( 'getOptions' )->willReturn( $mockOptions );
|
||||
$mockParser->method( 'getContentLanguage' )->willReturn(
|
||||
$this->createMock( Language::class ) );
|
||||
$mockParser->method( 'getContentLanguage' )->willReturn( $language );
|
||||
return new Cite( $mockParser );
|
||||
}
|
||||
|
||||
|
|
|
@ -384,7 +384,7 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
|
|||
global $wgCiteResponsiveReferences;
|
||||
$wgCiteResponsiveReferences = false;
|
||||
|
||||
$parser = $this->createMock( Parser::class );
|
||||
$parser = $this->createNoOpMock( Parser::class, [ 'recursiveTagParse' ] );
|
||||
|
||||
$cite = $this->newCite();
|
||||
/** @var Cite $spy */
|
||||
|
@ -479,7 +479,7 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
|
|||
array $expectedRefs,
|
||||
bool $isSectionPreview = false
|
||||
) {
|
||||
$mockParser = $this->createMock( Parser::class );
|
||||
$mockParser = $this->createNoOpMock( Parser::class, [ 'getStripState' ] );
|
||||
$mockParser->method( 'getStripState' )
|
||||
->willReturn( $this->createMock( StripState::class ) );
|
||||
|
||||
|
@ -658,10 +658,8 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
|
|||
->method( 'setPageProperty' )
|
||||
->with( Cite::BOOK_REF_PROPERTY, '' );
|
||||
|
||||
$mockParser = $this->createMock( Parser::class );
|
||||
$mockParser = $this->createNoOpMock( Parser::class, [ 'getOutput' ] );
|
||||
$mockParser->method( 'getOutput' )->willReturn( $mockOutput );
|
||||
$mockParser->method( 'getStripState' )
|
||||
->willReturn( $this->createMock( StripState::class ) );
|
||||
|
||||
$cite = $this->newCite();
|
||||
/** @var Cite $spy */
|
||||
|
@ -675,12 +673,14 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
|
|||
* @coversNothing
|
||||
*/
|
||||
public function testReferencesSectionPreview() {
|
||||
$language = $this->createNoOpMock( Language::class );
|
||||
|
||||
$parserOptions = $this->createMock( ParserOptions::class );
|
||||
$parserOptions->method( 'getIsSectionPreview' )->willReturn( true );
|
||||
|
||||
$parser = $this->createMock( Parser::class );
|
||||
$parser = $this->createNoOpMock( Parser::class, [ 'getOptions', 'getContentLanguage' ] );
|
||||
$parser->method( 'getOptions' )->willReturn( $parserOptions );
|
||||
$parser->method( 'getContentLanguage' )->willReturn( $this->createMock( Language::class ) );
|
||||
$parser->method( 'getContentLanguage' )->willReturn( $language );
|
||||
|
||||
/** @var Cite $cite */
|
||||
$cite = TestingAccessWrapper::newFromObject( new Cite( $parser ) );
|
||||
|
@ -703,15 +703,14 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
private function newCite( bool $isSectionPreview = false ): Cite {
|
||||
$language = $this->createNoOpMock( Language::class, [ '__debugInfo' ] );
|
||||
|
||||
$mockOptions = $this->createMock( ParserOptions::class );
|
||||
$mockOptions->method( 'getIsPreview' )->willReturn( false );
|
||||
$mockOptions->method( 'getIsSectionPreview' )->willReturn( $isSectionPreview );
|
||||
$mockOptions->method( 'getUserLangObj' )->willReturn(
|
||||
$this->createMock( Language::class ) );
|
||||
$mockParser = $this->createMock( Parser::class );
|
||||
|
||||
$mockParser = $this->createNoOpMock( Parser::class, [ 'getOptions', 'getContentLanguage' ] );
|
||||
$mockParser->method( 'getOptions' )->willReturn( $mockOptions );
|
||||
$mockParser->method( 'getContentLanguage' )->willReturn(
|
||||
$this->createMock( Language::class ) );
|
||||
$mockParser->method( 'getContentLanguage' )->willReturn( $language );
|
||||
return new Cite( $mockParser );
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ class FootnoteMarkFormatterTest extends \MediaWikiIntegrationTestCase {
|
|||
return $msg;
|
||||
}
|
||||
);
|
||||
$mockParser = $this->createMock( Parser::class );
|
||||
$mockParser = $this->createNoOpMock( Parser::class, [ 'recursiveTagParse' ] );
|
||||
$mockParser->method( 'recursiveTagParse' )->willReturnArgument( 0 );
|
||||
$formatter = new FootnoteMarkFormatter(
|
||||
$mockErrorReporter,
|
||||
|
@ -167,8 +167,8 @@ class FootnoteMarkFormatterTest extends \MediaWikiIntegrationTestCase {
|
|||
$mockMessageLocalizer
|
||||
) );
|
||||
|
||||
$output = $formatter->getLinkLabel(
|
||||
$this->createMock( Parser::class ), $group, $offset );
|
||||
$parser = $this->createNoOpMock( Parser::class );
|
||||
$output = $formatter->getLinkLabel( $parser, $group, $offset );
|
||||
$this->assertSame( $expectedLabel, $output );
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ class CiteParserHooksTest extends \MediaWikiUnitTestCase {
|
|||
* @covers ::onParserFirstCallInit
|
||||
*/
|
||||
public function testOnParserFirstCallInit() {
|
||||
$parser = $this->createMock( Parser::class );
|
||||
$parser = $this->createNoOpMock( Parser::class, [ 'setHook' ] );
|
||||
$parser->expects( $this->exactly( 2 ) )
|
||||
->method( 'setHook' )
|
||||
->withConsecutive(
|
||||
|
|
|
@ -19,7 +19,7 @@ class CiteParserTagHooksTest extends \MediaWikiUnitTestCase {
|
|||
* @covers ::register
|
||||
*/
|
||||
public function testRegister() {
|
||||
$parser = $this->createMock( Parser::class );
|
||||
$parser = $this->createNoOpMock( Parser::class, [ 'setHook' ] );
|
||||
$parser->expects( $this->exactly( 2 ) )
|
||||
->method( 'setHook' )
|
||||
->withConsecutive(
|
||||
|
|
|
@ -60,7 +60,7 @@ class ErrorReporterTest extends \MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
private function createLanguage(): Language {
|
||||
$language = $this->createMock( Language::class );
|
||||
$language = $this->createNoOpMock( Language::class, [ 'getDir', 'getHtmlCode' ] );
|
||||
$language->method( 'getDir' )->willReturn( 'rtl' );
|
||||
$language->method( 'getHtmlCode' )->willReturn( 'qqx' );
|
||||
return $language;
|
||||
|
@ -86,7 +86,7 @@ class ErrorReporterTest extends \MediaWikiUnitTestCase {
|
|||
$parserOptions = $this->createMock( ParserOptions::class );
|
||||
$parserOptions->method( 'getUserLangObj' )->willReturn( $language );
|
||||
|
||||
$parser = $this->createMock( Parser::class );
|
||||
$parser = $this->createNoOpMock( Parser::class, [ 'addTrackingCategory', 'getOptions', 'recursiveTagParse' ] );
|
||||
$parser->expects( $this->exactly( count( $expectedCategories ) ) )
|
||||
->method( 'addTrackingCategory' )
|
||||
->withConsecutive( $expectedCategories );
|
||||
|
|
|
@ -15,7 +15,7 @@ class ReferenceMessageLocalizerUnitTest extends \MediaWikiUnitTestCase {
|
|||
* @covers ::__construct
|
||||
*/
|
||||
public function testLocalizeSeparators() {
|
||||
$mockLanguage = $this->createMock( Language::class );
|
||||
$mockLanguage = $this->createNoOpMock( Language::class, [ 'separatorTransformTable' ] );
|
||||
$mockLanguage->method( 'separatorTransformTable' )->willReturn( [ '.' => ',', '0' => '' ] );
|
||||
$messageLocalizer = new ReferenceMessageLocalizer( $mockLanguage );
|
||||
$this->assertSame( '10,0', $messageLocalizer->localizeSeparators( '10.0' ) );
|
||||
|
@ -25,7 +25,7 @@ class ReferenceMessageLocalizerUnitTest extends \MediaWikiUnitTestCase {
|
|||
* @covers ::localizeDigits
|
||||
*/
|
||||
public function testLocalizeDigits() {
|
||||
$mockLanguage = $this->createMock( Language::class );
|
||||
$mockLanguage = $this->createNoOpMock( Language::class, [ 'formatNumNoSeparators' ] );
|
||||
$mockLanguage->method( 'formatNumNoSeparators' )->willReturn( 'ה' );
|
||||
$messageLocalizer = new ReferenceMessageLocalizer( $mockLanguage );
|
||||
$this->assertSame( 'ה', $messageLocalizer->localizeDigits( '5' ) );
|
||||
|
|
|
@ -44,7 +44,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
|
||||
for ( $i = 0; $i < count( $refs ); $i++ ) {
|
||||
$result = $stack->pushRef(
|
||||
$this->createMock( Parser::class ),
|
||||
$this->createNoOpMock( Parser::class ),
|
||||
$mockStripState,
|
||||
...$refs[$i]
|
||||
);
|
||||
|
@ -991,7 +991,7 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
|
|||
$mockStripState = $this->createMock( StripState::class );
|
||||
$mockStripState->method( 'unstripBoth' )->willReturnArgument( 0 );
|
||||
$stack->pushRef(
|
||||
$this->createMock( Parser::class ),
|
||||
$this->createNoOpMock( Parser::class ),
|
||||
$mockStripState,
|
||||
'text', [],
|
||||
'foo', null, 'a', null, 'rtl'
|
||||
|
|
|
@ -24,7 +24,7 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase {
|
|||
* @dataProvider provideFormatReferences
|
||||
*/
|
||||
public function testFormatReferences( array $refs, string $expectedOutput ) {
|
||||
$mockParser = $this->createMock( Parser::class );
|
||||
$mockParser = $this->createNoOpMock( Parser::class, [ 'recursiveTagParse' ] );
|
||||
$mockParser->method( 'recursiveTagParse' )->willReturnArgument( 0 );
|
||||
|
||||
$mockErrorReporter = $this->createMock( ErrorReporter::class );
|
||||
|
@ -229,8 +229,8 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase {
|
|||
$mockMessageLocalizer
|
||||
) );
|
||||
|
||||
$output = $formatter->formatListItem(
|
||||
$this->createMock( Parser::class ), $key, $val, false );
|
||||
$parser = $this->createNoOpMock( Parser::class );
|
||||
$output = $formatter->formatListItem( $parser, $key, $val, false );
|
||||
$this->assertSame( $expectedOutput, $output );
|
||||
}
|
||||
|
||||
|
@ -321,8 +321,8 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase {
|
|||
$this->createMock( ReferenceMessageLocalizer::class )
|
||||
) );
|
||||
|
||||
$output = $formatter->referenceText(
|
||||
$this->createMock( Parser::class ), $key, $text, $isSectionPreview );
|
||||
$parser = $this->createNoOpMock( Parser::class );
|
||||
$output = $formatter->referenceText( $parser, $key, $text, $isSectionPreview );
|
||||
$this->assertSame( $expectedOutput, $output );
|
||||
}
|
||||
|
||||
|
@ -384,8 +384,8 @@ class ReferencesFormatterTest extends \MediaWikiUnitTestCase {
|
|||
$mockMessageLocalizer
|
||||
) );
|
||||
|
||||
$label = $formatter->referencesFormatEntryAlternateBacklinkLabel(
|
||||
$this->createMock( Parser::class ), $offset );
|
||||
$parser = $this->createNoOpMock( Parser::class );
|
||||
$label = $formatter->referencesFormatEntryAlternateBacklinkLabel( $parser, $offset );
|
||||
if ( $expectedLabel !== null ) {
|
||||
$this->assertSame( $expectedLabel, $label );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue