Debian Codegraph @

tests/phpunit/unit/includes/filebackend/lockmanager/LockManagerGroupTest.php

raw symbols SCIP
1 <?php
2
3 use Wikimedia\Rdbms\LBFactory;
4
5 /**
6 * Since this is a unit test, we don't test the singleton() or destroySingletons() methods. We also
7 * can't test get() with a valid argument, because that winds up calling static methods of
8 * ObjectCache and LoggerFactory that aren't yet compatible with proper unit tests. Those will be
9 * tested in the integration test for now.
10 *
11 * @covers \LockManagerGroup
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 }