Skip to content

Commit

Permalink
Extract repeated code to getExecuteUpdateMockConnection method
Browse files Browse the repository at this point in the history
  • Loading branch information
jnvsor committed Mar 27, 2017
1 parent 8e6e090 commit fc7ff5c
Showing 1 changed file with 21 additions and 50 deletions.
71 changes: 21 additions & 50 deletions tests/Doctrine/Tests/DBAL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit fc7ff5c

Please sign in to comment.