Commit 7c467c34 authored by Darien Hager's avatar Darien Hager Committed by Steve Müller

Add a unit-test to verify that when statements throw exceptions, the logger...

Add a unit-test to verify that when statements throw exceptions, the logger still has stopQuery called.
parent 9800888d
......@@ -17,15 +17,20 @@ class StatementTest extends \Doctrine\Tests\DbalTestCase
* @var \Doctrine\DBAL\Configuration
*/
private $configuration;
/**
* @var \PDOStatement
*/
private $pdoStatement;
public function setUp()
{
$pdoStatement = $this->getMock('\PDOStatment', array('execute', 'bindParam', 'bindValue'));
$this->pdoStatement = $this->getMock('\PDOStatement', array('execute', 'bindParam', 'bindValue'));
$platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
$driverConnection = $this->getMock('\Doctrine\DBAL\Driver\Connection');
$driverConnection->expects($this->any())
->method('prepare')
->will($this->returnValue($pdoStatement));
->will($this->returnValue($this->pdoStatement));
$driver = $this->getMock('\Doctrine\DBAL\Driver');
$constructorArgs = array(
......@@ -43,6 +48,11 @@ class StatementTest extends \Doctrine\Tests\DbalTestCase
$this->conn->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($this->configuration));
$this->conn->expects($this->any())
->method('getDriver')
->will($this->returnValue($driver));
}
public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound()
......@@ -88,4 +98,34 @@ class StatementTest extends \Doctrine\Tests\DbalTestCase
$statement = new Statement($sql, $this->conn);
$statement->execute($values);
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testExecuteCallsLoggerStopQueryOnException()
{
$logger = $this->getMock('\Doctrine\DBAL\Logging\SQLLogger');
$this->configuration->expects($this->once())
->method('getSQLLogger')
->will($this->returnValue($logger));
// Needed to satisfy construction of DBALException
$this->conn->expects($this->any())
->method('resolveParams')
->will($this->returnValue(array()));
$logger->expects($this->once())
->method('startQuery');
$logger->expects($this->once())
->method('stopQuery');
$this->pdoStatement->expects($this->once())
->method('execute')
->will($this->throwException(new \Exception("Mock test exception")));
$statement = new Statement("", $this->conn);
$statement->execute();
}
}
\ No newline at end of file
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