Skip to content

Commit

Permalink
Showing that caching a query result actually works.
Browse files Browse the repository at this point in the history
Refs #6228
  • Loading branch information
lorenzo committed Apr 25, 2015
1 parent 89b0a2f commit baedcff
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/TestCase/ORM/QueryTest.php
Expand Up @@ -1725,6 +1725,32 @@ public function testCacheWriteIntegration()
$query->all();
}

/**
* 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
*
Expand Down

0 comments on commit baedcff

Please sign in to comment.