Skip to content

Commit

Permalink
Asserting that tuple comparison is used for eager laoding HasMany
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 12, 2014
1 parent f0ba802 commit f664429
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Test/TestCase/ORM/Association/HasManyTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


use Cake\Database\Expression\IdentifierExpression; use Cake\Database\Expression\IdentifierExpression;
use Cake\Database\Expression\QueryExpression; use Cake\Database\Expression\QueryExpression;
use Cake\Database\Expression\TupleComparison;
use Cake\ORM\Association\HasMany; use Cake\ORM\Association\HasMany;
use Cake\ORM\Entity; use Cake\ORM\Entity;
use Cake\ORM\Query; use Cake\ORM\Query;
Expand Down Expand Up @@ -430,7 +431,7 @@ public function testEagerLoaderMultipleKeys() {
$this->author->primaryKey(['id', 'site_id']); $this->author->primaryKey(['id', 'site_id']);
$association = new HasMany('Articles', $config); $association = new HasMany('Articles', $config);
$keys = [[1, 10], [2, 20], [3, 30], [4, 40]]; $keys = [[1, 10], [2, 20], [3, 30], [4, 40]];
$query = $this->getMock('Cake\ORM\Query', ['all'], [null, null]); $query = $this->getMock('Cake\ORM\Query', ['all', 'andWhere'], [null, null]);
$this->article->expects($this->once())->method('find')->with('all') $this->article->expects($this->once())->method('find')->with('all')
->will($this->returnValue($query)); ->will($this->returnValue($query));
$results = [ $results = [
Expand All @@ -440,6 +441,13 @@ public function testEagerLoaderMultipleKeys() {
$query->expects($this->once())->method('all') $query->expects($this->once())->method('all')
->will($this->returnValue($results)); ->will($this->returnValue($results));


$tuple = new TupleComparison(
['Articles.author_id', 'Articles.site_id'], $keys, [], 'IN'
);
$query->expects($this->once())->method('andWhere')
->with($tuple)
->will($this->returnSelf());

$callable = $association->eagerLoader(compact('keys', 'query')); $callable = $association->eagerLoader(compact('keys', 'query'));
$row = ['Authors__id' => 2, 'Authors__site_id' => 10, 'username' => 'author 1']; $row = ['Authors__id' => 2, 'Authors__site_id' => 10, 'username' => 'author 1'];
$result = $callable($row); $result = $callable($row);
Expand Down

0 comments on commit f664429

Please sign in to comment.