From fc7ff5c1f9a75da11d28d93a9c17853053fd30ee Mon Sep 17 00:00:00 2001 From: Jonathan Vollebregt Date: Mon, 27 Mar 2017 18:45:06 +0200 Subject: [PATCH] Extract repeated code to getExecuteUpdateMockConnection method --- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 71 ++++++-------------- 1 file changed, 21 insertions(+), 50 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index b897b73d2d8..c5705a26306 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -29,6 +29,22 @@ protected function setUp() $this->_conn = \Doctrine\DBAL\DriverManager::getConnection($this->params); } + public function getExecuteUpdateMockConnection() + { + $driverMock = $this->createMock(\Doctrine\DBAL\Driver::class); + + $driverMock->expects($this->any()) + ->method('connect') + ->will($this->returnValue(new DriverConnectionMock())); + + $conn = $this->getMockBuilder(Connection::class) + ->setMethods(['executeUpdate']) + ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) + ->getMock(); + + return $conn; + } + public function testIsConnected() { $this->assertFalse($this->_conn->isConnected()); @@ -280,16 +296,7 @@ public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions() public function testEmptyInsert() { - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); - - $driverMock->expects($this->any()) - ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); - - $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('executeUpdate')) - ->setConstructorArgs(array(array('platform' => new Mocks\MockPlatform()), $driverMock)) - ->getMock(); + $conn = $this->getExecuteUpdateMockConnection(); $conn->expects($this->once()) ->method('executeUpdate') @@ -303,16 +310,7 @@ public function testEmptyInsert() */ public function testUpdateWithDifferentColumnsInDataAndIdentifiers() { - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); - - $driverMock->expects($this->any()) - ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); - - $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('executeUpdate')) - ->setConstructorArgs(array(array('platform' => new Mocks\MockPlatform()), $driverMock)) - ->getMock(); + $conn = $this->getExecuteUpdateMockConnection(); $conn->expects($this->once()) ->method('executeUpdate') @@ -356,16 +354,7 @@ public function testUpdateWithDifferentColumnsInDataAndIdentifiers() */ public function testUpdateWithSameColumnInDataAndIdentifiers() { - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); - - $driverMock->expects($this->any()) - ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); - - $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('executeUpdate')) - ->setConstructorArgs(array(array('platform' => new Mocks\MockPlatform()), $driverMock)) - ->getMock(); + $conn = $this->getExecuteUpdateMockConnection(); $conn->expects($this->once()) ->method('executeUpdate') @@ -408,16 +397,7 @@ public function testUpdateWithSameColumnInDataAndIdentifiers() */ public function testUpdateWithIsNull() { - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); - - $driverMock->expects($this->any()) - ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); - - $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('executeUpdate')) - ->setConstructorArgs(array(array('platform' => new Mocks\MockPlatform()), $driverMock)) - ->getMock(); + $conn = $this->getExecuteUpdateMockConnection(); $conn->expects($this->once()) ->method('executeUpdate') @@ -459,16 +439,7 @@ public function testUpdateWithIsNull() */ public function testDeleteWithIsNull() { - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); - - $driverMock->expects($this->any()) - ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); - - $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('executeUpdate')) - ->setConstructorArgs(array(array('platform' => new Mocks\MockPlatform()), $driverMock)) - ->getMock(); + $conn = $this->getExecuteUpdateMockConnection(); $conn->expects($this->once()) ->method('executeUpdate')