Merge "Update tests for PHPUnit 9.6"

This commit is contained in:
jenkins-bot 2023-11-22 15:00:02 +00:00 committed by Gerrit Code Review
commit 3462165a56
4 changed files with 20 additions and 15 deletions

View file

@ -33,12 +33,11 @@ class CitationToolDefinitionTest extends \MediaWikiUnitTestCase {
$context = $this->createStub( Context::class );
$context->method( 'msg' )
->withConsecutive(
[ 'cite-tool-definition.json' ],
[ 'visualeditor-cite-tool-definition.json' ],
[ 'visualeditor-cite-tool-name-n' ]
)
->willReturn( $msg );
->willReturnMap( [
[ 'cite-tool-definition.json', $msg ],
[ 'visualeditor-cite-tool-definition.json', $msg ],
[ 'visualeditor-cite-tool-name-n', $msg ]
] );
$context->method( 'encodeJson' )->willReturnCallback( 'json_encode' );
return $context;
}

View file

@ -21,12 +21,13 @@ class CiteParserHooksTest extends \MediaWikiUnitTestCase {
*/
public function testOnParserFirstCallInit() {
$parser = $this->createNoOpMock( Parser::class, [ 'setHook' ] );
$expectedTags = [ 'ref' => true, 'references' => true ];
$parser->expects( $this->exactly( 2 ) )
->method( 'setHook' )
->withConsecutive(
[ 'ref', $this->isType( 'callable' ) ],
[ 'references', $this->isType( 'callable' ) ]
);
->willReturnCallback( function ( $tag ) use ( &$expectedTags ) {
$this->assertArrayHasKey( $tag, $expectedTags );
unset( $expectedTags[$tag] );
} );
$citeParserHooks = new CiteParserHooks();
$citeParserHooks->onParserFirstCallInit( $parser );

View file

@ -20,12 +20,13 @@ class CiteParserTagHooksTest extends \MediaWikiUnitTestCase {
*/
public function testRegister() {
$parser = $this->createNoOpMock( Parser::class, [ 'setHook' ] );
$expectedTags = [ 'ref' => true, 'references' => true ];
$parser->expects( $this->exactly( 2 ) )
->method( 'setHook' )
->withConsecutive(
[ 'ref', $this->isType( 'callable' ) ],
[ 'references', $this->isType( 'callable' ) ]
);
->willReturnCallback( function ( $tag ) use ( &$expectedTags ) {
$this->assertArrayHasKey( $tag, $expectedTags );
unset( $expectedTags[$tag] );
} );
CiteParserTagHooks::register( $parser );
}

View file

@ -89,7 +89,11 @@ class ErrorReporterTest extends \MediaWikiUnitTestCase {
$parser = $this->createNoOpMock( Parser::class, [ 'addTrackingCategory', 'getOptions', 'recursiveTagParse' ] );
$parser->expects( $this->exactly( count( $expectedCategories ) ) )
->method( 'addTrackingCategory' )
->withConsecutive( $expectedCategories );
->willReturnCallback( function ( $cat ) use ( &$expectedCategories ) {
$catIdx = array_search( $cat, $expectedCategories, true );
$this->assertNotFalse( $catIdx, "Unexpected category: $cat" );
unset( $expectedCategories[$catIdx] );
} );
$parser->method( 'getOptions' )->willReturn( $parserOptions );
$parser->method( 'recursiveTagParse' )->willReturnCallback(
static function ( $content ) {