Browse Source

Showing that caching a query result actually works.

Refs #6228
Jose Lorenzo Rodriguez 11 years ago
parent
commit
baedcff9db
1 changed files with 26 additions and 0 deletions
  1. 26 0
      tests/TestCase/ORM/QueryTest.php

+ 26 - 0
tests/TestCase/ORM/QueryTest.php

@@ -1726,6 +1726,32 @@ class QueryTest extends TestCase
     }
 
     /**
+     * Integration test for query caching usigna  real cache engine and
+     * a formatResults callback
+     *
+     * @return void
+     */
+    public function testCacheIntegrationWithFormatResults()
+    {
+        $table = TableRegistry::get('Articles');
+        $query = new Query($this->connection, $table);
+        $cacher = new \Cake\Cache\Engine\FileEngine();
+        $cacher->init();
+
+        $query
+            ->select(['id', 'title'])
+            ->formatResults(function ($results) {
+                return $results->combine('id', 'title');
+            })
+            ->cache('my_key', $cacher);
+
+        $expected = $query->toArray();
+        $query = new Query($this->connection, $table);
+        $results = $query->cache('my_key', $cacher)->toArray();
+        $this->assertSame($expected, $results);
+    }
+
+    /**
      * Integration test to show filtering associations using contain and a closure
      *
      * @return void