Commit d1038981 authored by Danny Berger's avatar Danny Berger

Fix DebugStack->stopQuery to prevent unnecessary timings when disabled.

parent 40d9841f
......@@ -61,7 +61,9 @@ class DebugStack implements SQLLogger
*/
public function stopQuery()
{
$this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start;
if ($this->enabled) {
$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