From 02c2535da498124071ac64a15e8103c946bebcad Mon Sep 17 00:00:00 2001 From: Daniel Mecke Date: Fri, 28 Feb 2014 14:38:53 +0100 Subject: [PATCH] added backtrace to query logging --- lib/Doctrine/DBAL/Logging/DebugStack.php | 2 +- .../Tests/DBAL/Logging/DebugStackTest.php | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/DBAL/Logging/DebugStack.php b/lib/Doctrine/DBAL/Logging/DebugStack.php index b143a3ee28e..0b5a1f36adc 100644 --- a/lib/Doctrine/DBAL/Logging/DebugStack.php +++ b/lib/Doctrine/DBAL/Logging/DebugStack.php @@ -62,7 +62,7 @@ public function startQuery($sql, array $params = null, array $types = null) { if ($this->enabled) { $this->start = microtime(true); - $this->queries[++$this->currentQuery] = array('sql' => $sql, 'params' => $params, 'types' => $types, 'executionMS' => 0); + $this->queries[++$this->currentQuery] = array('sql' => $sql, 'params' => $params, 'types' => $types, 'executionMS' => 0, 'stacktrace' => debug_backtrace(true)); } } diff --git a/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php b/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php index 00bc0b6fe80..b68d0b531e8 100644 --- a/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php +++ b/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php @@ -19,17 +19,14 @@ public function tearDown() 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->assertTrue(is_array($this->logger->queries)); + $this->assertTrue(is_array($this->logger->queries[1])); + $this->assertEquals('SELECT column FROM table', $this->logger->queries[1]['sql']); + $this->assertNull($this->logger->queries[1]['params']); + $this->assertNull($this->logger->queries[1]['types']); + $this->assertEquals(0, $this->logger->queries[1]['executionMS']); + $this->assertTrue(is_array($this->logger->queries[1]['stacktrace'])); + $this->assertNotEmpty($this->logger->queries[1]['stacktrace']); $this->logger->stopQuery(); $this->assertGreaterThan(0, $this->logger->queries[1]['executionMS']);