From bc193d41a71d056d121a07416baf24df8b8052b4 Mon Sep 17 00:00:00 2001 From: Derick Alangi Date: Mon, 19 Feb 2024 13:11:26 +0300 Subject: [PATCH] PreferencesIntegrationTest: CA will fail on `null` User objects `$this->createMock( User::class )` will return a mock User object with all fields defaulting to null and this will fail when the `onGetPreferences()` hook fires in CA since that gets consumed by `getFormDescriptor()` in PreferencesFactory. This patch changes the mock user object to a test user object and this is fine because it's already an integration test. Bug: T357854 Change-Id: I3d80fc1e59ff00a1a08def41c53d82bc093b6e00 --- tests/phpunit/integration/PreferencesIntegrationTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/phpunit/integration/PreferencesIntegrationTest.php b/tests/phpunit/integration/PreferencesIntegrationTest.php index aaafcf270..818c8449d 100644 --- a/tests/phpunit/integration/PreferencesIntegrationTest.php +++ b/tests/phpunit/integration/PreferencesIntegrationTest.php @@ -3,7 +3,6 @@ namespace MediaWiki\Extension\Math\Tests; use MediaWiki\Title\Title; -use MediaWiki\User\User; use MediaWikiIntegrationTestCase; use RequestContext; @@ -26,7 +25,7 @@ class PreferencesIntegrationTest extends MediaWikiIntegrationTestCase { $context->setTitle( Title::makeTitle( NS_MAIN, 'Dummy' ) ); $allPreferences = $this->getServiceContainer() ->getPreferencesFactory() - ->getFormDescriptor( $this->createMock( User::class ), $context ); + ->getFormDescriptor( $this->getTestUser()->getUser(), $context ); $this->assertArrayHasKey( 'math', $allPreferences ); $mathPrefs = $allPreferences['math']; $this->assertSame( 'radio', $mathPrefs['type'] );