Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

Fix DebugStack->stopQuery to prevent unnecessary timings when disabled.
  • Loading branch information...
commit 00ac50c0e721b1dcbcc4924938ab648e28feb4cf 2 parents 40d9841 + d103898
Guilherme Blanco guilhermeblanco authored
4 lib/Doctrine/DBAL/Logging/DebugStack.php
View
@@ -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 tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php
View
@@ -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);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.