Skip to content

Commit

Permalink
Log query execution time and rows (#8077)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernat Arlandis committed Jan 21, 2016
1 parent 16726e6 commit ba917d3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Database/Log/LoggedQuery.php
Expand Up @@ -65,6 +65,6 @@ class LoggedQuery
*/
public function __toString()
{
return $this->query;
return "duration={$this->took} rows={$this->numRows} {$this->query}";
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/Database/Log/LoggedQueryTest.php
Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions tests/TestCase/Database/Log/QueryLoggerTest.php
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit ba917d3

Please sign in to comment.