From 07a7bdce59722484c05b6397dc210932dd1abaec Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Thu, 22 Aug 2019 14:13:44 +0300 Subject: [PATCH] Some integration tests for LockManagerGroup Change-Id: Ide94a260e5f96c4cfcf76c1ee9b8dcf486976263 --- .../LockManagerGroupIntegrationTest.php | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 tests/phpunit/includes/filebackend/lockmanager/LockManagerGroupIntegrationTest.php diff --git a/tests/phpunit/includes/filebackend/lockmanager/LockManagerGroupIntegrationTest.php b/tests/phpunit/includes/filebackend/lockmanager/LockManagerGroupIntegrationTest.php new file mode 100644 index 0000000000..0615e9510d --- /dev/null +++ b/tests/phpunit/includes/filebackend/lockmanager/LockManagerGroupIntegrationTest.php @@ -0,0 +1,84 @@ +setMwGlobals( 'wgLockManagers', + [ [ 'name' => 'a', 'class' => 'b' ], [ 'name' => 'c', 'class' => 'd' ] ] ); + LockManagerGroup::destroySingletons(); + + $lmg = LockManagerGroup::singleton(); + $domain = WikiMap::getCurrentWikiDbDomain()->getId(); + + $this->assertSame( + [ 'class' => 'b', 'name' => 'a', 'domain' => $domain ], + $lmg->config( 'a' ) ); + $this->assertSame( + [ 'class' => 'd', 'name' => 'c', 'domain' => $domain ], + $lmg->config( 'c' ) ); + } + + public function testSingletonFalse() { + $this->setMwGlobals( 'wgLockManagers', [ [ 'name' => 'a', 'class' => 'b' ] ] ); + LockManagerGroup::destroySingletons(); + + $this->assertSame( + WikiMap::getCurrentWikiDbDomain()->getId(), + LockManagerGroup::singleton( false )->config( 'a' )['domain'] + ); + } + + public function testSingletonNull() { + $this->setMwGlobals( 'wgLockManagers', [ [ 'name' => 'a', 'class' => 'b' ] ] ); + LockManagerGroup::destroySingletons(); + + $this->assertSame( + null, + LockManagerGroup::singleton( null )->config( 'a' )['domain'] + ); + } + + public function testDestroySingletons() { + $instance = LockManagerGroup::singleton(); + $this->assertSame( $instance, LockManagerGroup::singleton() ); + LockManagerGroup::destroySingletons(); + $this->assertNotSame( $instance, LockManagerGroup::singleton() ); + } + + public function testDestroySingletonsNamedDomain() { + $instance = LockManagerGroup::singleton( 'domain' ); + $this->assertSame( $instance, LockManagerGroup::singleton( 'domain' ) ); + LockManagerGroup::destroySingletons(); + $this->assertNotSame( $instance, LockManagerGroup::singleton( 'domain' ) ); + } + + public function testGetDBLockManager() { + $this->markTestSkipped( 'DBLockManager case in LockManagerGroup::get appears to be ' . + 'broken, tries to instantiate an abstract class' ); + + $mockLB = $this->createMock( ILoadBalancer::class ); + $mockLB->expects( $this->never() ) + ->method( $this->anythingBut( '__destruct', 'getLazyConnectionRef' ) ); + $mockLB->expects( $this->once() )->method( 'getLazyConnectionRef' ) + ->with( DB_MASTER, [], 'domain', $mockLB::CONN_TRX_AUTOCOMMIT ) + ->willReturn( 'bogus value' ); + + $mockLBFactory = $this->createMock( LBFactory::class ); + $mockLBFactory->expects( $this->never() ) + ->method( $this->anythingBut( '__destruct', 'getMainLB' ) ); + $mockLBFactory->expects( $this->once() )->method( 'getMainLB' )->with( 'domain' ) + ->willReturn( $mockLB ); + + $lmg = new LockManagerGroup( 'domain', + [ [ 'name' => 'a', 'class' => DBLockManager::class ] ], $mockLBFactory ); + $this->assertSame( [], $lmg->get( 'a' ) ); + } +} -- 2.20.1