Merge "Make Special:ChangeContentModel field labels consistently use colons"
[lhc/web/wiklou.git] / tests / phpunit / unit / includes / filebackend / lockmanager / LockManagerGroupTest.php
1 <?php
2
3 use Wikimedia\Rdbms\LBFactory;
4 use Wikimedia\TestingAccessWrapper;
5
6 /**
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.
11 *
12 * @covers LockManagerGroup
13 */
14 class LockManagerGroupTest extends MediaWikiUnitTestCase {
15 private function getMockLBFactory() {
16 $mock = $this->createMock( LBFactory::class );
17 $mock->expects( $this->never() )->method( $this->anythingBut( '__destruct' ) );
18 return $mock;
19 }
20
21 public function testConstructorNoConfigs() {
22 new LockManagerGroup( 'domain', [], $this->getMockLBFactory() );
23 $this->assertTrue( true, 'No exception thrown' );
24 }
25
26 public function testConstructorConfigWithNoName() {
27 $this->setExpectedException( Exception::class,
28 'Cannot register a lock manager with no name.' );
29
30 new LockManagerGroup( 'domain',
31 [ [ 'name' => 'a', 'class' => 'b' ], [ 'class' => 'c' ] ], $this->getMockLBFactory() );
32 }
33
34 public function testConstructorConfigWithNoClass() {
35 $this->setExpectedException( Exception::class,
36 'Cannot register lock manager `c` with no class.' );
37
38 new LockManagerGroup( 'domain',
39 [ [ 'name' => 'a', 'class' => 'b' ], [ 'name' => 'c' ] ], $this->getMockLBFactory() );
40 }
41
42 public function testGetUndefined() {
43 $this->setExpectedException( Exception::class,
44 'No lock manager defined with the name `c`.' );
45
46 $lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b' ] ],
47 $this->getMockLBFactory() );
48 $lmg->get( 'c' );
49 }
50
51 public function testConfigUndefined() {
52 $this->setExpectedException( Exception::class,
53 'No lock manager defined with the name `c`.' );
54
55 $lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b' ] ],
56 $this->getMockLBFactory() );
57 $lmg->config( 'c' );
58 }
59
60 public function testConfig() {
61 $lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b', 'foo' => 'c' ] ],
62 $this->getMockLBFactory() );
63 $this->assertSame(
64 [ 'class' => 'b', 'name' => 'a', 'foo' => 'c', 'domain' => 'domain' ],
65 $lmg->config( 'a' )
66 );
67 }
68
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 );
77 }
78
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`.' );
83
84 $lmg = new LockManagerGroup( 'domain', [ [ 'name' => 'a', 'class' => 'b' ] ],
85 $this->getMockLBFactory() );
86 $lmg->getAny();
87 }
88 }