Skip to content

Loading…

DebugStack should ignore stopQuery when disabled #168

Closed
wants to merge 1 commit into from

3 participants

@dpb587

I noticed that DebugStack was adding an empty element when it was disabled. This PR changes it to match startQuery with its behavior.

1) Doctrine\Tests\DBAL\Logging\DebugStackTest::testLoggedQueryDisabled
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array
 (
+    [0] => Array
+        (
+            [executionMS] => 1341871660.9651
+        )
+
 )

I've submitted the PR to 2.0.x since that's where the bug is first seen and is still listed as stable on doctrine-project.org. Preferably this could also be applied to newer branches as well, or I can also submit separate PRs.

@travisbot

This pull request fails (merged d0352d7 into c1e4ec6).

@stof
Doctrine member

2.0.x is not maintained anymore for bug fixes, it receives only security fixes.

@dpb587

Should I resubmit to a different branch?

@stof
Doctrine member

Well, the best way is to submit a PR to master. This is where the development occurs (and where several people can merge it). @beberlei then chooses which PR should be backported to the maintenance branches (this one would be backported to 2.2 at least as it is a bugfix)

@dpb587

Thanks - I'll resubmit.

@dpb587 dpb587 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 50 additions and 2 deletions.
  1. +3 −2 lib/Doctrine/DBAL/Logging/DebugStack.php
  2. +47 −0 tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php
View
5 lib/Doctrine/DBAL/Logging/DebugStack.php
@@ -61,7 +61,8 @@ 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;
+ }
}
}
-
View
47 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);
+ }
+}
Something went wrong with that request. Please try again.