Skip to content
Permalink
Browse files

Make test cover hasmany that includes complex types.

This test will also help to cover when hydration fails in the future.
  • Loading branch information...
markstory committed Feb 1, 2016
1 parent 9f6fd40 commit 4c84d900cf8c6d1fb25a1d98c751db460de5b312
Showing with 16 additions and 11 deletions.
  1. +16 −11 tests/TestCase/ORM/QueryTest.php
@@ -20,6 +20,7 @@
use Cake\Database\TypeMap;
use Cake\Database\ValueBinder;
use Cake\Datasource\ConnectionManager;
use Cake\I18n\Time;
use Cake\ORM\Query;
use Cake\ORM\ResultSet;
use Cake\ORM\Table;
@@ -655,28 +656,32 @@ public function testBelongsToManyEagerLoadingNoHydration($strategy)
public function testFilteringByHasManyNoHydration()
{
$query = new Query($this->connection, $this->table);
$table = TableRegistry::get('authors');
TableRegistry::get('articles');
$table->hasMany('articles');
$table = TableRegistry::get('Articles');
$table->hasMany('Comments');
$results = $query->repository($table)
->select()
->hydrate(false)
->matching('articles', function ($q) {
return $q->where(['articles.id' => 2]);
->matching('Comments', function ($q) {
return $q->where(['Comments.user_id' => 4]);
})
->toArray();
$expected = [
[
'id' => 3,
'name' => 'larry',
'id' => 1,
'title' => 'First Article',
'body' => 'First Article Body',
'author_id' => 1,
'published' => 'Y',
'_matchingData' => [
'articles' => [
'Comments' => [
'id' => 2,
'title' => 'Second Article',
'body' => 'Second Article Body',
'author_id' => 3,
'article_id' => 1,
'user_id' => 4,
'comment' => 'Second Comment for First Article',
'published' => 'Y',
'created' => '2007-03-18 10:47:23',
'updated' => '2007-03-18 10:49:31',
]
]
]

0 comments on commit 4c84d90

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