From 1278c666730e1fe4bbace53b7661a9560fadb165 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Sun, 7 Apr 2019 21:44:48 +0000 Subject: [PATCH] Mock IDatabase instead of DatabaseMysqli PHPUnit 4 on HHVM is unable to create a mock for a class that uses variadic arguments in one of its methods. Details at I0e027f5ec66 in core. To work around this, IDatabase will continue to document it the old-fashioned way so that Phan can analyse it correctly, and also so that PHPUnit can mock it properly. Change-Id: I4b8f2b8a8bb54b71d8b4836c3663f1a646ece1bd --- tests/phpunit/NotifUserTest.php | 2 +- tests/phpunit/gateway/UserNotificationGatewayTest.php | 4 +--- tests/phpunit/mapper/EventMapperTest.php | 4 +--- tests/phpunit/mapper/NotificationMapperTest.php | 10 +++------- tests/phpunit/mapper/TargetPageMapperTest.php | 4 +--- 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/tests/phpunit/NotifUserTest.php b/tests/phpunit/NotifUserTest.php index 6369df201..1c1908f3e 100644 --- a/tests/phpunit/NotifUserTest.php +++ b/tests/phpunit/NotifUserTest.php @@ -122,7 +122,7 @@ class MWEchoNotifUserTest extends MediaWikiTestCase { $gateway->expects( $this->any() ) ->method( 'getDB' ) ->will( $this->returnValue( - $this->getMockBuilder( Database::class ) + $this->getMockBuilder( IDatabase::class ) ->disableOriginalConstructor()->getMock() ) ); diff --git a/tests/phpunit/gateway/UserNotificationGatewayTest.php b/tests/phpunit/gateway/UserNotificationGatewayTest.php index b22721659..09c205347 100644 --- a/tests/phpunit/gateway/UserNotificationGatewayTest.php +++ b/tests/phpunit/gateway/UserNotificationGatewayTest.php @@ -106,9 +106,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiTestCase { 'selectRow' => '', 'selectRowCount' => '', ]; - $db = $this->getMockBuilder( DatabaseMysqli::class ) - ->disableOriginalConstructor() - ->getMock(); + $db = $this->getMock( IDatabase::class ); $db->expects( $this->any() ) ->method( 'update' ) ->will( $this->returnValue( $dbResult['update'] ) ); diff --git a/tests/phpunit/mapper/EventMapperTest.php b/tests/phpunit/mapper/EventMapperTest.php index aefb627dd..344de7e12 100644 --- a/tests/phpunit/mapper/EventMapperTest.php +++ b/tests/phpunit/mapper/EventMapperTest.php @@ -103,9 +103,7 @@ class EchoEventMapperTest extends MediaWikiTestCase { 'select' => '', 'selectRow' => '' ]; - $db = $this->getMockBuilder( DatabaseMysqli::class ) - ->disableOriginalConstructor() - ->getMock(); + $db = $this->getMock( IDatabase::class ); $db->expects( $this->any() ) ->method( 'insert' ) ->will( $this->returnValue( $dbResult['insert'] ) ); diff --git a/tests/phpunit/mapper/NotificationMapperTest.php b/tests/phpunit/mapper/NotificationMapperTest.php index b16af1799..17cb1518d 100644 --- a/tests/phpunit/mapper/NotificationMapperTest.php +++ b/tests/phpunit/mapper/NotificationMapperTest.php @@ -128,9 +128,7 @@ class EchoNotificationMapperTest extends MediaWikiTestCase { public function testDeleteByUserEventOffset() { $this->setMwGlobals( [ 'wgUpdateRowsPerQuery' => 4 ] ); - $mockDb = $this->getMockBuilder( DatabaseMysqli::class ) - ->disableOriginalConstructor() - ->getMock(); + $mockDb = $this->getMock( IDatabase::class ); $mockDb->expects( $this->any() ) ->method( 'selectFieldValues' ) ->will( $this->returnValue( [ 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ] ) ); @@ -153,7 +151,7 @@ class EchoNotificationMapperTest extends MediaWikiTestCase { $this->anything() ] ) - ->will( $this->returnValue( true ) ); + ->willReturn( true ); $notifMapper = new EchoNotificationMapper( $this->mockMWEchoDbFactory( $mockDb ) ); $this->assertTrue( $notifMapper->deleteByUserEventOffset( User::newFromId( 1 ), 500 ) ); @@ -221,9 +219,7 @@ class EchoNotificationMapperTest extends MediaWikiTestCase { 'delete' => '' ]; - $db = $this->getMockBuilder( DatabaseMysqli::class ) - ->disableOriginalConstructor() - ->getMock(); + $db = $this->getMock( IDatabase::class ); $db->expects( $this->any() ) ->method( 'insert' ) ->will( $this->returnValue( $dbResult['insert'] ) ); diff --git a/tests/phpunit/mapper/TargetPageMapperTest.php b/tests/phpunit/mapper/TargetPageMapperTest.php index 74ce6f950..34aa9ea25 100644 --- a/tests/phpunit/mapper/TargetPageMapperTest.php +++ b/tests/phpunit/mapper/TargetPageMapperTest.php @@ -74,9 +74,7 @@ class EchoTargetPageMapperTest extends MediaWikiTestCase { 'select' => '', 'delete' => '' ]; - $db = $this->getMockBuilder( DatabaseMysqli::class ) - ->disableOriginalConstructor() - ->getMock(); + $db = $this->getMock( IDatabase::class ); $db->expects( $this->any() ) ->method( 'insert' ) ->will( $this->returnValue( $dbResult['insert'] ) );