Skip to content

Commit

Permalink
Merge pull request #169 from dpb587/bugfix-disabled-DebugStack
Browse files Browse the repository at this point in the history
Fix DebugStack->stopQuery to prevent unnecessary timings when disabled.
  • Loading branch information
guilhermeblanco committed Jul 10, 2012
2 parents 40d9841 + d103898 commit 00ac50c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Doctrine/DBAL/Logging/DebugStack.php
Expand Up @@ -61,7 +61,9 @@ public function startQuery($sql, array $params = null, array $types = null)
*/
public function stopQuery()
{
$this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start;
if ($this->enabled) {
$this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start;
}
}
}

47 changes: 47 additions & 0 deletions tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php
@@ -0,0 +1,47 @@
<?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);
}
}

0 comments on commit 00ac50c

Please sign in to comment.