wiki.techinc.nl/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php
Timo Tijhof bee9f4db96 Remove various redundant '@license' tags in file headers
Redundant given this is the project-wide license already,
especially in file headers that already include the GPL license
header.

This and other minor fixups based on feedback from Ie0cea0ef5027c7e5.

* Add @file where missing.
* Move @ingroup and @deprecated from file to class doc where needed.

Change-Id: I7067abb7abee1f0c238cb2536e16192e946d8daa
2018-01-12 18:15:11 +00:00

108 lines
2.8 KiB
PHP

<?php
namespace Wikimedia\Tests\Rdbms;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\LoadBalancer;
use PHPUnit_Framework_MockObject_MockObject;
use Wikimedia\Rdbms\SessionConsistentConnectionManager;
/**
* @covers Wikimedia\Rdbms\SessionConsistentConnectionManager
*
* @author Daniel Kinzler
*/
class SessionConsistentConnectionManagerTest extends \PHPUnit_Framework_TestCase {
/**
* @return IDatabase|PHPUnit_Framework_MockObject_MockObject
*/
private function getIDatabaseMock() {
return $this->getMockBuilder( IDatabase::class )
->getMock();
}
/**
* @return LoadBalancer|PHPUnit_Framework_MockObject_MockObject
*/
private function getLoadBalancerMock() {
$lb = $this->getMockBuilder( LoadBalancer::class )
->disableOriginalConstructor()
->getMock();
return $lb;
}
public function testGetReadConnection() {
$database = $this->getIDatabaseMock();
$lb = $this->getLoadBalancerMock();
$lb->expects( $this->once() )
->method( 'getConnection' )
->with( DB_REPLICA )
->will( $this->returnValue( $database ) );
$manager = new SessionConsistentConnectionManager( $lb );
$actual = $manager->getReadConnection();
$this->assertSame( $database, $actual );
}
public function testGetReadConnectionReturnsWriteDbOnForceMatser() {
$database = $this->getIDatabaseMock();
$lb = $this->getLoadBalancerMock();
$lb->expects( $this->once() )
->method( 'getConnection' )
->with( DB_MASTER )
->will( $this->returnValue( $database ) );
$manager = new SessionConsistentConnectionManager( $lb );
$manager->prepareForUpdates();
$actual = $manager->getReadConnection();
$this->assertSame( $database, $actual );
}
public function testGetWriteConnection() {
$database = $this->getIDatabaseMock();
$lb = $this->getLoadBalancerMock();
$lb->expects( $this->once() )
->method( 'getConnection' )
->with( DB_MASTER )
->will( $this->returnValue( $database ) );
$manager = new SessionConsistentConnectionManager( $lb );
$actual = $manager->getWriteConnection();
$this->assertSame( $database, $actual );
}
public function testForceMaster() {
$database = $this->getIDatabaseMock();
$lb = $this->getLoadBalancerMock();
$lb->expects( $this->once() )
->method( 'getConnection' )
->with( DB_MASTER )
->will( $this->returnValue( $database ) );
$manager = new SessionConsistentConnectionManager( $lb );
$manager->prepareForUpdates();
$manager->getReadConnection();
}
public function testReleaseConnection() {
$database = $this->getIDatabaseMock();
$lb = $this->getLoadBalancerMock();
$lb->expects( $this->once() )
->method( 'reuseConnection' )
->with( $database )
->will( $this->returnValue( null ) );
$manager = new SessionConsistentConnectionManager( $lb );
$manager->releaseConnection( $database );
}
}