Skip to content
Permalink
Browse files

Renaming QueryLogger::write to log()

  • Loading branch information...
lorenzo committed Apr 1, 2013
1 parent 547cf94 commit 2f3e8bec386ea36a4efe92fabec5f99b1db073e4
@@ -496,9 +496,9 @@ public function logger($instance = null) {
* @return void
*/
public function log($sql) {
$logged = new LoggedQuery;
$logged->query = $sql;
$this->logger()->write($logged);
$query = new LoggedQuery;
$query->query = $sql;
$this->logger()->log($query);
}
/**
@@ -48,12 +48,12 @@ public function execute($params = null) {
$t = microtime(true);
$result = parent::execute($params);
$logged = new LoggedQuery;
$logged->took = round((microtime(true) - $t) * 1000, 0);
$logged->numRows = $this->rowCount();
$logged->params = $params ?: $this->_compiledParams;
$logged->query = $this->queryString;
$this->logger()->write($logged);
$query = new LoggedQuery;
$query->took = round((microtime(true) - $t) * 1000, 0);
$query->numRows = $this->rowCount();
$query->params = $params ?: $this->_compiledParams;
$query->query = $this->queryString;
$this->logger()->log($query);
return $result;
}
@@ -33,7 +33,7 @@ class QueryLogger {
* @param LoggedQuery $query to be written in log
* @return void
*/
public function write(LoggedQuery $query) {
public function log(LoggedQuery $query) {
if (!empty($query->params)) {
$query->query = $this->_interpolate($query);
}
@@ -650,14 +650,14 @@ public function testLoggerDecorator() {
}
/**
* Tests that log() function writes to the configured query logger
* Tests that log() function logs to the configured query logger
*
* @return void
*/
public function testLogFunction() {
$logger = $this->getMock('\Cake\Model\Datasource\Database\Log\QueryLogger');
$this->connection->logger($logger);
$logger->expects($this->once())->method('write')
$logger->expects($this->once())->method('log')
->with($this->logicalAnd(
$this->isInstanceOf('\Cake\Model\Datasource\Database\Log\LoggedQuery'),
$this->attributeEqualTo('query', 'SELECT 1')
@@ -673,12 +673,12 @@ public function testLogFunction() {
public function testLogBeginRollbackTransaction() {
$logger = $this->getMock('\Cake\Model\Datasource\Database\Log\QueryLogger');
$this->connection->logger($logger);
$logger->expects($this->at(0))->method('write')
$logger->expects($this->at(0))->method('log')
->with($this->logicalAnd(
$this->isInstanceOf('\Cake\Model\Datasource\Database\Log\LoggedQuery'),
$this->attributeEqualTo('query', 'BEGIN')
));
$logger->expects($this->at(1))->method('write')
$logger->expects($this->at(1))->method('log')
->with($this->logicalAnd(
$this->isInstanceOf('\Cake\Model\Datasource\Database\Log\LoggedQuery'),
$this->attributeEqualTo('query', 'ROLLBACK')
@@ -697,7 +697,7 @@ public function testLogBeginRollbackTransaction() {
public function testLogCommitTransaction() {
$logger = $this->getMock('\Cake\Model\Datasource\Database\Log\QueryLogger');
$this->connection->logger($logger);
$logger->expects($this->at(1))->method('write')
$logger->expects($this->at(1))->method('log')
->with($this->logicalAnd(
$this->isInstanceOf('\Cake\Model\Datasource\Database\Log\LoggedQuery'),
$this->attributeEqualTo('query', 'COMMIT')
@@ -35,7 +35,7 @@ public function testExecuteNoParams() {
$inner->expects($this->once())->method('rowCount')->will($this->returnValue(3));
$logger = $this->getMock('\Cake\Model\Datasource\Database\Log\QueryLogger');
$logger->expects($this->once())
->method('write')
->method('log')
->with($this->logicalAnd(
$this->isInstanceOf('\Cake\Model\Datasource\Database\Log\LoggedQuery'),
$this->attributeEqualTo('query', 'SELECT bar FROM foo'),
@@ -59,7 +59,7 @@ public function testExecuteWithParams() {
$inner->expects($this->once())->method('rowCount')->will($this->returnValue(4));
$logger = $this->getMock('\Cake\Model\Datasource\Database\Log\QueryLogger');
$logger->expects($this->once())
->method('write')
->method('log')
->with($this->logicalAnd(
$this->isInstanceOf('\Cake\Model\Datasource\Database\Log\LoggedQuery'),
$this->attributeEqualTo('query', 'SELECT bar FROM foo'),
@@ -83,7 +83,7 @@ public function testExecuteWithBinding() {
$inner->expects($this->any())->method('rowCount')->will($this->returnValue(4));
$logger = $this->getMock('\Cake\Model\Datasource\Database\Log\QueryLogger');
$logger->expects($this->at(0))
->method('write')
->method('log')
->with($this->logicalAnd(
$this->isInstanceOf('\Cake\Model\Datasource\Database\Log\LoggedQuery'),
$this->attributeEqualTo('query', 'SELECT bar FROM foo'),
@@ -92,7 +92,7 @@ public function testExecuteWithBinding() {
$this->attributeEqualTo('params', ['a' => 1, 'b' => '2013-01-01'])
));
$logger->expects($this->at(1))
->method('write')
->method('log')
->with($this->logicalAnd(
$this->isInstanceOf('\Cake\Model\Datasource\Database\Log\LoggedQuery'),
$this->attributeEqualTo('query', 'SELECT bar FROM foo'),
@@ -74,7 +74,7 @@ public function testStingInterpolation() {
$query->params = ['p1' => 'string', 'p2' => 3, 'p3' => null];
$logger->expects($this->once())->method('_log')->with($query);
$logger->write($query);
$logger->log($query);
$expected = "SELECT a FROM b where a = 'string' AND b = 3 AND c = NULL";
$this->assertEquals($expected, (string)$query);
}
@@ -91,7 +91,7 @@ public function testStingInterpolation2() {
$query->params = ['string', '3', null];
$logger->expects($this->once())->method('_log')->with($query);
$logger->write($query);
$logger->log($query);
$expected = "SELECT a FROM b where a = 'string' AND b = '3' AND c = NULL";
$this->assertEquals($expected, (string)$query);
}
@@ -112,7 +112,7 @@ public function testLogFunction() {
$engine2 = $this->getMock('\Cake\Log\Engine\BaseLog', ['write'], ['scopes' => ['foo']]);
Log::engine('queryLoggerTest2', $engine);
$engine2->expects($this->never())->method('write');
$logger->write($query);
$logger->log($query);
}

0 comments on commit 2f3e8be

Please sign in to comment.
You can’t perform that action at this time.