Simplify ErrorReporter mocks in tests

In some tests we want to see the message parameters. But not here.
Simply echoing the message key (thats parameter number one) is
enough.

Change-Id: Id9824cbbe944c84c9fd1932b0863ac1b3f232b75
This commit is contained in:
thiemowmde 2024-08-06 09:47:13 +02:00 committed by Thiemo Kreuz (WMDE)
parent e9d8aa1f25
commit f3b732bf93
2 changed files with 10 additions and 16 deletions

View file

@ -135,9 +135,7 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
/** @var Cite $spy */ /** @var Cite $spy */
$spy = TestingAccessWrapper::newFromObject( $cite ); $spy = TestingAccessWrapper::newFromObject( $cite );
$spy->errorReporter = $this->createPartialMock( ErrorReporter::class, [ 'halfParsed' ] ); $spy->errorReporter = $this->createPartialMock( ErrorReporter::class, [ 'halfParsed' ] );
$spy->errorReporter->method( 'halfParsed' )->willReturnCallback( $spy->errorReporter->method( 'halfParsed' )->willReturnArgument( 1 );
static fn ( $parser, ...$args ) => '(' . implode( '|', $args ) . ')'
);
$spy->referenceListFormatter = $this->createMock( ReferenceListFormatter::class ); $spy->referenceListFormatter = $this->createMock( ReferenceListFormatter::class );
$spy->referenceListFormatter->method( 'formatReferences' ) $spy->referenceListFormatter->method( 'formatReferences' )
->with( $parser, [], $expectedResponsive, false ) ->with( $parser, [], $expectedResponsive, false )
@ -195,7 +193,7 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
'expectedRollbackCount' => 0, 'expectedRollbackCount' => 0,
'expectedInReferencesGroup' => '', 'expectedInReferencesGroup' => '',
'expectedResponsive' => false, 'expectedResponsive' => false,
'expectedOutput' => '(cite_error_references_invalid_parameters)', 'expectedOutput' => 'cite_error_references_invalid_parameters',
], ],
'Contains refs (which are broken)' => [ 'Contains refs (which are broken)' => [
'text' => Parser::MARKER_PREFIX . '-ref- and ' . Parser::MARKER_PREFIX . '-notref-', 'text' => Parser::MARKER_PREFIX . '-ref- and ' . Parser::MARKER_PREFIX . '-notref-',
@ -203,7 +201,7 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
'expectedRollbackCount' => 1, 'expectedRollbackCount' => 1,
'expectedInReferencesGroup' => '', 'expectedInReferencesGroup' => '',
'expectedResponsive' => false, 'expectedResponsive' => false,
'expectedOutput' => "references!\n(cite_error_references_no_key)" 'expectedOutput' => "references!\ncite_error_references_no_key"
], ],
]; ];
} }
@ -226,10 +224,8 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
$mockParser->method( 'getStripState' ) $mockParser->method( 'getStripState' )
->willReturn( $this->createMock( StripState::class ) ); ->willReturn( $this->createMock( StripState::class ) );
$errorReporter = $this->createPartialMock( ErrorReporter::class, [ 'halfParsed', 'plain' ] ); $errorReporter = $this->createPartialMock( ErrorReporter::class, [ 'halfParsed' ] );
$errorReporter->method( $this->logicalOr( 'halfParsed', 'plain' ) )->willReturnCallback( $errorReporter->method( 'halfParsed' )->willReturnArgument( 1 );
static fn ( $parser, ...$args ) => '(' . implode( '|', $args ) . ')'
);
$referenceStack = new ReferenceStack(); $referenceStack = new ReferenceStack();
/** @var ReferenceStack $stackSpy */ /** @var ReferenceStack $stackSpy */
@ -337,7 +333,7 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
], ],
'inReferencesGroup' => null, 'inReferencesGroup' => null,
'initialRefs' => [], 'initialRefs' => [],
'expectedOutput' => '(cite_error_ref_too_many_keys)', 'expectedOutput' => 'cite_error_ref_too_many_keys',
'expectedError' => null, 'expectedError' => null,
'expectedRefs' => [] 'expectedRefs' => []
], ],

View file

@ -199,9 +199,7 @@ class ReferenceListFormatterTest extends \MediaWikiUnitTestCase {
string $expectedOutput string $expectedOutput
) { ) {
$mockErrorReporter = $this->createMock( ErrorReporter::class ); $mockErrorReporter = $this->createMock( ErrorReporter::class );
$mockErrorReporter->method( 'plain' )->willReturnCallback( $mockErrorReporter->method( 'plain' )->willReturnArgument( 1 );
static fn ( $parser, ...$args ) => '(' . implode( '|', $args ) . ')'
);
$anchorFormatter = $this->createMock( AnchorFormatter::class ); $anchorFormatter = $this->createMock( AnchorFormatter::class );
$anchorFormatter->method( 'backLink' )->willReturnCallback( $anchorFormatter->method( 'backLink' )->willReturnCallback(
@ -291,9 +289,9 @@ class ReferenceListFormatterTest extends \MediaWikiUnitTestCase {
'expectedOutput' => '(cite_references_link_many|1-5|(cite_references_link_many_format|1+5-0|3.0|' . 'expectedOutput' => '(cite_references_link_many|1-5|(cite_references_link_many_format|1+5-0|3.0|' .
'(cite_references_link_many_format_backlink_labels))' . '(cite_references_link_many_format_backlink_labels))' .
'(cite_references_link_many_sep)(cite_references_link_many_format|1+5-1|3.1|' . '(cite_references_link_many_sep)(cite_references_link_many_format|1+5-1|3.1|' .
'(cite_error_references_no_backlink_label))(cite_references_link_many_and)' . 'cite_error_references_no_backlink_label)(cite_references_link_many_and)' .
'(cite_references_link_many_format|1+5-2|3.2|(cite_error_references_no_backlink_label' . '(cite_references_link_many_format|1+5-2|3.2|cite_error_references_no_backlink_label' .
'))|<span class="reference-text">t</span>' . "\n|)" ')|<span class="reference-text">t</span>' . "\n|)"
], ],
]; ];
} }