X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FStorage%2FRevisionStoreFactoryTest.php;h=3f8bd4b6ab53aa4d44b3ac2ce91e0717331734f3;hb=84662b72f073f2df3aa8e8e209da0bc568b91716;hp=a5c18ac5a6657ef85cf9d16ac513a352457b429c;hpb=e5b128f2e4072c99f59c0fdc0fd3fe83b1a27101;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/Storage/RevisionStoreFactoryTest.php b/tests/phpunit/includes/Storage/RevisionStoreFactoryTest.php index a5c18ac5a6..3f8bd4b6ab 100644 --- a/tests/phpunit/includes/Storage/RevisionStoreFactoryTest.php +++ b/tests/phpunit/includes/Storage/RevisionStoreFactoryTest.php @@ -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; + } + }