Merge "Add semantic tags to license info text"
[lhc/web/wiklou.git] / tests / phpunit / includes / db / LBFactoryTest.php
index 8b285cb..75d5414 100644 (file)
@@ -1,10 +1,4 @@
 <?php
-
-use Wikimedia\Rdbms\LBFactorySimple;
-use Wikimedia\Rdbms\LBFactoryMulti;
-use Wikimedia\Rdbms\ChronologyProtector;
-use Wikimedia\Rdbms\MySQLMasterPos;
-
 /**
  * Holds tests for LBFactory abstract MediaWiki class.
  *
@@ -23,15 +17,26 @@ use Wikimedia\Rdbms\MySQLMasterPos;
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @group Database
  * @file
  * @author Antoine Musso
  * @copyright © 2013 Antoine Musso
  * @copyright © 2013 Wikimedia Foundation Inc.
  */
+
+use Wikimedia\Rdbms\LBFactorySimple;
+use Wikimedia\Rdbms\LBFactoryMulti;
+use Wikimedia\Rdbms\ChronologyProtector;
+use Wikimedia\Rdbms\MySQLMasterPos;
+
+/**
+ * @group Database
+ * @covers \Wikimedia\Rdbms\LBFactorySimple
+ * @covers \Wikimedia\Rdbms\LBFactoryMulti
+ */
 class LBFactoryTest extends MediaWikiTestCase {
 
        /**
+        * @covers MWLBFactory::getLBFactoryClass
         * @dataProvider getLBFactoryClassProvider
         */
        public function testGetLBFactoryClass( $expected, $deprecated ) {
@@ -88,8 +93,8 @@ class LBFactoryTest extends MediaWikiTestCase {
                $dbw = $lb->getConnection( DB_MASTER );
                $this->assertTrue( $dbw->getLBInfo( 'master' ), 'master shows as master' );
 
-               $dbr = $lb->getConnection( DB_SLAVE );
-               $this->assertTrue( $dbr->getLBInfo( 'master' ), 'DB_SLAVE also gets the master' );
+               $dbr = $lb->getConnection( DB_REPLICA );
+               $this->assertTrue( $dbr->getLBInfo( 'master' ), 'DB_REPLICA also gets the master' );
 
                $factory->shutdown();
                $lb->closeAll();
@@ -134,7 +139,7 @@ class LBFactoryTest extends MediaWikiTestCase {
                        $dbw->getLBInfo( 'clusterMasterHost' ),
                        'cluster master set' );
 
-               $dbr = $lb->getConnection( DB_SLAVE );
+               $dbr = $lb->getConnection( DB_REPLICA );
                $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'slave shows as slave' );
                $this->assertEquals(
                        ( $wgDBserver != '' ) ? $wgDBserver : 'localhost',
@@ -175,13 +180,16 @@ class LBFactoryTest extends MediaWikiTestCase {
                $dbw = $lb->getConnection( DB_MASTER );
                $this->assertTrue( $dbw->getLBInfo( 'master' ), 'master shows as master' );
 
-               $dbr = $lb->getConnection( DB_SLAVE );
+               $dbr = $lb->getConnection( DB_REPLICA );
                $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'slave shows as slave' );
 
                $factory->shutdown();
                $lb->closeAll();
        }
 
+       /**
+        * @covers \Wikimedia\Rdbms\ChronologyProtector
+        */
        public function testChronologyProtector() {
                // (a) First HTTP request
                $mPos = new MySQLMasterPos( 'db1034-bin.000976', '843431247' );
@@ -409,16 +417,27 @@ class LBFactoryTest extends MediaWikiTestCase {
                        "Correct full table name"
                );
 
-               \MediaWiki\suppressWarnings();
-               $this->assertFalse( $db->selectDB( 'garbage-db' ) );
-               \MediaWiki\restoreWarnings();
-
                $this->assertEquals(
                        $this->quoteTable( $db, 'garbage-db' ) . '.' . $this->quoteTable( $db, 'page' ),
                        $db->tableName( 'garbage-db.page' ),
                        "Correct full table name"
                );
 
+               if ( $db->databasesAreIndependent() ) {
+                       try {
+                               $e = null;
+                               $db->selectDB( 'garbage-db' );
+                       } catch ( \Wikimedia\Rdbms\DBConnectionError $e ) {
+                               // expected
+                       }
+                       $this->assertInstanceOf( '\Wikimedia\Rdbms\DBConnectionError', $e );
+                       $this->assertFalse( $db->isOpen() );
+               } else {
+                       \MediaWiki\suppressWarnings();
+                       $this->assertFalse( $db->selectDB( 'garbage-db' ) );
+                       \MediaWiki\restoreWarnings();
+               }
+
                $factory->closeAll();
                $factory->destroy();
        }