|
17 | 17 | use Cake\Cache\Cache;
|
18 | 18 | use Cake\Cache\Engine\FileEngine;
|
19 | 19 | use Cake\Core\Configure;
|
| 20 | +use Cake\ORM\ResultSet; |
| 21 | +use Cake\ORM\TableRegistry; |
20 | 22 | use Cake\TestSuite\TestCase;
|
| 23 | +use TestApp\Model\Table\ArticlesTable; |
21 | 24 |
|
22 | 25 | /**
|
23 | 26 | * FileEngineTest class
|
24 | 27 | */
|
25 | 28 | class FileEngineTest extends TestCase
|
26 | 29 | {
|
| 30 | + /** |
| 31 | + * @var array |
| 32 | + */ |
| 33 | + public $fixtures = [ |
| 34 | + 'core.articles' |
| 35 | + ]; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var bool |
| 39 | + */ |
| 40 | + public $autoFixtures = false; |
27 | 41 |
|
28 | 42 | /**
|
29 | 43 | * setUp method
|
@@ -192,6 +206,34 @@ public function testSerialize()
|
192 | 206 | $this->assertSame(unserialize($read), $data);
|
193 | 207 | }
|
194 | 208 |
|
| 209 | + /** |
| 210 | + * Verify across PHP versions that caching of ResultSet objects works as expected. |
| 211 | + * |
| 212 | + * @see https://github.com/cakephp/cakephp/issues/10111 |
| 213 | + * @return void |
| 214 | + */ |
| 215 | + public function testResultSetCache() |
| 216 | + { |
| 217 | + Configure::write('App.namespace', 'TestApp'); |
| 218 | + $this->loadFixtures('Articles'); |
| 219 | + |
| 220 | + /* @var ArticlesTable $articles */ |
| 221 | + $articles = TableRegistry::get('Articles'); |
| 222 | + $query = $articles->find()->all(); |
| 223 | + $this->assertInstanceOf(ResultSet::class, $query); |
| 224 | + $this->assertSame(3, count($query->toArray())); |
| 225 | + |
| 226 | + $this->_configCache(['serialize' => true]); |
| 227 | + $write = Cache::write('articles', $query, 'file_test'); |
| 228 | + $this->assertTrue($write); |
| 229 | + |
| 230 | + $read = Cache::read('articles', 'file_test'); |
| 231 | + $this->assertInstanceOf(ResultSet::class, $read); |
| 232 | + $this->assertSame(3, count($read->toArray())); |
| 233 | + |
| 234 | + TableRegistry::clear(); |
| 235 | + } |
| 236 | + |
195 | 237 | /**
|
196 | 238 | * testClear method
|
197 | 239 | *
|
|
0 commit comments