Skip to content
Permalink
Browse files

Adding test case to prove adding subqueries in form clause works

  • Loading branch information...
lorenzo committed Jan 15, 2013
1 parent 3423414 commit 967aca3dc85095d5b13669ff4c4ac52a71d8f1d1
Showing with 27 additions and 0 deletions.
  1. +27 −0 lib/Cake/Test/TestCase/Model/Datasource/Database/QueryTest.php
@@ -1301,4 +1301,31 @@ public function testSuqueryInSelect() {
->from(['a' => 'dates'])->execute();
}
/**
* Tests that Query objects can be included inside the from clause
* and be used as a normal table, including binding any passed parameter
*
* @return void
**/
public function testSuqueryInFrom() {
$this->_insertDateRecords();
$this->_insertTwoRecords();
$query = new Query($this->connection);
$subquery = (new Query($this->connection))
->select(['id', 'name'])
->from('dates')
->where(['posted >' => new \DateTime('2012-12-21 12:00')], ['posted' => 'datetime']);
$result = $query
->select(['name'])
->from(['b' => $subquery])
->where(['id !=' => 3])
->execute();
$expected = [
['name' => 'Bruce Lee'],
];
$this->assertEquals($expected, $result->fetchAll('assoc'));
}
}

0 comments on commit 967aca3

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