Skip to content

Commit

Permalink
Fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 14, 2014
1 parent ac3710d commit 277422c
Showing 1 changed file with 65 additions and 46 deletions.
111 changes: 65 additions & 46 deletions Test/TestCase/ORM/Association/BelongsToManyTest.php
Expand Up @@ -428,7 +428,7 @@ public function testEagerLoader() {
]);
$association = new BelongsToMany('Tags', $config);
$keys = [1, 2, 3, 4];
$query = $this->getMock('Cake\ORM\Query', ['all', 'contain'], [null, null]);
$query = $this->getMock('Cake\ORM\Query', ['all', 'matching'], [null, null]);

$this->tag->expects($this->once())
->method('find')
Expand All @@ -443,14 +443,18 @@ public function testEagerLoader() {
->method('all')
->will($this->returnValue($results));

$query->expects($this->once())->method('contain')
->with([
'ArticlesTags' => [
'conditions' => ['ArticlesTags.article_id in' => $keys],
'matching' => true
]
])
->will($this->returnSelf());
$query->expects($this->once())->method('matching')
->will($this->returnCallback(function($alias, $callable) use ($query, $keys) {
$this->assertEquals('ArticlesTags', $alias);
$q = $this->getMock('Cake\ORM\Query', [], [null, null]);

$q->expects($this->once())->method('andWhere')
->with(['ArticlesTags.article_id IN' => $keys])
->will($this->returnSelf());

$this->assertSame($q, $callable($q));
return $query;
}));

$query->hydrate(false);

Expand Down Expand Up @@ -491,7 +495,7 @@ public function testEagerLoaderWithDefaults() {
]);
$association = new BelongsToMany('Tags', $config);
$keys = [1, 2, 3, 4];
$methods = ['all', 'contain', 'where', 'order'];
$methods = ['all', 'matching', 'where', 'order'];
$query = $this->getMock('Cake\ORM\Query', $methods, [null, null]);
$this->tag->expects($this->once())
->method('find')
Expand All @@ -505,15 +509,18 @@ public function testEagerLoaderWithDefaults() {
->method('all')
->will($this->returnValue($results));

$query->expects($this->once())
->method('contain')
->with([
'ArticlesTags' => [
'conditions' => ['ArticlesTags.article_id in' => $keys],
'matching' => true
]
])
->will($this->returnSelf());
$query->expects($this->once())->method('matching')
->will($this->returnCallback(function($alias, $callable) use ($query, $keys) {
$this->assertEquals('ArticlesTags', $alias);
$q = $this->getMock('Cake\ORM\Query', [], [null, null]);

$q->expects($this->once())->method('andWhere')
->with(['ArticlesTags.article_id IN' => $keys])
->will($this->returnSelf());

$this->assertSame($q, $callable($q));
return $query;
}));

$query->expects($this->at(0))->method('where')
->with(['Tags.name' => 'foo'])
Expand Down Expand Up @@ -552,7 +559,7 @@ public function testEagerLoaderWithOverrides() {
]);
$association = new BelongsToMany('Tags', $config);
$keys = [1, 2, 3, 4];
$methods = ['all', 'contain', 'where', 'order', 'select'];
$methods = ['all', 'matching', 'where', 'order', 'select'];
$query = $this->getMock('Cake\ORM\Query', $methods, [null, null]);
$this->tag->expects($this->once())->method('find')->with('all')
->will($this->returnValue($query));
Expand All @@ -563,14 +570,18 @@ public function testEagerLoaderWithOverrides() {
$query->expects($this->once())->method('all')
->will($this->returnValue($results));

$query->expects($this->once())->method('contain')
->with([
'ArticlesTags' => [
'conditions' => ['ArticlesTags.article_id in' => $keys],
'matching' => true
]
])
->will($this->returnSelf());
$query->expects($this->once())->method('matching')
->will($this->returnCallback(function($alias, $callable) use ($query, $keys) {
$this->assertEquals('ArticlesTags', $alias);
$q = $this->getMock('Cake\ORM\Query', [], [null, null]);

$q->expects($this->once())->method('andWhere')
->with(['ArticlesTags.article_id IN' => $keys])
->will($this->returnSelf());

$this->assertSame($q, $callable($q));
return $query;
}));

$query->expects($this->at(0))->method('where')
->with(['Tags.name' => 'foo'])
Expand Down Expand Up @@ -669,7 +680,7 @@ public function testEagerLoaderSubquery() {

$query = $this->getMock(
'Cake\ORM\Query',
['all', 'where', 'andWhere', 'order', 'select', 'contain'],
['all', 'where', 'andWhere', 'order', 'select', 'matching'],
[null, null]
);
$query->hydrate(false);
Expand Down Expand Up @@ -702,14 +713,18 @@ public function testEagerLoaderSubquery() {
->with([])
->will($this->returnSelf());

$query->expects($this->once())->method('contain')
->with([
'ArticlesTags' => [
'conditions' => ['ArticlesTags.article_id in' => $expected],
'matching' => true
]
])
->will($this->returnSelf());
$query->expects($this->once())->method('matching')
->will($this->returnCallback(function($alias, $callable) use ($query, $expected) {
$this->assertEquals('ArticlesTags', $alias);
$q = $this->getMock('Cake\ORM\Query', [], [null, null]);

$q->expects($this->once())->method('andWhere')
->with(['ArticlesTags.article_id IN' => $expected])
->will($this->returnSelf());

$this->assertSame($q, $callable($q));
return $query;
}));

$callable = $association->eagerLoader([
'query' => $parent, 'strategy' => BelongsToMany::STRATEGY_SUBQUERY,
Expand Down Expand Up @@ -752,7 +767,7 @@ public function testEagerLoaderWithQueryBuilder() {
$keys = [1, 2, 3, 4];
$query = $this->getMock(
'Cake\ORM\Query',
['all', 'contain', 'andWhere', 'limit'],
['all', 'matching', 'andWhere', 'limit'],
[null, null]
);

Expand All @@ -769,14 +784,18 @@ public function testEagerLoaderWithQueryBuilder() {
->method('all')
->will($this->returnValue($results));

$query->expects($this->once())->method('contain')
->with([
'ArticlesTags' => [
'conditions' => ['ArticlesTags.article_id in' => $keys],
'matching' => true
]
])
->will($this->returnSelf());
$query->expects($this->once())->method('matching')
->will($this->returnCallback(function($alias, $callable) use ($query, $keys) {
$this->assertEquals('ArticlesTags', $alias);
$q = $this->getMock('Cake\ORM\Query', [], [null, null]);

$q->expects($this->once())->method('andWhere')
->with(['ArticlesTags.article_id IN' => $keys])
->will($this->returnSelf());

$this->assertSame($q, $callable($q));
return $query;
}));

$query->hydrate(false);

Expand Down

0 comments on commit 277422c

Please sign in to comment.