Merge "Simplify ErrorReporter mocks in tests"

This commit is contained in:
jenkins-bot 2024-08-12 09:17:19 +00:00 committed by Gerrit Code Review
commit d056400800
2 changed files with 10 additions and 16 deletions

View file

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

View file

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