Skip to content

Commit 391390b

Browse files
malbertsclaude
andcommitted
tests: return a string from the mocked Parser::recursiveTagParse
MediaWiki master declares Parser::recursiveTagParse() and recursiveTagParseFully() with a `string` return type. The component test mocks stub them with returnArgument(0), echoing the input verbatim. When a component passes a non-string attribute value (a bool or int) to the parser, the mock returns that non-string and PHPUnit's typed mock throws "Return value must be of type string". Cast the echoed value to string so the mocks honour the method's contract. Behaviour is unchanged for string inputs, and the renderErrorMessage mock is left as-is. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 98e3740 commit 391390b

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎tests/phpunit/Unit/CarouselGalleryTest.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public function testToHtml( $imageList, $additionalAttributes, $expectedOutput )
5252
->getMock();
5353
$instance->mParser->expects( $this->any() )
5454
->method( 'recursiveTagParse' )
55-
->will( $this->returnArgument( 0 ) );
55+
->will( $this->returnCallback( function ( $text ) {
56+
return (string)$text;
57+
} ) );
5658

5759
foreach ( $imageList as $imageData ) {
5860
$instance->add( Title::newFromText( $imageData[0] ), $imageData[1], $imageData[2], $imageData[3], $imageData[4] );

‎tests/phpunit/Unit/ComponentsTestBase.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ public function setUp(): void {
5858
$this->parser = $this->createMock( Parser::class );
5959
$this->parser->expects( $this->any() )
6060
->method( 'recursiveTagParse' )
61-
->will( $this->returnArgument( 0 ) );
61+
->will( $this->returnCallback( function ( $text ) {
62+
return (string)$text;
63+
} ) );
6264
$this->parser->expects( $this->any() )
6365
->method( 'recursiveTagParseFully' )
64-
->will( $this->returnArgument( 0 ) );
66+
->will( $this->returnCallback( function ( $text ) {
67+
return (string)$text;
68+
} ) );
6569
$this->parserOutputHelper = $this->createMock( ParserOutputHelper::class );
6670
$this->parserOutputHelper->expects( $this->any() )
6771
->method( 'renderErrorMessage' )

0 commit comments

Comments
 (0)