Avoid DB access in tests when possible

Use mocks where that makes sense, and add `@group Database` otherwise.

Change-Id: I8f8ec8f4b2c73066cc8e7a6f8e38b3fc286a1070
This commit is contained in:
Daimona Eaytoy 2023-07-17 20:09:54 +02:00
parent b3c74b1412
commit 0d8422a569
2 changed files with 11 additions and 4 deletions

View file

@ -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() );

View file

@ -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 {