From ba917d38a4aab270d28de48543a5a2936ea1a2c2 Mon Sep 17 00:00:00 2001 From: Bernat Arlandis Date: Thu, 21 Jan 2016 16:43:51 +0100 Subject: [PATCH] Log query execution time and rows (#8077) --- src/Database/Log/LoggedQuery.php | 2 +- tests/TestCase/Database/Log/LoggedQueryTest.php | 2 +- tests/TestCase/Database/Log/QueryLoggerTest.php | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Database/Log/LoggedQuery.php b/src/Database/Log/LoggedQuery.php index 603c186213f..cb528fcb56c 100644 --- a/src/Database/Log/LoggedQuery.php +++ b/src/Database/Log/LoggedQuery.php @@ -65,6 +65,6 @@ class LoggedQuery */ public function __toString() { - return $this->query; + return "duration={$this->took} rows={$this->numRows} {$this->query}"; } } diff --git a/tests/TestCase/Database/Log/LoggedQueryTest.php b/tests/TestCase/Database/Log/LoggedQueryTest.php index a61bdd6b9a2..87f9d14653b 100644 --- a/tests/TestCase/Database/Log/LoggedQueryTest.php +++ b/tests/TestCase/Database/Log/LoggedQueryTest.php @@ -33,6 +33,6 @@ public function testStringConversion() { $logged = new LoggedQuery; $logged->query = 'SELECT foo FROM bar'; - $this->assertEquals('SELECT foo FROM bar', (string)$logged); + $this->assertEquals('duration=0 rows=0 SELECT foo FROM bar', (string)$logged); } } diff --git a/tests/TestCase/Database/Log/QueryLoggerTest.php b/tests/TestCase/Database/Log/QueryLoggerTest.php index 0ad824fb9e8..48ddd836693 100644 --- a/tests/TestCase/Database/Log/QueryLoggerTest.php +++ b/tests/TestCase/Database/Log/QueryLoggerTest.php @@ -62,7 +62,7 @@ public function testStringInterpolation() $logger->expects($this->once())->method('_log')->with($query); $logger->log($query); - $expected = "SELECT a FROM b where a = 'string' AND b = 3 AND c = NULL AND d = 1 AND e = 0 AND f = 0"; + $expected = "duration=0 rows=0 SELECT a FROM b where a = 'string' AND b = 3 AND c = NULL AND d = 1 AND e = 0 AND f = 0"; $this->assertEquals($expected, (string)$query); } @@ -80,7 +80,7 @@ public function testStringInterpolation2() $logger->expects($this->once())->method('_log')->with($query); $logger->log($query); - $expected = "SELECT a FROM b where a = 'string' AND b = '3' AND c = NULL AND d = 1 AND e = 0 AND f = 0"; + $expected = "duration=0 rows=0 SELECT a FROM b where a = 'string' AND b = '3' AND c = NULL AND d = 1 AND e = 0 AND f = 0"; $this->assertEquals($expected, (string)$query); } @@ -98,7 +98,7 @@ public function testStringInterpolation3() $logger->expects($this->once())->method('_log')->with($query); $logger->log($query); - $expected = "SELECT a FROM b where a = 'string' AND b = 'string' AND c = 3 AND d = 3"; + $expected = "duration=0 rows=0 SELECT a FROM b where a = 'string' AND b = 'string' AND c = 3 AND d = 3"; $this->assertEquals($expected, (string)$query); } @@ -116,7 +116,7 @@ public function testStringInterpolationNamed() $logger->expects($this->once())->method('_log')->with($query); $logger->log($query); - $expected = "SELECT a FROM b where a = 'string' AND b = 'test' AND c = 5 AND d = 3"; + $expected = "duration=0 rows=0 SELECT a FROM b where a = 'string' AND b = 'test' AND c = 5 AND d = 3"; $this->assertEquals($expected, (string)$query); }