3 use Wikimedia\Rdbms\LBFactory
;
4 use Wikimedia\TestingAccessWrapper
;
7 * Since this is a unit test, we don't test the singleton() or destroySingletons() methods. We also
8 * can't test get() with a valid argument, because that winds up calling static methods of
9 * ObjectCache and LoggerFactory that aren't yet compatible with proper unit tests. Those will be
10 * tested in the integration test for now.
12 * @covers LockManagerGroup
14 class LockManagerGroupTest
extends MediaWikiUnitTestCase
{
15 private function getMockLBFactory() {
16 $mock = $this->createMock( LBFactory
::class );
17 $mock->expects( $this->never() )->method( $this->anythingBut( '__destruct' ) );
21 public function testConstructorNoConfigs() {
22 new LockManagerGroup( 'domain', [], $this->getMockLBFactory() );
23 $this->assertTrue( true, 'No exception thrown' );
26 public function testConstructorConfigWithNoName() {
27 $this->setExpectedException( Exception
::class,
28 'Cannot register a lock manager with no name.' );
30 new LockManagerGroup( 'domain',
31 [ [ 'name' => 'a', 'class' => 'b' ], [ 'class' => 'c' ] ], $this->getMockLBFactory() );
34 public function testConstructorConfigWithNoClass() {
35 $this->setExpectedException( Exception
::class,
36 'Cannot register lock manager `c` with no class.' );
38 new LockManagerGroup( 'domain',
39 [ [ 'name' => 'a', 'class' => 'b' ], [ 'name' => 'c' ] ], $this->getMockLBFactory() );
42 public function testGetUndefined() {
43 $this->setExpectedException( Exception
::class,
44 'No lock manager defined with the name `c`.' );
46 $lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b' ] ],
47 $this->getMockLBFactory() );
51 public function testConfigUndefined() {
52 $this->setExpectedException( Exception
::class,
53 'No lock manager defined with the name `c`.' );
55 $lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b' ] ],
56 $this->getMockLBFactory() );
60 public function testConfig() {
61 $lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b', 'foo' => 'c' ] ],
62 $this->getMockLBFactory() );
64 [ 'class' => 'b', 'name' => 'a', 'foo' => 'c', 'domain' => 'domain' ],
69 public function testGetDefaultNull() {
70 $lmg = new LockManagerGroup( 'domain', [], $this->getMockLBFactory() );
71 $expected = new NullLockManager( [] );
72 $actual = $lmg->getDefault();
73 // Have to get rid of the $sessions for equality check to work
74 TestingAccessWrapper
::newFromObject( $actual )->session
= null;
75 TestingAccessWrapper
::newFromObject( $expected )->session
= null;
76 $this->assertEquals( $expected, $actual );
79 public function testGetAnyException() {
80 // XXX Isn't the name 'getAny' misleading if we don't get whatever's available?
81 $this->setExpectedException( Exception
::class,
82 'No lock manager defined with the name `fsLockManager`.' );
84 $lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b' ] ],
85 $this->getMockLBFactory() );