Merge "tests: Return FakeResultWrapper from mocked IReadableDatabase::select"

This commit is contained in:
jenkins-bot 2024-04-19 20:42:26 +00:00 committed by Gerrit Code Review
commit 03309bd42d
4 changed files with 14 additions and 10 deletions

View file

@ -3,6 +3,7 @@
use MediaWiki\Extension\Notifications\DbFactory;
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
use MediaWiki\Extension\Notifications\Model\Event;
use Wikimedia\Rdbms\FakeResultWrapper;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\InsertQueryBuilder;
@ -103,7 +104,7 @@ class EventMapperTest extends MediaWikiIntegrationTestCase {
$dbResult += [
'insert' => '',
'insertId' => '',
'select' => '',
'select' => [],
'selectRow' => ''
];
$db = $this->createMock( IDatabase::class );
@ -112,7 +113,7 @@ class EventMapperTest extends MediaWikiIntegrationTestCase {
$db->method( 'insertId' )
->willReturn( $dbResult['insertId'] );
$db->method( 'select' )
->willReturn( $dbResult['select'] );
->willReturn( new FakeResultWrapper( $dbResult['select'] ) );
$db->method( 'selectRow' )
->willReturn( $dbResult['selectRow'] );
$db->method( 'newInsertQueryBuilder' )

View file

@ -5,6 +5,7 @@ use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MediaWiki\Extension\Notifications\Model\Notification;
use MediaWiki\User\User;
use Wikimedia\Rdbms\DeleteQueryBuilder;
use Wikimedia\Rdbms\FakeResultWrapper;
use Wikimedia\Rdbms\IDatabase;
/**
@ -115,7 +116,7 @@ class NotificationMapperTest extends MediaWikiIntegrationTestCase {
$this->setMwGlobals( [ 'wgUpdateRowsPerQuery' => 4 ] );
$mockDb = $this->createMock( IDatabase::class );
$makeResultRows = static function ( $eventIds ) {
return new ArrayIterator( array_map( static function ( $eventId ) {
return new FakeResultWrapper( array_map( static function ( $eventId ) {
return (object)[ 'notification_event' => $eventId ];
}, $eventIds ) );
};
@ -229,7 +230,7 @@ class NotificationMapperTest extends MediaWikiIntegrationTestCase {
protected function mockDb( array $dbResult ) {
$dbResult += [
'insert' => '',
'select' => '',
'select' => [],
'selectRow' => '',
'delete' => ''
];
@ -238,7 +239,7 @@ class NotificationMapperTest extends MediaWikiIntegrationTestCase {
$db->method( 'insert' )
->willReturn( $dbResult['insert'] );
$db->method( 'select' )
->willReturn( $dbResult['select'] );
->willReturn( new FakeResultWrapper( $dbResult['select'] ) );
$db->method( 'delete' )
->willReturn( $dbResult['delete'] );
$db->method( 'selectRow' )

View file

@ -4,6 +4,7 @@ use MediaWiki\Config\HashConfig;
use MediaWiki\Extension\Notifications\DbFactory;
use MediaWiki\Extension\Notifications\Gateway\UserNotificationGateway;
use MediaWiki\User\User;
use Wikimedia\Rdbms\FakeResultWrapper;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\UpdateQueryBuilder;
@ -144,9 +145,9 @@ class UserNotificationGatewayTest extends MediaWikiUnitTestCase {
protected function mockDb( array $dbResult = [] ) {
$dbResult += [
'update' => '',
'select' => '',
'select' => [],
'selectRow' => '',
'selectRowCount' => '',
'selectRowCount' => 0,
];
$db = $this->createMock( IDatabase::class );
$db->method( 'affectedRows' )
@ -154,7 +155,7 @@ class UserNotificationGatewayTest extends MediaWikiUnitTestCase {
$db->method( 'update' )
->willReturn( $dbResult['update'] );
$db->method( 'select' )
->willReturn( $dbResult['select'] );
->willReturn( new FakeResultWrapper( $dbResult['select'] ) );
$db->method( 'selectRow' )
->willReturn( $dbResult['selectRow'] );
$db->method( 'selectRowCount' )

View file

@ -3,6 +3,7 @@
use MediaWiki\Extension\Notifications\DbFactory;
use MediaWiki\Extension\Notifications\Mapper\TargetPageMapper;
use MediaWiki\Extension\Notifications\Model\TargetPage;
use Wikimedia\Rdbms\FakeResultWrapper;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\InsertQueryBuilder;
@ -73,7 +74,7 @@ class TargetPageMapperTest extends MediaWikiUnitTestCase {
$dbResult += [
'insert' => '',
'insertId' => '',
'select' => '',
'select' => [],
'delete' => ''
];
$db = $this->createMock( IDatabase::class );
@ -82,7 +83,7 @@ class TargetPageMapperTest extends MediaWikiUnitTestCase {
$db->method( 'insertId' )
->willReturn( $dbResult['insertId'] );
$db->method( 'select' )
->willReturn( $dbResult['select'] );
->willReturn( new FakeResultWrapper( $dbResult['select'] ) );
$db->method( 'delete' )
->willReturn( $dbResult['delete'] );
$db->method( 'newInsertQueryBuilder' )