From: addshore Date: Thu, 1 Dec 2016 00:15:38 +0000 (+0000) Subject: Fix SessionConsistentConnectionManagerTest class and file name X-Git-Tag: 1.31.0-rc.0~4710 X-Git-Url: http://git.cyclocoop.org//%27http:/code.google.com/p/ie7-js//%27?a=commitdiff_plain;h=a4bd573142b329943cd6a6155d0a0182c604d53a;p=lhc%2Fweb%2Fwiklou.git Fix SessionConsistentConnectionManagerTest class and file name Change-Id: If60f081946b8f3bb564f2bb17fd1261af0cb7e3a --- diff --git a/tests/phpunit/includes/libs/rdbms/connectionmanager/ConsistentReadConnectionManagerTest.php b/tests/phpunit/includes/libs/rdbms/connectionmanager/ConsistentReadConnectionManagerTest.php deleted file mode 100644 index 5ac97b2295..0000000000 --- a/tests/phpunit/includes/libs/rdbms/connectionmanager/ConsistentReadConnectionManagerTest.php +++ /dev/null @@ -1,164 +0,0 @@ -getMock( IDatabase::class ); - } - - /** - * @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 ); - } - - public function testBeginAtomicSection() { - $database = $this->getIDatabaseMock(); - $lb = $this->getLoadBalancerMock(); - - $lb->expects( $this->exactly( 2 ) ) - ->method( 'getConnection' ) - ->with( DB_MASTER ) - ->will( $this->returnValue( $database ) ); - - $database->expects( $this->once() ) - ->method( 'startAtomic' ) - ->will( $this->returnValue( null ) ); - - $manager = new SessionConsistentConnectionManager( $lb ); - $manager->beginAtomicSection( 'TEST' ); - - // Should also ask for a DB_MASTER connection. - // This is asserted by the $lb mock. - $manager->getReadConnection(); - } - - public function testCommitAtomicSection() { - $database = $this->getIDatabaseMock(); - $lb = $this->getLoadBalancerMock(); - - $lb->expects( $this->once() ) - ->method( 'reuseConnection' ) - ->with( $database ) - ->will( $this->returnValue( null ) ); - - $database->expects( $this->once() ) - ->method( 'endAtomic' ) - ->will( $this->returnValue( null ) ); - - $manager = new SessionConsistentConnectionManager( $lb ); - $manager->commitAtomicSection( $database, 'TEST' ); - } - - public function testRollbackAtomicSection() { - $database = $this->getIDatabaseMock(); - $lb = $this->getLoadBalancerMock(); - - $lb->expects( $this->once() ) - ->method( 'reuseConnection' ) - ->with( $database ) - ->will( $this->returnValue( null ) ); - - $database->expects( $this->once() ) - ->method( 'rollback' ) - ->will( $this->returnValue( null ) ); - - $manager = new SessionConsistentConnectionManager( $lb ); - $manager->rollbackAtomicSection( $database, 'TEST' ); - } - -} diff --git a/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php b/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php new file mode 100644 index 0000000000..4dcab82df8 --- /dev/null +++ b/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php @@ -0,0 +1,164 @@ +getMock( IDatabase::class ); + } + + /** + * @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 ); + } + + public function testBeginAtomicSection() { + $database = $this->getIDatabaseMock(); + $lb = $this->getLoadBalancerMock(); + + $lb->expects( $this->exactly( 2 ) ) + ->method( 'getConnection' ) + ->with( DB_MASTER ) + ->will( $this->returnValue( $database ) ); + + $database->expects( $this->once() ) + ->method( 'startAtomic' ) + ->will( $this->returnValue( null ) ); + + $manager = new SessionConsistentConnectionManager( $lb ); + $manager->beginAtomicSection( 'TEST' ); + + // Should also ask for a DB_MASTER connection. + // This is asserted by the $lb mock. + $manager->getReadConnection(); + } + + public function testCommitAtomicSection() { + $database = $this->getIDatabaseMock(); + $lb = $this->getLoadBalancerMock(); + + $lb->expects( $this->once() ) + ->method( 'reuseConnection' ) + ->with( $database ) + ->will( $this->returnValue( null ) ); + + $database->expects( $this->once() ) + ->method( 'endAtomic' ) + ->will( $this->returnValue( null ) ); + + $manager = new SessionConsistentConnectionManager( $lb ); + $manager->commitAtomicSection( $database, 'TEST' ); + } + + public function testRollbackAtomicSection() { + $database = $this->getIDatabaseMock(); + $lb = $this->getLoadBalancerMock(); + + $lb->expects( $this->once() ) + ->method( 'reuseConnection' ) + ->with( $database ) + ->will( $this->returnValue( null ) ); + + $database->expects( $this->once() ) + ->method( 'rollback' ) + ->will( $this->returnValue( null ) ); + + $manager = new SessionConsistentConnectionManager( $lb ); + $manager->rollbackAtomicSection( $database, 'TEST' ); + } + +}