From a10765baec32005882ab0a4b4bc7d63a72f26b3f Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Fri, 18 Aug 2023 01:49:26 +0200 Subject: [PATCH] Use real user ID in EchoNotifierTest Echo will at some point try to load the user with the given ID, and will throw an exception if it doesn't exist. The test is currently passing just because we're not properly cleaning DB tables, and the user with ID 1 happens to exist at that point, but it will fail with core change Ie2f1809d. Change-Id: Ie686f4d5c2842e45a6ed564b311bb5d9b0265091 --- tests/phpunit/integration/EchoNotifierTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/integration/EchoNotifierTest.php b/tests/phpunit/integration/EchoNotifierTest.php index 882da8c26..7b2418e44 100644 --- a/tests/phpunit/integration/EchoNotifierTest.php +++ b/tests/phpunit/integration/EchoNotifierTest.php @@ -21,13 +21,13 @@ class EchoNotifierTest extends MediaWikiIntegrationTestCase { '2' => 42, ]; - private function getFilterLookup(): FilterLookup { + private function getFilterLookup( int $userID = null ): FilterLookup { $lookup = $this->createMock( FilterLookup::class ); $lookup->method( 'getFilter' ) - ->willReturnCallback( function ( $filter, $global ) { + ->willReturnCallback( function ( $filter, $global ) use ( $userID ) { + $userID ??= self::USER_IDS[ $global ? "global-$filter" : $filter ] ?? 0; $filterObj = $this->createMock( ExistingFilter::class ); - $filterObj->method( 'getUserID' ) - ->willReturn( self::USER_IDS[ $global ? "global-$filter" : $filter ] ?? 0 ); + $filterObj->method( 'getUserID' )->willReturn( $userID ); return $filterObj; } ); return $lookup; @@ -74,11 +74,11 @@ class EchoNotifierTest extends MediaWikiIntegrationTestCase { * @covers ::notifyForFilter */ public function testNotifyForFilter() { - if ( !class_exists( Event::class ) ) { - $this->markTestSkipped( 'Echo not loaded' ); - } + $this->markTestSkippedIfExtensionNotLoaded( 'Echo' ); + // Use a real user, or Echo will throw an exception. + $user = $this->getTestUser()->getUserIdentity(); $notifier = new EchoNotifier( - $this->getFilterLookup(), + $this->getFilterLookup( $user->getId() ), $this->createMock( ConsequencesRegistry::class ), true );