Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DBAL-11 - Changed Interface of SQLLogger to allow for timing variable…
…s, added tests for logging. Contract of Loggers changed, they are not called before the query but after the query they are logging, which means queries that fail wont appear in the logs.
- Loading branch information
Showing
9 changed files
with
94 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\DBAL\Functional; | ||
|
||
require_once __DIR__ . '/../../TestInit.php'; | ||
|
||
class LoggingTest extends \Doctrine\Tests\DbalFunctionalTestCase | ||
{ | ||
public function testLogExecuteQuery() | ||
{ | ||
$sql = $this->_conn->getDatabasePlatform()->getDummySelectSQL(); | ||
|
||
$logMock = $this->getMock('Doctrine\DBAL\Logging\SQLLogger'); | ||
$logMock->expects($this->once()) | ||
->method('logSQL') | ||
->with($this->equalTo($sql), $this->equalTo(array()), $this->isType('float')); | ||
$this->_conn->getConfiguration()->setSQLLogger($logMock); | ||
$this->_conn->executeQuery($sql, array()); | ||
} | ||
|
||
public function testLogPrepareExecute() | ||
{ | ||
$sql = $this->_conn->getDatabasePlatform()->getDummySelectSQL(); | ||
|
||
$logMock = $this->getMock('Doctrine\DBAL\Logging\SQLLogger'); | ||
$logMock->expects($this->once()) | ||
->method('logSQL') | ||
->with($this->equalTo($sql), $this->equalTo(array()), $this->isType('float')); | ||
$this->_conn->getConfiguration()->setSQLLogger($logMock); | ||
|
||
$stmt = $this->_conn->prepare($sql); | ||
$stmt->execute(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fe0f0e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes it very difficult to tell which query is failing if you get a query exception.
Wouldn't it make more sense to change the interface for the SQLLogger class to have a queryStart() and a queryEnd() function? This way ALL queries can be logged, and timing isn't something that happens automatically, but is left up to the logger if it chooses to do so.