From d77b6e99920bf1640b7db7d38e749e993cda47b6 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Mon, 27 Nov 2023 03:13:29 +0100 Subject: [PATCH] Update tests for PHPUnit 9.6 - Avoid withConsecutive() Bug: T342110 Change-Id: I3f07a2f071ddec3f9bbd147b8bfc0d32277203d6 --- tests/phpunit/PopupsGadgetsIntegrationTest.php | 18 ++++++++---------- tests/phpunit/PopupsHooksTest.php | 14 ++++++++++---- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/tests/phpunit/PopupsGadgetsIntegrationTest.php b/tests/phpunit/PopupsGadgetsIntegrationTest.php index 9d6522689..8b30c45bb 100644 --- a/tests/phpunit/PopupsGadgetsIntegrationTest.php +++ b/tests/phpunit/PopupsGadgetsIntegrationTest.php @@ -72,11 +72,10 @@ class PopupsGadgetsIntegrationTest extends MediaWikiIntegrationTestCase { $mock = $this->createMock( Config::class ); $mock->expects( $this->atLeastOnce() ) ->method( 'get' ) - ->withConsecutive( - [ PopupsGadgetsIntegration::CONFIG_NAVIGATION_POPUPS_NAME ], - [ PopupsGadgetsIntegration::CONFIG_REFERENCE_TOOLTIPS_NAME ] - ) - ->willReturn( self::NAV_POPUPS_GADGET_NAME ); + ->willReturnMap( [ + [ PopupsGadgetsIntegration::CONFIG_NAVIGATION_POPUPS_NAME, self::NAV_POPUPS_GADGET_NAME ], + [ PopupsGadgetsIntegration::CONFIG_REFERENCE_TOOLTIPS_NAME, self::NAV_POPUPS_GADGET_NAME ], + ] ); return $mock; } @@ -173,11 +172,10 @@ class PopupsGadgetsIntegrationTest extends MediaWikiIntegrationTestCase { $configMock = $this->createMock( Config::class ); $configMock->expects( $this->atLeastOnce() ) ->method( 'get' ) - ->withConsecutive( - [ PopupsGadgetsIntegration::CONFIG_NAVIGATION_POPUPS_NAME ], - [ PopupsGadgetsIntegration::CONFIG_REFERENCE_TOOLTIPS_NAME ] - ) - ->willReturn( $name ); + ->willReturnMap( [ + [ PopupsGadgetsIntegration::CONFIG_NAVIGATION_POPUPS_NAME, $name ], + [ PopupsGadgetsIntegration::CONFIG_REFERENCE_TOOLTIPS_NAME, $name ] + ] ); $gadgetMock = $this->createMock( Gadget::class ); $gadgetMock->expects( $this->once() ) diff --git a/tests/phpunit/PopupsHooksTest.php b/tests/phpunit/PopupsHooksTest.php index 0985dc927..6fbc24c80 100644 --- a/tests/phpunit/PopupsHooksTest.php +++ b/tests/phpunit/PopupsHooksTest.php @@ -326,12 +326,18 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase { $userMock = $this->createMock( User::class ); $userOptionsManagerMock = $this->createMock( UserOptionsManager::class ); + $expectedOptions = [ + 'popups' => $expectedState, + 'popups-reference-previews' => $expectedState + ]; $userOptionsManagerMock->expects( $this->exactly( $enabled ? 2 : 1 ) ) ->method( 'setOption' ) - ->withConsecutive( - [ $userMock, 'popups', $expectedState ], - [ $userMock, 'popups-reference-previews', $expectedState ] - ); + ->willReturnCallback( function ( $user, $option, $val ) use ( &$expectedOptions, $userMock ) { + $this->assertSame( $userMock, $user ); + $this->assertArrayHasKey( $option, $expectedOptions ); + $this->assertSame( $expectedOptions[$option], $val ); + unset( $expectedOptions[$option] ); + } ); $this->setMwGlobals( [ 'wgPopupsOptInStateForNewAccounts' => $expectedState,