Commit 00ac50c0 authored by Guilherme Blanco's avatar Guilherme Blanco

Merge pull request #169 from dpb587/bugfix-disabled-DebugStack

Fix DebugStack->stopQuery to prevent unnecessary timings when disabled.
parents 40d9841f d1038981
...@@ -61,7 +61,9 @@ class DebugStack implements SQLLogger ...@@ -61,7 +61,9 @@ class DebugStack implements SQLLogger
*/ */
public function stopQuery() public function stopQuery()
{ {
if ($this->enabled) {
$this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start; $this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start;
} }
}
} }
<?php
namespace Doctrine\Tests\DBAL\Logging;
require_once __DIR__ . '/../../TestInit.php';
class DebugStackTest extends \Doctrine\Tests\DbalTestCase
{
public function setUp()
{
$this->logger = new \Doctrine\DBAL\Logging\DebugStack();
}
public function tearDown()
{
unset($this->logger);
}
public function testLoggedQuery()
{
$this->logger->startQuery('SELECT column FROM table');
$this->assertEquals(
array(
1 => array(
'sql' => 'SELECT column FROM table',
'params' => null,
'types' => null,
'executionMS' => 0,
),
),
$this->logger->queries
);
$this->logger->stopQuery();
$this->assertGreaterThan(0, $this->logger->queries[1]['executionMS']);
}
public function testLoggedQueryDisabled()
{
$this->logger->enabled = false;
$this->logger->startQuery('SELECT column FROM table');
$this->assertEquals(array(), $this->logger->queries);
$this->logger->stopQuery();
$this->assertEquals(array(), $this->logger->queries);
}
}
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