wiki.techinc.nl/tests/phpunit/unit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php
Reedy 85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00

76 lines
2 KiB
PHP

<?php
namespace Wikimedia\Tests\Rdbms;
use MediaWikiUnitTestCase;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\LoadBalancer;
use Wikimedia\Rdbms\SessionConsistentConnectionManager;
/**
* @covers \Wikimedia\Rdbms\SessionConsistentConnectionManager
*
* @author Daniel Kinzler
*/
class SessionConsistentConnectionManagerTest extends MediaWikiUnitTestCase {
public function testGetReadConnection() {
$database = $this->createMock( IDatabase::class );
$lb = $this->createMock( LoadBalancer::class );
$lb->expects( $this->once() )
->method( 'getConnection' )
->with( DB_REPLICA )
->willReturn( $database );
$manager = new SessionConsistentConnectionManager( $lb );
$actual = $manager->getReadConnection();
$this->assertSame( $database, $actual );
}
public function testGetReadConnectionReturnsWriteDbOnForceMaster() {
$database = $this->createMock( IDatabase::class );
$lb = $this->createMock( LoadBalancer::class );
$lb->expects( $this->once() )
->method( 'getConnection' )
->with( DB_PRIMARY )
->willReturn( $database );
$manager = new SessionConsistentConnectionManager( $lb );
$manager->prepareForUpdates();
$actual = $manager->getReadConnection();
$this->assertSame( $database, $actual );
}
public function testGetWriteConnection() {
$database = $this->createMock( IDatabase::class );
$lb = $this->createMock( LoadBalancer::class );
$lb->expects( $this->once() )
->method( 'getConnection' )
->with( DB_PRIMARY )
->willReturn( $database );
$manager = new SessionConsistentConnectionManager( $lb );
$actual = $manager->getWriteConnection();
$this->assertSame( $database, $actual );
}
public function testForceMaster() {
$database = $this->createMock( IDatabase::class );
$lb = $this->createMock( LoadBalancer::class );
$lb->expects( $this->once() )
->method( 'getConnection' )
->with( DB_PRIMARY )
->willReturn( $database );
$manager = new SessionConsistentConnectionManager( $lb );
$manager->prepareForUpdates();
$manager->getReadConnection();
}
}