Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

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

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

Danny Berger

Should I resubmit to a different branch?

Christophe Coevoet

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

Thanks - I'll resubmit.

Danny Berger dpb587 closed this
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
View
@@ -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;
+ }
}
}
-
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);
+ }
+}
Something went wrong with that request. Please try again.