0615e9510d123fe2ab87afcbbe5cb0ef1af5a703
[lhc/web/wiklou.git] / tests / phpunit / includes / filebackend / lockmanager / LockManagerGroupIntegrationTest.php
1 <?php
2
3 use Wikimedia\Rdbms\ILoadBalancer;
4 use Wikimedia\Rdbms\LBFactory;
5
6 /**
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.
9 *
10 * @covers LockManagerGroup
11 */
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();
17
18 $lmg = LockManagerGroup::singleton();
19 $domain = WikiMap::getCurrentWikiDbDomain()->getId();
20
21 $this->assertSame(
22 [ 'class' => 'b', 'name' => 'a', 'domain' => $domain ],
23 $lmg->config( 'a' ) );
24 $this->assertSame(
25 [ 'class' => 'd', 'name' => 'c', 'domain' => $domain ],
26 $lmg->config( 'c' ) );
27 }
28
29 public function testSingletonFalse() {
30 $this->setMwGlobals( 'wgLockManagers', [ [ 'name' => 'a', 'class' => 'b' ] ] );
31 LockManagerGroup::destroySingletons();
32
33 $this->assertSame(
34 WikiMap::getCurrentWikiDbDomain()->getId(),
35 LockManagerGroup::singleton( false )->config( 'a' )['domain']
36 );
37 }
38
39 public function testSingletonNull() {
40 $this->setMwGlobals( 'wgLockManagers', [ [ 'name' => 'a', 'class' => 'b' ] ] );
41 LockManagerGroup::destroySingletons();
42
43 $this->assertSame(
44 null,
45 LockManagerGroup::singleton( null )->config( 'a' )['domain']
46 );
47 }
48
49 public function testDestroySingletons() {
50 $instance = LockManagerGroup::singleton();
51 $this->assertSame( $instance, LockManagerGroup::singleton() );
52 LockManagerGroup::destroySingletons();
53 $this->assertNotSame( $instance, LockManagerGroup::singleton() );
54 }
55
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' ) );
61 }
62
63 public function testGetDBLockManager() {
64 $this->markTestSkipped( 'DBLockManager case in LockManagerGroup::get appears to be ' .
65 'broken, tries to instantiate an abstract class' );
66
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' );
73
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 );
79
80 $lmg = new LockManagerGroup( 'domain',
81 [ [ 'name' => 'a', 'class' => DBLockManager::class ] ], $mockLBFactory );
82 $this->assertSame( [], $lmg->get( 'a' ) );
83 }
84 }