From 0d8422a569ae66933f2468a340b6321c09c83256 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Mon, 17 Jul 2023 20:09:54 +0200 Subject: [PATCH] Avoid DB access in tests when possible Use mocks where that makes sense, and add `@group Database` otherwise. Change-Id: I8f8ec8f4b2c73066cc8e7a6f8e38b3fc286a1070 --- tests/phpunit/integration/Push/PushNotifierTest.php | 10 +++++++--- tests/phpunit/integration/Push/UtilsTest.php | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/integration/Push/PushNotifierTest.php b/tests/phpunit/integration/Push/PushNotifierTest.php index 117975a74..a6d6343d6 100644 --- a/tests/phpunit/integration/Push/PushNotifierTest.php +++ b/tests/phpunit/integration/Push/PushNotifierTest.php @@ -2,16 +2,20 @@ use MediaWiki\Extension\Notifications\Push\NotificationRequestJob; use MediaWiki\Extension\Notifications\Push\PushNotifier; -use MediaWiki\Extension\Notifications\Push\Utils; use Wikimedia\TestingAccessWrapper; /** @covers \MediaWiki\Extension\Notifications\Push\PushNotifier */ class PushNotifierTest extends MediaWikiIntegrationTestCase { public function testCreateJob(): void { + $user = $this->createMock( User::class ); + $centralId = 42; + $centralIdLookup = $this->createMock( CentralIdLookup::class ); + $centralIdLookup->method( 'centralIdFromLocalUser' ) + ->with( $user ) + ->willReturn( 42 ); + $this->setService( 'CentralIdLookup', $centralIdLookup ); $notifier = TestingAccessWrapper::newFromClass( PushNotifier::class ); - $user = $this->getTestUser()->getUser(); - $centralId = Utils::getPushUserId( $user ); $job = $notifier->createJob( $user ); $this->assertInstanceOf( NotificationRequestJob::class, $job ); $this->assertSame( 'EchoPushNotificationRequest', $job->getType() ); diff --git a/tests/phpunit/integration/Push/UtilsTest.php b/tests/phpunit/integration/Push/UtilsTest.php index 0ec5e1388..3840558c7 100644 --- a/tests/phpunit/integration/Push/UtilsTest.php +++ b/tests/phpunit/integration/Push/UtilsTest.php @@ -2,7 +2,10 @@ use MediaWiki\Extension\Notifications\Push\Utils; -/** @covers \MediaWiki\Extension\Notifications\Push\Utils */ +/** + * @covers \MediaWiki\Extension\Notifications\Push\Utils + * @group Database + */ class UtilsTest extends MediaWikiIntegrationTestCase { public function testGetLoggedInPushId(): void {