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 = $this->createStub( Context::class );
$context->method( 'msg' ) $context->method( 'msg' )
->withConsecutive( ->willReturnMap( [
[ 'cite-tool-definition.json' ], [ 'cite-tool-definition.json', $msg ],
[ 'visualeditor-cite-tool-definition.json' ], [ 'visualeditor-cite-tool-definition.json', $msg ],
[ 'visualeditor-cite-tool-name-n' ] [ 'visualeditor-cite-tool-name-n', $msg ]
) ] );
->willReturn( $msg );
$context->method( 'encodeJson' )->willReturnCallback( 'json_encode' ); $context->method( 'encodeJson' )->willReturnCallback( 'json_encode' );
return $context; return $context;
} }

View file

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

View file

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

View file

@ -89,7 +89,11 @@ class ErrorReporterTest extends \MediaWikiUnitTestCase {
$parser = $this->createNoOpMock( Parser::class, [ 'addTrackingCategory', 'getOptions', 'recursiveTagParse' ] ); $parser = $this->createNoOpMock( Parser::class, [ 'addTrackingCategory', 'getOptions', 'recursiveTagParse' ] );
$parser->expects( $this->exactly( count( $expectedCategories ) ) ) $parser->expects( $this->exactly( count( $expectedCategories ) ) )
->method( 'addTrackingCategory' ) ->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( 'getOptions' )->willReturn( $parserOptions );
$parser->method( 'recursiveTagParse' )->willReturnCallback( $parser->method( 'recursiveTagParse' )->willReturnCallback(
static function ( $content ) { static function ( $content ) {