Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

DebugStack should ignore stopQuery when disabled #168

Closed
wants to merge 1 commit into from

3 participants

Danny Berger Don't Add Me To Your Organization a.k.a The Travis Bot Christophe Coevoet
Danny Berger
dpb587 commented July 09, 2012

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.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged d0352d7 into c1e4ec6).

Christophe Coevoet
stof commented July 09, 2012

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

Danny Berger
dpb587 commented July 09, 2012

Should I resubmit to a different branch?

Christophe Coevoet
stof commented July 09, 2012

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)

Danny Berger
dpb587 commented July 09, 2012

Thanks - I'll resubmit.

Danny Berger dpb587 closed this July 09, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
5  lib/Doctrine/DBAL/Logging/DebugStack.php
@@ -61,7 +61,8 @@ public function startQuery($sql, array $params = null, array $types = null)
61 61
      */
62 62
     public function stopQuery()
63 63
     {
64  
-        $this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start;
  64
+        if ($this->enabled) {
  65
+            $this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start;
  66
+        }
65 67
     }
66 68
 }
67  
-
47  tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php
... ...
@@ -0,0 +1,47 @@
  1
+<?php
  2
+
  3
+namespace Doctrine\Tests\DBAL\Logging;
  4
+
  5
+require_once __DIR__ . '/../../TestInit.php';
  6
+
  7
+class DebugStackTest extends \Doctrine\Tests\DbalTestCase
  8
+{
  9
+    public function setUp()
  10
+    {
  11
+        $this->logger = new \Doctrine\DBAL\Logging\DebugStack();
  12
+    }
  13
+
  14
+    public function tearDown()
  15
+    {
  16
+        unset($this->logger);
  17
+    }
  18
+
  19
+    public function testLoggedQuery()
  20
+    {
  21
+        $this->logger->startQuery('SELECT column FROM table');
  22
+        $this->assertEquals(
  23
+            array(
  24
+                1 => array(
  25
+                    'sql' => 'SELECT column FROM table',
  26
+                    'params' => null,
  27
+                    'types' => null,
  28
+                    'executionMS' => 0,
  29
+                ),
  30
+            ),
  31
+            $this->logger->queries
  32
+        );
  33
+
  34
+        $this->logger->stopQuery();
  35
+        $this->assertGreaterThan(0, $this->logger->queries[1]['executionMS']);
  36
+    }
  37
+
  38
+    public function testLoggedQueryDisabled()
  39
+    {
  40
+        $this->logger->enabled = false;
  41
+        $this->logger->startQuery('SELECT column FROM table');
  42
+        $this->assertEquals(array(), $this->logger->queries);
  43
+
  44
+        $this->logger->stopQuery();
  45
+        $this->assertEquals(array(), $this->logger->queries);
  46
+    }
  47
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.