2019-08-15 18:07:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use Wikimedia\Rdbms\LBFactory;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Since this is a unit test, we don't test the singleton() or destroySingletons() methods. We also
|
|
|
|
|
* can't test get() with a valid argument, because that winds up calling static methods of
|
|
|
|
|
* ObjectCache and LoggerFactory that aren't yet compatible with proper unit tests. Those will be
|
|
|
|
|
* tested in the integration test for now.
|
|
|
|
|
*
|
2024-02-16 18:04:47 +00:00
|
|
|
* @covers \LockManagerGroup
|
2019-08-15 18:07:36 +00:00
|
|
|
*/
|
|
|
|
|
class LockManagerGroupTest extends MediaWikiUnitTestCase {
|
|
|
|
|
private function getMockLBFactory() {
|
2022-07-18 08:39:00 +00:00
|
|
|
return $this->createNoOpMock( LBFactory::class );
|
2019-08-15 18:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testConstructorNoConfigs() {
|
|
|
|
|
new LockManagerGroup( 'domain', [], $this->getMockLBFactory() );
|
|
|
|
|
$this->assertTrue( true, 'No exception thrown' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testConstructorConfigWithNoName() {
|
2019-10-05 04:47:46 +00:00
|
|
|
$this->expectException( Exception::class );
|
|
|
|
|
$this->expectExceptionMessage( 'Cannot register a lock manager with no name.' );
|
2019-08-15 18:07:36 +00:00
|
|
|
|
|
|
|
|
new LockManagerGroup( 'domain',
|
|
|
|
|
[ [ 'name' => 'a', 'class' => 'b' ], [ 'class' => 'c' ] ], $this->getMockLBFactory() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testConstructorConfigWithNoClass() {
|
2019-10-05 04:47:46 +00:00
|
|
|
$this->expectException( Exception::class );
|
|
|
|
|
$this->expectExceptionMessage( 'Cannot register lock manager `c` with no class.' );
|
2019-08-15 18:07:36 +00:00
|
|
|
|
|
|
|
|
new LockManagerGroup( 'domain',
|
|
|
|
|
[ [ 'name' => 'a', 'class' => 'b' ], [ 'name' => 'c' ] ], $this->getMockLBFactory() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetUndefined() {
|
2019-10-05 04:47:46 +00:00
|
|
|
$this->expectException( Exception::class );
|
|
|
|
|
$this->expectExceptionMessage( 'No lock manager defined with the name `c`.' );
|
2019-08-15 18:07:36 +00:00
|
|
|
|
|
|
|
|
$lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b' ] ],
|
|
|
|
|
$this->getMockLBFactory() );
|
|
|
|
|
$lmg->get( 'c' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testConfigUndefined() {
|
2019-10-05 04:47:46 +00:00
|
|
|
$this->expectException( Exception::class );
|
|
|
|
|
$this->expectExceptionMessage( 'No lock manager defined with the name `c`.' );
|
2019-08-15 18:07:36 +00:00
|
|
|
|
|
|
|
|
$lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b' ] ],
|
|
|
|
|
$this->getMockLBFactory() );
|
|
|
|
|
$lmg->config( 'c' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testConfig() {
|
|
|
|
|
$lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b', 'foo' => 'c' ] ],
|
|
|
|
|
$this->getMockLBFactory() );
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[ 'class' => 'b', 'name' => 'a', 'foo' => 'c', 'domain' => 'domain' ],
|
|
|
|
|
$lmg->config( 'a' )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|