Merge "Fix eslint warnings and switch to error code"
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / RevisionStoreFactoryTest.php
index a5c18ac..3f8bd4b 100644 (file)
@@ -4,29 +4,32 @@ namespace MediaWiki\Tests\Storage;
 
 use ActorMigration;
 use CommentStore;
-use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\Logger\Spi as LoggerSpi;
+use MediaWiki\Storage\BlobStore;
+use MediaWiki\Storage\BlobStoreFactory;
 use MediaWiki\Storage\NameTableStore;
 use MediaWiki\Storage\RevisionStore;
 use MediaWiki\Storage\RevisionStoreFactory;
 use MediaWiki\Storage\SqlBlobStore;
 use MediaWikiTestCase;
+use Psr\Log\LoggerInterface;
+use Psr\Log\NullLogger;
 use WANObjectCache;
-use Wikimedia\Rdbms\LoadBalancer;
+use Wikimedia\Rdbms\ILBFactory;
+use Wikimedia\Rdbms\ILoadBalancer;
 use Wikimedia\TestingAccessWrapper;
 
 class RevisionStoreFactoryTest extends MediaWikiTestCase {
 
        public function testValidConstruction_doesntCauseErrors() {
                new RevisionStoreFactory(
-                       $this->getMockLoadBalancer(),
-                       $this->getMockSqlBlobStore(),
+                       $this->getMockLoadBalancerFactory(),
+                       $this->getMockBlobStoreFactory(),
                        $this->getHashWANObjectCache(),
                        $this->getMockCommentStore(),
-                       $this->getMockNameTableStore(),
-                       $this->getMockNameTableStore(),
-                       MIGRATION_OLD,
                        ActorMigration::newMigration(),
-                       LoggerFactory::getInstance( 'someInstance' ),
+                       MIGRATION_OLD,
+                       $this->getMockLoggerSpi(),
                        true
                );
                $this->assertTrue( true );
@@ -48,25 +51,21 @@ class RevisionStoreFactoryTest extends MediaWikiTestCase {
                $mcrMigrationStage = MIGRATION_OLD,
                $contentHandlerUseDb = true
        ) {
-               $lb = $this->getMockLoadBalancer();
-               $blobStore = $this->getMockSqlBlobStore();
+               $lbFactory = $this->getMockLoadBalancerFactory();
+               $blobStoreFactory = $this->getMockBlobStoreFactory();
                $cache = $this->getHashWANObjectCache();
                $commentStore = $this->getMockCommentStore();
-               $contentModelStore = $this->getMockNameTableStore();
-               $slotRoleStore = $this->getMockNameTableStore();
                $actorMigration = ActorMigration::newMigration();
-               $logger = LoggerFactory::getInstance( 'someInstance' );
+               $loggerProvider = $this->getMockLoggerSpi();
 
                $factory = new RevisionStoreFactory(
-                       $lb,
-                       $blobStore,
+                       $lbFactory,
+                       $blobStoreFactory,
                        $cache,
                        $commentStore,
-                       $contentModelStore,
-                       $slotRoleStore,
-                       $mcrMigrationStage,
                        $actorMigration,
-                       $logger,
+                       $mcrMigrationStage,
+                       $loggerProvider,
                        $contentHandlerUseDb
                );
 
@@ -80,32 +79,40 @@ class RevisionStoreFactoryTest extends MediaWikiTestCase {
                $this->assertSame( $wikiId, $wrapper->wikiId );
 
                // ensure all other required services are correctly set
-               $this->assertSame( $lb, $wrapper->loadBalancer );
-               $this->assertSame( $blobStore, $wrapper->blobStore );
                $this->assertSame( $cache, $wrapper->cache );
                $this->assertSame( $commentStore, $wrapper->commentStore );
-               $this->assertSame( $contentModelStore, $wrapper->contentModelStore );
-               $this->assertSame( $slotRoleStore, $wrapper->slotRoleStore );
                $this->assertSame( $mcrMigrationStage, $wrapper->mcrMigrationStage );
                $this->assertSame( $actorMigration, $wrapper->actorMigration );
-               $this->assertSame( $logger, $wrapper->logger );
                $this->assertSame( $contentHandlerUseDb, $store->getContentHandlerUseDB() );
+
+               $this->assertInstanceOf( ILoadBalancer::class, $wrapper->loadBalancer );
+               $this->assertInstanceOf( BlobStore::class, $wrapper->blobStore );
+               $this->assertInstanceOf( NameTableStore::class, $wrapper->contentModelStore );
+               $this->assertInstanceOf( NameTableStore::class, $wrapper->slotRoleStore );
+               $this->assertInstanceOf( LoggerInterface::class, $wrapper->logger );
        }
 
        /**
-        * @return \PHPUnit_Framework_MockObject_MockObject|NameTableStore
+        * @return \PHPUnit_Framework_MockObject_MockObject|ILoadBalancer
         */
-       private function getMockNameTableStore() {
-               return $this->getMockBuilder( NameTableStore::class )
+       private function getMockLoadBalancer() {
+               return $this->getMockBuilder( ILoadBalancer::class )
                        ->disableOriginalConstructor()->getMock();
        }
 
        /**
-        * @return \PHPUnit_Framework_MockObject_MockObject|LoadBalancer
+        * @return \PHPUnit_Framework_MockObject_MockObject|ILBFactory
         */
-       private function getMockLoadBalancer() {
-               return $this->getMockBuilder( LoadBalancer::class )
+       private function getMockLoadBalancerFactory() {
+               $mock = $this->getMockBuilder( ILBFactory::class )
                        ->disableOriginalConstructor()->getMock();
+
+               $mock->method( 'getMainLB' )
+                       ->willReturnCallback( function () {
+                               return $this->getMockLoadBalancer();
+                       } );
+
+               return $mock;
        }
 
        /**
@@ -116,6 +123,21 @@ class RevisionStoreFactoryTest extends MediaWikiTestCase {
                        ->disableOriginalConstructor()->getMock();
        }
 
+       /**
+        * @return \PHPUnit_Framework_MockObject_MockObject|BlobStoreFactory
+        */
+       private function getMockBlobStoreFactory() {
+               $mock = $this->getMockBuilder( BlobStoreFactory::class )
+                       ->disableOriginalConstructor()->getMock();
+
+               $mock->method( 'newSqlBlobStore' )
+                       ->willReturnCallback( function () {
+                               return $this->getMockSqlBlobStore();
+                       } );
+
+               return $mock;
+       }
+
        /**
         * @return \PHPUnit_Framework_MockObject_MockObject|CommentStore
         */
@@ -128,4 +150,16 @@ class RevisionStoreFactoryTest extends MediaWikiTestCase {
                return new WANObjectCache( [ 'cache' => new \HashBagOStuff() ] );
        }
 
+       /**
+        * @return \PHPUnit_Framework_MockObject_MockObject|LoggerSpi
+        */
+       private function getMockLoggerSpi() {
+               $mock = $this->getMock( LoggerSpi::class );
+
+               $mock->method( 'getLogger' )
+                       ->willReturn( new NullLogger() );
+
+               return $mock;
+       }
+
 }