Thiemo Mättig (WMDE) has uploaded a new change for review.

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

Change subject: [WIP] Replace useless IDatabase type in ConnectionManager
......................................................................

[WIP] Replace useless IDatabase type in ConnectionManager

The ConnectionManager was kind of broken. The methods it uses are not
declared in IDatabase but in DatabaseBase. Not sure what IDatabase is
for. It's an empty interface. Why? This is pretty much pointless and
the reason for all the warnings (everything you try do access on an
IDatabase object is undeclared) I get in PHPStorm.

Not sure how to fix the tests. Please help.

Change-Id: Ia6f1e10723ee43cded5110a236ca5f91d160efe8
---
M client/includes/store/sql/ConnectionManager.php
M client/tests/phpunit/includes/store/sql/ConnectionManagerTest.php
2 files changed, 37 insertions(+), 42 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/07/170307/1

diff --git a/client/includes/store/sql/ConnectionManager.php 
b/client/includes/store/sql/ConnectionManager.php
index 38fdd6f..cf4d181 100644
--- a/client/includes/store/sql/ConnectionManager.php
+++ b/client/includes/store/sql/ConnectionManager.php
@@ -2,7 +2,7 @@
 
 namespace Wikibase\Client\Store\Sql;
 
-use IDatabase;
+use DatabaseBase;
 use LoadBalancer;
 
 /**
@@ -21,30 +21,30 @@
        }
 
        /**
-        * @return IDatabase
+        * @return DatabaseBase
         */
        public function getReadConnection() {
                return $this->loadBalancer->getConnection( DB_READ );
        }
 
        /**
-        * @return IDatabase
+        * @return DatabaseBase
         */
        private function getWriteConnection() {
                return $this->loadBalancer->getConnection( DB_WRITE );
        }
 
        /**
-        * @param IDatabase $db
+        * @param DatabaseBase $db
         */
-       public function releaseConnection( IDatabase $db ) {
+       public function releaseConnection( DatabaseBase $db ) {
                $this->loadBalancer->reuseConnection( $db );
        }
 
        /**
         * @param string $fname
         *
-        * @return IDatabase
+        * @return DatabaseBase
         */
        public function beginAtomicSection( $fname ) {
                $db = $this->getWriteConnection();
@@ -53,23 +53,19 @@
        }
 
        /**
-        * @param IDatabase $db
+        * @param DatabaseBase $db
         * @param string $fname
-        *
-        * @return IDatabase
         */
-       public function commitAtomicSection( IDatabase $db, $fname ) {
+       public function commitAtomicSection( DatabaseBase $db, $fname ) {
                $db->endAtomic( $fname );
                $this->releaseConnection( $db );
        }
 
        /**
-        * @param IDatabase $db
+        * @param DatabaseBase $db
         * @param string $fname
-        *
-        * @return IDatabase
         */
-       public function rollbackAtomicSection( IDatabase $db, $fname ) {
+       public function rollbackAtomicSection( DatabaseBase $db, $fname ) {
                //FIXME: there does not seem to be a clean way to roll back an 
atomic section?!
                $db->rollback( $fname, 'flush' );
                $this->releaseConnection( $db );
diff --git a/client/tests/phpunit/includes/store/sql/ConnectionManagerTest.php 
b/client/tests/phpunit/includes/store/sql/ConnectionManagerTest.php
index 72b80db..bdbe36c 100644
--- a/client/tests/phpunit/includes/store/sql/ConnectionManagerTest.php
+++ b/client/tests/phpunit/includes/store/sql/ConnectionManagerTest.php
@@ -16,13 +16,12 @@
  */
 class ConnectionManagerTest extends \PHPUnit_Framework_TestCase {
 
-       private function getConnectionMock() {
-               $connection = $this->getMockBuilder( 'IDatabase' )
-                       ->setMethods( array( 'startAtomic', 'endAtomic', 
'rollback' ) )
+       private function getDatabaseBaseMock() {
+               $db = $this->getMockBuilder( 'DatabaseBase' )
                        ->disableOriginalConstructor()
-                       ->getMock();
+                       ->getMockForAbstractClass();
 
-               return $connection;
+               return $db;
        }
 
        private function getLoadBalancerMock() {
@@ -34,85 +33,85 @@
        }
 
        public function testGetReadConnection() {
-               $connection = $this->getConnectionMock();
+               $db = $this->getDatabaseBaseMock();
                $lb = $this->getLoadBalancerMock();
 
                $lb->expects( $this->once() )
                        ->method( 'getConnection' )
                        ->with( DB_READ )
-                       ->will( $this->returnValue( $connection ) );
+                       ->willReturn( $db );
 
                $manager = new ConnectionManager( $lb );
                $actual = $manager->getReadConnection();
 
-               $this->assertSame( $connection, $actual );
+               $this->assertSame( $db, $actual );
        }
 
        public function testReleaseConnection() {
-               $connection = $this->getConnectionMock();
+               $db = $this->getDatabaseBaseMock();
                $lb = $this->getLoadBalancerMock();
 
                $lb->expects( $this->once() )
                        ->method( 'reuseConnection' )
-                       ->with( $connection )
-                       ->will( $this->returnValue( null ) );
+                       ->with( $db )
+                       ->willReturn( null );
 
                $manager = new ConnectionManager( $lb );
-               $manager->releaseConnection( $connection );
+               $manager->releaseConnection( $db );
        }
 
        public function testBeginAtomicSection() {
-               $connection = $this->getConnectionMock();
+               $db = $this->getDatabaseBaseMock();
                $lb = $this->getLoadBalancerMock( );
 
                $lb->expects( $this->once() )
                        ->method( 'getConnection' )
                        ->with( DB_WRITE )
-                       ->will( $this->returnValue( $connection ) );
+                       ->willReturn( $db );
 
-               $connection->expects( $this->once() )
+               $db->expects( $this->once() )
                        ->method( 'startAtomic' )
                        ->withAnyParameters()
-                       ->will( $this->returnValue( null ) );
+                       ->willReturn( null );
 
                $manager = new ConnectionManager( $lb );
                $manager->beginAtomicSection( 'TEST' );
        }
 
        public function testCommitAtomicSection() {
-               $connection = $this->getConnectionMock();
+               $db = $this->getDatabaseBaseMock();
                $lb = $this->getLoadBalancerMock( );
 
                $lb->expects( $this->once() )
                        ->method( 'reuseConnection' )
-                       ->with( $connection )
-                       ->will( $this->returnValue( null ) );
+                       ->with( $db )
+                       ->willReturn( null );
 
-               $connection->expects( $this->once() )
+               $db->expects( $this->once() )
                        ->method( 'endAtomic' )
                        ->withAnyParameters()
-                       ->will( $this->returnValue( null ) );
+                       ->willReturn( null );
 
                $manager = new ConnectionManager( $lb );
-               $manager->commitAtomicSection( $connection, 'TEST' );
+               $manager->commitAtomicSection( $db, 'TEST' );
        }
 
        public function testRollbackAtomicSection() {
-               $connection = $this->getConnectionMock();
+               $db = $this->getDatabaseBaseMock();
                $lb = $this->getLoadBalancerMock( );
 
                $lb->expects( $this->once() )
                        ->method( 'reuseConnection' )
-                       ->with( $connection )
-                       ->will( $this->returnValue( null ) );
+                       ->with( $db )
+                       ->willReturn( null );
 
-               $connection->expects( $this->once() )
+               $db->expects( $this->once() )
                        ->method( 'rollback' )
                        ->withAnyParameters()
-                       ->will( $this->returnValue( null ) );
+                       ->willReturn( null );
 
                $manager = new ConnectionManager( $lb );
-               $manager->rollbackAtomicSection( $connection, 'TEST' );
+               $manager->rollbackAtomicSection( $db, 'TEST' );
        }
 
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia6f1e10723ee43cded5110a236ca5f91d160efe8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

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

Reply via email to