Commit cab04d0e authored by Jonathan Vollebregt's avatar Jonathan Vollebregt

Extract repeated code to getExecuteUpdateMockConnection method

parent 07a48467
...@@ -34,6 +34,22 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase ...@@ -34,6 +34,22 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
$this->_conn = \Doctrine\DBAL\DriverManager::getConnection($this->params); $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() public function testIsConnected()
{ {
$this->assertFalse($this->_conn->isConnected()); $this->assertFalse($this->_conn->isConnected());
...@@ -285,16 +301,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase ...@@ -285,16 +301,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
public function testEmptyInsert() public function testEmptyInsert()
{ {
$driverMock = $this->createMock('Doctrine\DBAL\Driver'); $conn = $this->getExecuteUpdateMockConnection();
$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->expects($this->once()) $conn->expects($this->once())
->method('executeUpdate') ->method('executeUpdate')
...@@ -308,16 +315,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase ...@@ -308,16 +315,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
*/ */
public function testUpdateWithDifferentColumnsInDataAndIdentifiers() public function testUpdateWithDifferentColumnsInDataAndIdentifiers()
{ {
$driverMock = $this->createMock('Doctrine\DBAL\Driver'); $conn = $this->getExecuteUpdateMockConnection();
$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->expects($this->once()) $conn->expects($this->once())
->method('executeUpdate') ->method('executeUpdate')
...@@ -361,16 +359,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase ...@@ -361,16 +359,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
*/ */
public function testUpdateWithSameColumnInDataAndIdentifiers() public function testUpdateWithSameColumnInDataAndIdentifiers()
{ {
$driverMock = $this->createMock('Doctrine\DBAL\Driver'); $conn = $this->getExecuteUpdateMockConnection();
$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->expects($this->once()) $conn->expects($this->once())
->method('executeUpdate') ->method('executeUpdate')
...@@ -413,16 +402,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase ...@@ -413,16 +402,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
*/ */
public function testUpdateWithIsNull() public function testUpdateWithIsNull()
{ {
$driverMock = $this->createMock('Doctrine\DBAL\Driver'); $conn = $this->getExecuteUpdateMockConnection();
$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->expects($this->once()) $conn->expects($this->once())
->method('executeUpdate') ->method('executeUpdate')
...@@ -464,16 +444,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase ...@@ -464,16 +444,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
*/ */
public function testDeleteWithIsNull() public function testDeleteWithIsNull()
{ {
$driverMock = $this->createMock('Doctrine\DBAL\Driver'); $conn = $this->getExecuteUpdateMockConnection();
$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->expects($this->once()) $conn->expects($this->once())
->method('executeUpdate') ->method('executeUpdate')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment