summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKunio Murasawa <[email protected]>2014-06-24 10:37:35 +0900
committerKunio Murasawa <[email protected]>2014-06-24 10:37:35 +0900
commitb65268cea3ecd96f278e51a2936d0d7ab0286c18 (patch)
tree1ecfe3d307a99761ee00666da4fe3a115b98fd4b /test
parentb0922d8719a94e3a0e0e4a0ca3876f4f91475dcf (diff)
Support named placeholders logging and test
Diffstat (limited to 'test')
-rw-r--r--test/QueryBuilderPsr1Test53.php6
-rw-r--r--test/QueryBuilderTest.php6
-rw-r--r--test/bootstrap.php7
3 files changed, 15 insertions, 4 deletions
diff --git a/test/QueryBuilderPsr1Test53.php b/test/QueryBuilderPsr1Test53.php
index 0aa8930..3b267eb 100644
--- a/test/QueryBuilderPsr1Test53.php
+++ b/test/QueryBuilderPsr1Test53.php
@@ -274,6 +274,12 @@ class QueryBuilderPsr1Test53 extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected, ORM::getLastQuery());
}
+ public function testRawQueryWithNamedPlaceholders() {
+ ORM::forTable('widget')->rawQuery('SELECT `w`.* FROM `widget` w WHERE `name` = :name AND `age` = :age', array(':name' => 'Fred', ':age' => 5))->findMany();
+ $expected = "SELECT `w`.* FROM `widget` w WHERE `name` = 'Fred' AND `age` = '5'";
+ $this->assertEquals($expected, ORM::getLastQuery());
+ }
+
public function testSimpleResultColumn() {
ORM::forTable('widget')->select('name')->findMany();
$expected = "SELECT `name` FROM `widget`";
diff --git a/test/QueryBuilderTest.php b/test/QueryBuilderTest.php
index 9c4ef97..54320d0 100644
--- a/test/QueryBuilderTest.php
+++ b/test/QueryBuilderTest.php
@@ -304,6 +304,12 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected, ORM::get_last_query());
}
+ public function testRawQueryWithNamedPlaceholders() {
+ ORM::for_table('widget')->raw_query('SELECT `w`.* FROM `widget` w WHERE `name` = :name AND `age` = :age', array(':name' => 'Fred', ':age' => 5))->find_many();
+ $expected = "SELECT `w`.* FROM `widget` w WHERE `name` = 'Fred' AND `age` = '5'";
+ $this->assertEquals($expected, ORM::get_last_query());
+ }
+
public function testSimpleResultColumn() {
ORM::for_table('widget')->select('name')->find_many();
$expected = "SELECT `name` FROM `widget`";
diff --git a/test/bootstrap.php b/test/bootstrap.php
index 3b3cace..02d9725 100644
--- a/test/bootstrap.php
+++ b/test/bootstrap.php
@@ -46,15 +46,14 @@ class MockPDOStatement extends PDOStatement {
/**
* Add data to arrays
*/
- public function bindParam($index, $value, $type)
+ public function bindParam($key, $value, $type)
{
- // Do check on index, and type
- if (!is_int($index)) throw new Exception('Incorrect parameter type. Expected $index to be an integer.');
+ // Do check on type
if (!is_int($type) || ($type != PDO::PARAM_STR && $type != PDO::PARAM_NULL && $type != PDO::PARAM_BOOL && $type != PDO::PARAM_INT))
throw new Exception('Incorrect parameter type. Expected $type to be an integer.');
// Add param to array
- $this->bindParams[$index - 1] = $value;
+ $this->bindParams[is_int($key) ? --$key : $key] = $value;
}
/**