wiki.techinc.nl/tests/phpunit/unit/includes/filebackend/lockmanager/LockManagerGroupFactoryTest.php
Aryeh Gregor 5a6c18a086 LockManagerGroupFactory to replace singletons
100% test coverage of code that appears to be working and used, in both
LockManagerGroupFactory and also LockManagerGroup. Where possible I
wrote it as unit tests. One preexisting code path seems to be broken and
I marked the test as skipped. Two methods look unused and perhaps not
especially helpful, so I didn't write tests for them yet in case we want
to just get rid of them instead.

Change-Id: Iaa7354f31c451b87773468609c674a3bf1d4382f
2019-08-27 13:19:15 +03:00

34 lines
1.5 KiB
PHP

<?php
use MediaWiki\FileBackend\LockManager\LockManagerGroupFactory;
use Wikimedia\Rdbms\LBFactory;
/**
* @covers MediaWiki\FileBackend\LockManager\LockManagerGroupFactory
* @todo Should we somehow test that the LockManagerGroup objects are as we expect? How do we do
* that without getting into testing LockManagerGroup itself?
*/
class LockManagerGroupFactoryTest extends MediaWikiUnitTestCase {
public function testGetLockManagerGroup() {
$mockLbFactory = $this->createMock( LBFactory::class );
$mockLbFactory->expects( $this->never() )->method( $this->anything() );
$factory = new LockManagerGroupFactory( 'defaultDomain', [], $mockLbFactory );
$lbmUnspecified = $factory->getLockManagerGroup();
$lbmFalse = $factory->getLockManagerGroup( false );
$lbmDefault = $factory->getLockManagerGroup( 'defaultDomain' );
$lbmOther = $factory->getLockManagerGroup( 'otherDomain' );
$this->assertSame( $lbmUnspecified, $lbmFalse );
$this->assertSame( $lbmFalse, $lbmDefault );
$this->assertSame( $lbmDefault, $lbmUnspecified );
$this->assertNotEquals( $lbmUnspecified, $lbmOther );
$this->assertNotEquals( $lbmFalse, $lbmOther );
$this->assertNotEquals( $lbmDefault, $lbmOther );
$this->assertSame( $lbmUnspecified, $factory->getLockManagerGroup() );
$this->assertSame( $lbmFalse, $factory->getLockManagerGroup( false ) );
$this->assertSame( $lbmDefault, $factory->getLockManagerGroup( 'defaultDomain' ) );
$this->assertSame( $lbmOther, $factory->getLockManagerGroup( 'otherDomain' ) );
}
}