Browse Source

Make test cover hasmany that includes complex types.

This test will also help to cover when hydration fails in the future.
Mark Story 10 years ago
parent
commit
4c84d900cf
1 changed files with 16 additions and 11 deletions
  1. 16 11
      tests/TestCase/ORM/QueryTest.php

+ 16 - 11
tests/TestCase/ORM/QueryTest.php

@@ -20,6 +20,7 @@ use Cake\Database\Expression\QueryExpression;
 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 @@ class QueryTest extends TestCase
     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',
                     ]
                 ]
             ]