Skip to content
Permalink
Browse files

Fix failing tests around positional replacements.

Both named and positional placeholders should be replaced correctly.
Positional arguments with double digit values should also be handled
correctly.
  • Loading branch information...
markstory committed May 8, 2015
1 parent bec7304 commit 5b475a1f15ec5dca553868316c76c2743ab7041c
Showing with 19 additions and 2 deletions.
  1. +1 −2 src/Database/Log/QueryLogger.php
  2. +18 −0 tests/TestCase/Database/Log/QueryLoggerTest.php
@@ -71,9 +71,8 @@ protected function _interpolate($query)
$keys = [];
$limit = is_int(key($params)) ? 1 : -1;
$params = array_reverse($params);
foreach ($params as $key => $param) {
$keys[] = is_string($key) ? "/:$key/" : '/[?]/';
$keys[] = is_string($key) ? "/:$key\b/" : '/[?]/';
}
return preg_replace($keys, $params, $query->query, $limit);
@@ -102,6 +102,24 @@ public function testStringInterpolation3()
$this->assertEquals($expected, (string)$query);
}
/**
* Tests that named placeholders
*
* @return void
*/
public function testStringInterpolationNamed()
{
$logger = $this->getMock('\Cake\Database\Log\QueryLogger', ['_log']);
$query = new LoggedQuery;
$query->query = 'SELECT a FROM b where a = :p1 AND b = :p11 AND c = :p20 AND d = :p2';
$query->params = ['p11' => 'test', 'p1' => 'string', 'p2' => 3, 'p20' => 5];
$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";
$this->assertEquals($expected, (string)$query);
}
/**
* Tests that the logged query object is passed to the built-in logger using
* the correct scope

0 comments on commit 5b475a1

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