diff options
Diffstat (limited to 'Echo/tests/phpunit/gateway/UserNotificationGatewayTest.php')
-rw-r--r-- | Echo/tests/phpunit/gateway/UserNotificationGatewayTest.php | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/Echo/tests/phpunit/gateway/UserNotificationGatewayTest.php b/Echo/tests/phpunit/gateway/UserNotificationGatewayTest.php index 7e656e19..2cc4fd78 100644 --- a/Echo/tests/phpunit/gateway/UserNotificationGatewayTest.php +++ b/Echo/tests/phpunit/gateway/UserNotificationGatewayTest.php @@ -1,11 +1,14 @@ <?php +/** + * @covers EchoUserNotificationGateway + */ class EchoUserNotificationGatewayTest extends MediaWikiTestCase { public function testMarkRead() { // no event ids to mark $gateway = new EchoUserNotificationGateway( User::newFromId( 1 ), $this->mockMWEchoDbFactory() ); - $this->assertNull( $gateway->markRead( [] ) ); + $this->assertFalse( $gateway->markRead( [] ) ); // successful update $gateway = new EchoUserNotificationGateway( User::newFromId( 1 ), $this->mockMWEchoDbFactory( [ 'update' => true ] ) ); @@ -29,19 +32,19 @@ class EchoUserNotificationGatewayTest extends MediaWikiTestCase { public function testGetNotificationCount() { // unsuccessful select $gateway = new EchoUserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'selectRowCount' => 0 ] ) ); - $this->assertEquals( 0, $gateway->getCappedNotificationCount( DB_SLAVE, [ 'event_one' ] ) ); + $this->assertEquals( 0, $gateway->getCappedNotificationCount( DB_REPLICA, [ 'event_one' ] ) ); // successful select of alert $gateway = new EchoUserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'selectRowCount' => 2 ] ) ); - $this->assertEquals( 2, $gateway->getCappedNotificationCount( DB_SLAVE, [ 'event_one', 'event_two' ] ) ); + $this->assertEquals( 2, $gateway->getCappedNotificationCount( DB_REPLICA, [ 'event_one', 'event_two' ] ) ); // there is event, should return 0 $gateway = new EchoUserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'selectRowCount' => 2 ] ) ); - $this->assertEquals( 0, $gateway->getCappedNotificationCount( DB_SLAVE, [] ) ); + $this->assertEquals( 0, $gateway->getCappedNotificationCount( DB_REPLICA, [] ) ); // successful select $gateway = new EchoUserNotificationGateway( $this->mockUser(), $this->mockMWEchoDbFactory( [ 'selectRowCount' => 3 ] ) ); - $this->assertEquals( 3, $gateway->getCappedNotificationCount( DB_SLAVE, [ 'event_one' ] ) ); + $this->assertEquals( 3, $gateway->getCappedNotificationCount( DB_REPLICA, [ 'event_one' ] ) ); } public function testGetUnreadNotifications() { @@ -93,7 +96,8 @@ class EchoUserNotificationGatewayTest extends MediaWikiTestCase { } /** - * Mock object of DatabaseMysql ( DatabaseBase ) + * Returns a mock database object + * @return \Wikimedia\Rdbms\IDatabase */ protected function mockDb( array $dbResult = [] ) { $dbResult += [ @@ -102,7 +106,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiTestCase { 'selectRow' => '', 'selectRowCount' => '', ]; - $db = $this->getMockBuilder( 'DatabaseMysql' ) + $db = $this->getMockBuilder( 'DatabaseMysqli' ) ->disableOriginalConstructor() ->getMock(); $db->expects( $this->any() ) @@ -117,9 +121,10 @@ class EchoUserNotificationGatewayTest extends MediaWikiTestCase { $db->expects( $this->any() ) ->method( 'selectRowCount' ) ->will( $this->returnValue( $dbResult['selectRowCount'] ) ); + $numRows = is_array( $dbResult['select'] ) ? count( $dbResult['select'] ) : 0; $db->expects( $this->any() ) ->method( 'numRows' ) - ->will( $this->returnValue( count( $dbResult['select'] ) ) ); + ->will( $this->returnValue( $numRows ) ); return $db; } |