Skip to content

Commit

Permalink
Adding another test showing that parameters ar bound in subqueries too
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 14, 2013
1 parent bfd7a4b commit 3423414
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/Cake/Test/TestCase/Model/Datasource/Database/QueryTest.php
Expand Up @@ -1265,6 +1265,12 @@ public function testSelectOffset() {
$this->assertEquals(['id' => 3], $result->fetch('assoc'));
}

/**
* Tests that Query objects can be included inside the select clause
* and be used as a normal field, including binding any passed parameter
*
* @return void
**/
public function testSuqueryInSelect() {
$this->_insertDateRecords();
$this->_insertTwoRecords();
Expand All @@ -1285,7 +1291,14 @@ public function testSuqueryInSelect() {
];
$this->assertEquals($expected, $result->fetchAll('assoc'));


$query = new Query($this->connection);
$subquery = (new Query($this->connection))
->select('name')
->from(['b' => 'authors'])
->where(['name' => 'Chuck Norris'], ['name' => 'string']);
$result = $query
->select(['id', 'name' => $subquery])
->from(['a' => 'dates'])->execute();

This comment has been minimized.

Copy link
@markstory

markstory Jan 28, 2013

Member

Should you include any assertions for the results?

This comment has been minimized.

Copy link
@lorenzo

lorenzo Jan 28, 2013

Author Member

Hmm, I remember adding the asserts there. Thanks for noticing

}

}

0 comments on commit 3423414

Please sign in to comment.