| 1 |
<?php |
| 2 |
|
| 3 |
use Wikimedia\Rdbms\LBFactory; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class LockManagerGroupTest extends MediaWikiUnitTestCase { |
| 14 |
private function getMockLBFactory() { |
| 15 |
return $this->createNoOpMock( LBFactory::class ); |
| 16 |
} |
| 17 |
|
| 18 |
public function testConstructorNoConfigs() { |
| 19 |
new LockManagerGroup( 'domain', [], $this->getMockLBFactory() ); |
| 20 |
$this->assertTrue( true, 'No exception thrown' ); |
| 21 |
} |
| 22 |
|
| 23 |
public function testConstructorConfigWithNoName() { |
| 24 |
$this->expectException( Exception::class ); |
| 25 |
$this->expectExceptionMessage( 'Cannot register a lock manager with no name.' ); |
| 26 |
|
| 27 |
new LockManagerGroup( 'domain', |
| 28 |
[ [ 'name' => 'a', 'class' => 'b' ], [ 'class' => 'c' ] ], $this->getMockLBFactory() ); |
| 29 |
} |
| 30 |
|
| 31 |
public function testConstructorConfigWithNoClass() { |
| 32 |
$this->expectException( Exception::class ); |
| 33 |
$this->expectExceptionMessage( 'Cannot register lock manager `c` with no class.' ); |
| 34 |
|
| 35 |
new LockManagerGroup( 'domain', |
| 36 |
[ [ 'name' => 'a', 'class' => 'b' ], [ 'name' => 'c' ] ], $this->getMockLBFactory() ); |
| 37 |
} |
| 38 |
|
| 39 |
public function testGetUndefined() { |
| 40 |
$this->expectException( Exception::class ); |
| 41 |
$this->expectExceptionMessage( 'No lock manager defined with the name `c`.' ); |
| 42 |
|
| 43 |
$lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b' ] ], |
| 44 |
$this->getMockLBFactory() ); |
| 45 |
$lmg->get( 'c' ); |
| 46 |
} |
| 47 |
|
| 48 |
public function testConfigUndefined() { |
| 49 |
$this->expectException( Exception::class ); |
| 50 |
$this->expectExceptionMessage( 'No lock manager defined with the name `c`.' ); |
| 51 |
|
| 52 |
$lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b' ] ], |
| 53 |
$this->getMockLBFactory() ); |
| 54 |
$lmg->config( 'c' ); |
| 55 |
} |
| 56 |
|
| 57 |
public function testConfig() { |
| 58 |
$lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b', 'foo' => 'c' ] ], |
| 59 |
$this->getMockLBFactory() ); |
| 60 |
$this->assertSame( |
| 61 |
[ 'class' => 'b', 'name' => 'a', 'foo' => 'c', 'domain' => 'domain' ], |
| 62 |
$lmg->config( 'a' ) |
| 63 |
); |
| 64 |
} |
| 65 |
} |