Krinkle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/310686

Change subject: phpunit: Simplify mock object syntax in includes/db/ tests
......................................................................

phpunit: Simplify mock object syntax in includes/db/ tests

* Omit redundant `expects( $this->any() )`.
* Use willReturn() instead of `will( $this->returnValue() )`.

Change-Id: If90ac651748af8a78a720992240e40ba53cec79c
---
M tests/phpunit/includes/db/DatabaseMysqlBaseTest.php
M tests/phpunit/includes/db/LBFactoryTest.php
2 files changed, 18 insertions(+), 34 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/86/310686/1

diff --git a/tests/phpunit/includes/db/DatabaseMysqlBaseTest.php 
b/tests/phpunit/includes/db/DatabaseMysqlBaseTest.php
index 607f25c..f13ead4 100644
--- a/tests/phpunit/includes/db/DatabaseMysqlBaseTest.php
+++ b/tests/phpunit/includes/db/DatabaseMysqlBaseTest.php
@@ -169,15 +169,11 @@
                        ->setMethods( [ 'fetchRow', 'query' ] )
                        ->getMock();
 
-               $db->expects( $this->any() )
-                       ->method( 'query' )
+               $db->method( 'query' )
                        ->with( $this->anything() )
-                       ->will(
-                               $this->returnValue( null )
-                       );
+                       ->willReturn( null );
 
-               $db->expects( $this->any() )
-                       ->method( 'fetchRow' )
+               $db->method( 'fetchRow' )
                        ->with( $this->anything() )
                        ->will( $this->onConsecutiveCalls(
                                [ 'Tables_in_' => 'view1' ],
@@ -361,13 +357,11 @@
                                'getLagDetectionMethod', 'getHeartbeatData', 
'getMasterServerInfo' ] )
                        ->getMock();
 
-               $db->expects( $this->any() )
-                       ->method( 'getLagDetectionMethod' )
-                       ->will( $this->returnValue( 'pt-heartbeat' ) );
+               $db->method( 'getLagDetectionMethod' )
+                       ->willReturn( 'pt-heartbeat' );
 
-               $db->expects( $this->any() )
-                       ->method( 'getMasterServerInfo' )
-                       ->will( $this->returnValue( [ 'serverId' => 172, 'asOf' 
=> time() ] ) );
+               $db->method( 'getMasterServerInfo' )
+                       ->willReturn( [ 'serverId' => 172, 'asOf' => time() ] );
 
                // Fake the current time.
                list( $nowSecFrac, $nowSec ) = explode( ' ', microtime() );
@@ -381,10 +375,9 @@
                $ptTimeISO = $ptDateTime->format( 'Y-m-d\TH:i:s' );
                $ptTimeISO .= ltrim( number_format( $ptSecFrac, 6 ), '0' );
 
-               $db->expects( $this->any() )
-                       ->method( 'getHeartbeatData' )
+               $db->method( 'getHeartbeatData' )
                        ->with( [ 'server_id' => 172 ] )
-                       ->will( $this->returnValue( [ $ptTimeISO, $now ] ) );
+                       ->willReturn( [ $ptTimeISO, $now ] );
 
                $db->setLBInfo( 'clusterMasterHost', 'db1052' );
                $lagEst = $db->getLag();
diff --git a/tests/phpunit/includes/db/LBFactoryTest.php 
b/tests/phpunit/includes/db/LBFactoryTest.php
index bf78d13..862ec42 100644
--- a/tests/phpunit/includes/db/LBFactoryTest.php
+++ b/tests/phpunit/includes/db/LBFactoryTest.php
@@ -159,26 +159,18 @@
                $mockDB = $this->getMockBuilder( 'DatabaseMysql' )
                        ->disableOriginalConstructor()
                        ->getMock();
-               $mockDB->expects( $this->any() )
-                       ->method( 'writesOrCallbacksPending' )->will( 
$this->returnValue( true ) );
-               $mockDB->expects( $this->any() )
-                       ->method( 'lastDoneWrites' )->will( $this->returnValue( 
$now ) );
-               $mockDB->expects( $this->any() )
-                       ->method( 'getMasterPos' )->will( $this->returnValue( 
$mPos ) );
+               $mockDB->method( 'writesOrCallbacksPending' )->willReturn( true 
);
+               $mockDB->method( 'lastDoneWrites' )->willReturn( $now );
+               $mockDB->method( 'getMasterPos' )->willReturn( $mPos );
 
                $lb = $this->getMockBuilder( 'LoadBalancer' )
                        ->disableOriginalConstructor()
                        ->getMock();
-               $lb->expects( $this->any() )
-                       ->method( 'getConnection' )->will( $this->returnValue( 
$mockDB ) );
-               $lb->expects( $this->any() )
-                       ->method( 'getServerCount' )->will( $this->returnValue( 
2 ) );
-               $lb->expects( $this->any() )
-                       ->method( 'parentInfo' )->will( $this->returnValue( [ 
'id' => "main-DEFAULT" ] ) );
-               $lb->expects( $this->any() )
-                       ->method( 'getAnyOpenConnection' )->will( 
$this->returnValue( $mockDB ) );
-               $lb->expects( $this->any() )
-                       ->method( 'hasOrMadeRecentMasterChanges' )->will( 
$this->returnCallback(
+               $lb->method( 'getConnection' )->willReturn( $mockDB );
+               $lb->method( 'getServerCount' )->willReturn( 2 );
+               $lb->method( 'parentInfo' )->willReturn( [ 'id' => 
"main-DEFAULT" ] );
+               $lb->method( 'getAnyOpenConnection' )->willReturn( $mockDB );
+               $lb->method( 'hasOrMadeRecentMasterChanges' )->will( 
$this->returnCallback(
                                function () use ( $mockDB ) {
                                        $p = 0;
                                        $p |= call_user_func( [ $mockDB, 
'writesOrCallbacksPending' ] );
@@ -187,8 +179,7 @@
                                        return (bool)$p;
                                }
                        ) );
-               $lb->expects( $this->any() )
-                       ->method( 'getMasterPos' )->will( $this->returnValue( 
$mPos ) );
+               $lb->method( 'getMasterPos' )->willReturn( $mPos );
 
                $bag = new HashBagOStuff();
                $cp = new ChronologyProtector(

-- 
To view, visit https://gerrit.wikimedia.org/r/310686
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If90ac651748af8a78a720992240e40ba53cec79c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <krinklem...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to