Commit a900ed83 authored by Steve Müller's avatar Steve Müller

Merge pull request #822 from DHager/trailing_stopwatch_fix

Fix for bad profiling data, showing an indefinitely long query
parents 26195bed c66fccab
......@@ -164,6 +164,9 @@ class Statement implements \IteratorAggregate, DriverStatement
try {
$stmt = $this->stmt->execute($params);
} catch (\Exception $ex) {
if ($logger) {
$logger->stopQuery();
}
throw DBALException::driverExceptionDuringQuery(
$this->conn->getDriver(),
$ex,
......
......@@ -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