Skip to content

Commit

Permalink
Adding test case to prove adding subqueries in form clause works
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 15, 2013
1 parent 3423414 commit 967aca3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/Cake/Test/TestCase/Model/Datasource/Database/QueryTest.php
Expand Up @@ -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.