3 use Wikimedia\Rdbms\ILoadBalancer
;
4 use Wikimedia\Rdbms\LBFactory
;
7 * Most of the file is covered by the unit test and/or FileBackendTest. Here we fill in the missing
8 * bits that don't work with unit tests yet.
10 * @covers LockManagerGroup
12 class LockManagerGroupIntegrationTest
extends MediaWikiIntegrationTestCase
{
13 public function testWgLockManagers() {
14 $this->setMwGlobals( 'wgLockManagers',
15 [ [ 'name' => 'a', 'class' => 'b' ], [ 'name' => 'c', 'class' => 'd' ] ] );
16 LockManagerGroup
::destroySingletons();
18 $lmg = LockManagerGroup
::singleton();
19 $domain = WikiMap
::getCurrentWikiDbDomain()->getId();
22 [ 'class' => 'b', 'name' => 'a', 'domain' => $domain ],
23 $lmg->config( 'a' ) );
25 [ 'class' => 'd', 'name' => 'c', 'domain' => $domain ],
26 $lmg->config( 'c' ) );
29 public function testSingletonFalse() {
30 $this->setMwGlobals( 'wgLockManagers', [ [ 'name' => 'a', 'class' => 'b' ] ] );
31 LockManagerGroup
::destroySingletons();
34 WikiMap
::getCurrentWikiDbDomain()->getId(),
35 LockManagerGroup
::singleton( false )->config( 'a' )['domain']
39 public function testSingletonNull() {
40 $this->setMwGlobals( 'wgLockManagers', [ [ 'name' => 'a', 'class' => 'b' ] ] );
41 LockManagerGroup
::destroySingletons();
45 LockManagerGroup
::singleton( null )->config( 'a' )['domain']
49 public function testDestroySingletons() {
50 $instance = LockManagerGroup
::singleton();
51 $this->assertSame( $instance, LockManagerGroup
::singleton() );
52 LockManagerGroup
::destroySingletons();
53 $this->assertNotSame( $instance, LockManagerGroup
::singleton() );
56 public function testDestroySingletonsNamedDomain() {
57 $instance = LockManagerGroup
::singleton( 'domain' );
58 $this->assertSame( $instance, LockManagerGroup
::singleton( 'domain' ) );
59 LockManagerGroup
::destroySingletons();
60 $this->assertNotSame( $instance, LockManagerGroup
::singleton( 'domain' ) );
63 public function testGetDBLockManager() {
64 $this->markTestSkipped( 'DBLockManager case in LockManagerGroup::get appears to be ' .
65 'broken, tries to instantiate an abstract class' );
67 $mockLB = $this->createMock( ILoadBalancer
::class );
68 $mockLB->expects( $this->never() )
69 ->method( $this->anythingBut( '__destruct', 'getLazyConnectionRef' ) );
70 $mockLB->expects( $this->once() )->method( 'getLazyConnectionRef' )
71 ->with( DB_MASTER
, [], 'domain', $mockLB::CONN_TRX_AUTOCOMMIT
)
72 ->willReturn( 'bogus value' );
74 $mockLBFactory = $this->createMock( LBFactory
::class );
75 $mockLBFactory->expects( $this->never() )
76 ->method( $this->anythingBut( '__destruct', 'getMainLB' ) );
77 $mockLBFactory->expects( $this->once() )->method( 'getMainLB' )->with( 'domain' )
78 ->willReturn( $mockLB );
80 $lmg = new LockManagerGroup( 'domain',
81 [ [ 'name' => 'a', 'class' => DBLockManager
::class ] ], $mockLBFactory );
82 $this->assertSame( [], $lmg->get( 'a' ) );