Merge ".pipeline/config.yaml: rename dev stage to publish"
[lhc/web/wiklou.git] / tests / phpunit / includes / Revision / RevisionStoreTest.php
index 0648bfc..9b26c37 100644 (file)
@@ -12,6 +12,8 @@ use MediaWiki\Revision\RevisionStore;
 use MediaWiki\Revision\SlotRoleRegistry;
 use MediaWiki\Revision\SlotRecord;
 use MediaWiki\Storage\SqlBlobStore;
+use Wikimedia\Rdbms\ILoadBalancer;
+use Wikimedia\Rdbms\MaintainableDBConnRef;
 use MediaWikiTestCase;
 use MWException;
 use Title;
@@ -77,6 +79,17 @@ class RevisionStoreTest extends MediaWikiTestCase {
                        ->disableOriginalConstructor()->getMock();
        }
 
+       /**
+        * @param ILoadBalancer $mockLoadBalancer
+        * @param Database $db
+        * @return callable
+        */
+       private function getMockDBConnRefCallback( ILoadBalancer $mockLoadBalancer, IDatabase $db ) {
+               return function ( $i, $g, $domain, $flg ) use ( $mockLoadBalancer, $db ) {
+                       return new MaintainableDBConnRef( $mockLoadBalancer, $db, $i );
+               };
+       }
+
        /**
         * @return \PHPUnit_Framework_MockObject_MockObject|SqlBlobStore
         */
@@ -107,9 +120,7 @@ class RevisionStoreTest extends MediaWikiTestCase {
 
        public function provideSetContentHandlerUseDB() {
                return [
-                       // ContentHandlerUseDB can be true of false pre migration.
-                       [ false, SCHEMA_COMPAT_OLD, false ],
-                       [ true, SCHEMA_COMPAT_OLD, false ],
+                       // ContentHandlerUseDB can be true or false pre migration.
                        // During and after migration it can not be false...
                        [ false, SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, true ],
                        [ false, SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, true ],
@@ -158,10 +169,14 @@ class RevisionStoreTest extends MediaWikiTestCase {
                $this->setService( 'DBLoadBalancer', $mockLoadBalancer );
 
                $db = $this->getMockDatabase();
-               // Title calls wfGetDB() which uses a regular Connection
+               // RevisionStore uses getConnectionRef
+               $mockLoadBalancer->expects( $this->any() )
+                       ->method( 'getConnectionRef' )
+                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
+               // Title calls wfGetDB() which uses getMaintenanceConnectionRef
                $mockLoadBalancer->expects( $this->atLeastOnce() )
-                       ->method( 'getConnection' )
-                       ->willReturn( $db );
+                       ->method( 'getMaintenanceConnectionRef' )
+                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
 
                // First call to Title::newFromID, faking no result (db lag?)
                $db->expects( $this->at( 0 ) )
@@ -192,15 +207,15 @@ class RevisionStoreTest extends MediaWikiTestCase {
                $this->setService( 'DBLoadBalancer', $mockLoadBalancer );
 
                $db = $this->getMockDatabase();
-               // Title calls wfGetDB() which uses a regular Connection
+               // Title calls wfGetDB() which uses getMaintenanceConnectionRef
                // Assert that the first call uses a REPLICA and the second falls back to master
-               $mockLoadBalancer->expects( $this->exactly( 2 ) )
-                       ->method( 'getConnection' )
-                       ->willReturn( $db );
-               // RevisionStore getTitle uses a ConnectionRef
                $mockLoadBalancer->expects( $this->atLeastOnce() )
                        ->method( 'getConnectionRef' )
-                       ->willReturn( $db );
+                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
+               // Title calls wfGetDB() which uses getMaintenanceConnectionRef
+               $mockLoadBalancer->expects( $this->exactly( 2 ) )
+                       ->method( 'getMaintenanceConnectionRef' )
+                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
 
                // First call to Title::newFromID, faking no result (db lag?)
                $db->expects( $this->at( 0 ) )
@@ -251,14 +266,14 @@ class RevisionStoreTest extends MediaWikiTestCase {
                $this->setService( 'DBLoadBalancer', $mockLoadBalancer );
 
                $db = $this->getMockDatabase();
-               // Title calls wfGetDB() which uses a regular Connection
-               $mockLoadBalancer->expects( $this->atLeastOnce() )
-                       ->method( 'getConnection' )
-                       ->willReturn( $db );
-               // RevisionStore getTitle uses a ConnectionRef
                $mockLoadBalancer->expects( $this->atLeastOnce() )
                        ->method( 'getConnectionRef' )
-                       ->willReturn( $db );
+                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
+               // Title calls wfGetDB() which uses getMaintenanceConnectionRef
+               // RevisionStore getTitle uses getMaintenanceConnectionRef
+               $mockLoadBalancer->expects( $this->atLeastOnce() )
+                       ->method( 'getMaintenanceConnectionRef' )
+                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
 
                // First call to Title::newFromID, faking no result (db lag?)
                $db->expects( $this->at( 0 ) )
@@ -299,15 +314,15 @@ class RevisionStoreTest extends MediaWikiTestCase {
                $this->setService( 'DBLoadBalancer', $mockLoadBalancer );
 
                $db = $this->getMockDatabase();
-               // Title calls wfGetDB() which uses a regular Connection
                // Assert that the first call uses a REPLICA and the second falls back to master
-               $mockLoadBalancer->expects( $this->exactly( 2 ) )
-                       ->method( 'getConnection' )
-                       ->willReturn( $db );
-               // RevisionStore getTitle uses a ConnectionRef
+               // RevisionStore uses getMaintenanceConnectionRef
                $mockLoadBalancer->expects( $this->atLeastOnce() )
                        ->method( 'getConnectionRef' )
-                       ->willReturn( $db );
+                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
+               // Title calls wfGetDB() which uses getMaintenanceConnectionRef
+               $mockLoadBalancer->expects( $this->exactly( 2 ) )
+                       ->method( 'getMaintenanceConnectionRef' )
+                       ->willReturnCallback( $this->getMockDBConnRefCallback( $mockLoadBalancer, $db ) );
 
                // First call to Title::newFromID, faking no result (db lag?)
                $db->expects( $this->at( 0 ) )
@@ -368,12 +383,14 @@ class RevisionStoreTest extends MediaWikiTestCase {
                $this->setService( 'DBLoadBalancer', $mockLoadBalancer );
 
                $db = $this->getMockDatabase();
-               // Title calls wfGetDB() which uses a regular Connection
+               // Title calls wfGetDB() which uses getMaintenanceConnectionRef
                // Assert that the first call uses a REPLICA and the second falls back to master
 
                // RevisionStore getTitle uses getConnectionRef
-               // Title::newFromID uses getConnection
-               foreach ( [ 'getConnection', 'getConnectionRef' ] as $method ) {
+               // Title::newFromID uses getMaintenanceConnectionRef
+               foreach ( [
+                       'getConnectionRef', 'getMaintenanceConnectionRef'
+               ] as $method ) {
                        $mockLoadBalancer->expects( $this->exactly( 2 ) )
                                ->method( $method )
                                ->willReturnCallback( function ( $masterOrReplica ) use ( $db ) {
@@ -544,7 +561,6 @@ class RevisionStoreTest extends MediaWikiTestCase {
 
        public function provideMigrationConstruction() {
                return [
-                       [ SCHEMA_COMPAT_OLD, false ],
                        [ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, false ],
                        [ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, false ],
                        [ SCHEMA_COMPAT_NEW, false ],