One small change that was supposed to be in 5a6c18a086 but didn't make
it into the patch version that got merged, and removal of some long-dead
code.
phan objected to the use of new $class without being explicitly
reassured that $class is, in fact, a string. I don't know why.
Change-Id: Ifa00c59ab4464109414f21db37e3a6db21decdf3
84 lines
2.9 KiB
PHP
84 lines
2.9 KiB
PHP
<?php
|
|
|
|
use Wikimedia\Rdbms\ILoadBalancer;
|
|
use Wikimedia\Rdbms\LBFactory;
|
|
|
|
/**
|
|
* Most of the file is covered by the unit test and/or FileBackendTest. Here we fill in the missing
|
|
* bits that don't work with unit tests yet.
|
|
*
|
|
* @covers LockManagerGroup
|
|
*/
|
|
class LockManagerGroupIntegrationTest extends MediaWikiIntegrationTestCase {
|
|
public function testWgLockManagers() {
|
|
$this->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(
|
|
WikiMap::getCurrentWikiDbDomain()->getId(),
|
|
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' ) );
|
|
}
|
|
}
|