Merge "Adjust type hints in database related classes"
[lhc/web/wiklou.git] / tests / phpunit / tests / MediaWikiTestCaseTest.php
index 599b733..9641802 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
 use Psr\Log\LoggerInterface;
@@ -7,6 +8,7 @@ use Wikimedia\Rdbms\LoadBalancer;
 /**
  * @covers MediaWikiTestCase
  * @group MediaWikiTestCaseTest
+ * @group Database
  *
  * @author Addshore
  */
@@ -66,32 +68,7 @@ class MediaWikiTestCaseTest extends MediaWikiTestCase {
        }
 
        /**
-        * @dataProvider provideExistingKeysAndNewValues
-        *
-        * @covers MediaWikiTestCase::stashMwGlobals
-        * @covers MediaWikiTestCase::tearDown
-        */
-       public function testStashedGlobalsAreRestoredOnTearDown( $globalKey, $newValue ) {
-               $this->hideDeprecated( 'MediaWikiTestCase::stashMwGlobals' );
-               $this->stashMwGlobals( $globalKey );
-               $GLOBALS[$globalKey] = $newValue;
-               $this->assertEquals(
-                       $newValue,
-                       $GLOBALS[$globalKey],
-                       'Global failed to correctly set'
-               );
-
-               $this->tearDown();
-
-               $this->assertEquals(
-                       self::$startGlobals[$globalKey],
-                       $GLOBALS[$globalKey],
-                       'Global failed to be restored on tearDown'
-               );
-       }
-
-       /**
-        * @covers MediaWikiTestCase::stashMwGlobals
+        * @covers MediaWikiTestCase::setMwGlobals
         * @covers MediaWikiTestCase::tearDown
         */
        public function testSetNonExistentGlobalsAreUnsetOnTearDown() {
@@ -173,4 +150,38 @@ class MediaWikiTestCaseTest extends MediaWikiTestCase {
 
                $this->assertSame( $logger1, $logger2 );
        }
+
+       /**
+        * @covers MediaWikiTestCase::setupDatabaseWithTestPrefix
+        * @covers MediaWikiTestCase::copyTestData
+        */
+       public function testCopyTestData() {
+               $this->markTestSkippedIfDbType( 'sqlite' );
+
+               $this->tablesUsed[] = 'objectcache';
+               $this->db->insert(
+                       'objectcache',
+                       [ 'keyname' => __METHOD__, 'value' => 'TEST', 'exptime' => $this->db->timestamp( 11 ) ],
+                       __METHOD__
+               );
+
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+               $lb = $lbFactory->newMainLB();
+               $db = $lb->getConnection( DB_REPLICA, DBO_TRX );
+
+               // sanity
+               $this->assertNotSame( $this->db, $db );
+
+               // Make sure the DB connection has the fake table clones and the fake table prefix
+               MediaWikiTestCase::setupDatabaseWithTestPrefix( $db, $this->dbPrefix(), false );
+
+               $this->assertSame( $this->db->tablePrefix(), $db->tablePrefix(), 'tablePrefix' );
+
+               // Make sure the DB connection has all the test data
+               $this->copyTestData( $this->db, $db );
+
+               $value = $db->selectField( 'objectcache', 'value', [ 'keyname' => __METHOD__ ], __METHOD__ );
+               $this->assertSame( 'TEST', $value, 'Copied Data' );
+       }
+
 }