Skip to content

Commit

Permalink
Make test cover hasmany that includes complex types.
Browse files Browse the repository at this point in the history
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 4c84d90
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions tests/TestCase/ORM/QueryTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
]
]
]
Expand Down

0 comments on commit 4c84d90

Please sign in to comment.