CacheTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 1.2.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Cache;
  16. use Cake\Cache\Cache;
  17. use Cake\Cache\CacheRegistry;
  18. use Cake\Cache\Engine\FileEngine;
  19. use Cake\Core\Configure;
  20. use Cake\Core\Plugin;
  21. use Cake\TestSuite\TestCase;
  22. /**
  23. * CacheTest class
  24. */
  25. class CacheTest extends TestCase
  26. {
  27. /**
  28. * setUp method
  29. *
  30. * @return void
  31. */
  32. public function setUp()
  33. {
  34. parent::setUp();
  35. Cache::enable();
  36. }
  37. /**
  38. * tearDown method
  39. *
  40. * @return void
  41. */
  42. public function tearDown()
  43. {
  44. parent::tearDown();
  45. Cache::drop('tests');
  46. Cache::drop('test_trigger');
  47. }
  48. /**
  49. * Configure cache settings for test
  50. *
  51. * @return void
  52. */
  53. protected function _configCache()
  54. {
  55. Cache::setConfig('tests', [
  56. 'engine' => 'File',
  57. 'path' => TMP,
  58. 'prefix' => 'test_'
  59. ]);
  60. }
  61. /**
  62. * tests Cache::engine() fallback
  63. *
  64. * @return void
  65. */
  66. public function testCacheEngineFallback()
  67. {
  68. $filename = tempnam(TMP, 'tmp_');
  69. Cache::setConfig('tests', [
  70. 'engine' => 'File',
  71. 'path' => $filename,
  72. 'prefix' => 'test_',
  73. 'fallback' => 'tests_fallback'
  74. ]);
  75. Cache::setConfig('tests_fallback', [
  76. 'engine' => 'File',
  77. 'path' => TMP,
  78. 'prefix' => 'test_',
  79. ]);
  80. $engine = Cache::engine('tests');
  81. $path = $engine->getConfig('path');
  82. $this->assertSame(TMP, $path);
  83. Cache::drop('tests');
  84. Cache::drop('tests_fallback');
  85. unlink($filename);
  86. }
  87. /**
  88. * tests cache fallback
  89. *
  90. * @return void
  91. */
  92. public function testCacheFallbackIntegration()
  93. {
  94. $filename = tempnam(TMP, 'tmp_');
  95. Cache::setConfig('tests', [
  96. 'engine' => 'File',
  97. 'path' => $filename,
  98. 'prefix' => 'test_',
  99. 'fallback' => 'tests_fallback',
  100. ]);
  101. Cache::setConfig('tests_fallback', [
  102. 'engine' => 'File',
  103. 'path' => $filename,
  104. 'prefix' => 'test_',
  105. 'fallback' => 'tests_fallback_final',
  106. ]);
  107. Cache::setConfig('tests_fallback_final', [
  108. 'engine' => 'File',
  109. 'path' => TMP,
  110. 'prefix' => 'test_',
  111. ]);
  112. $this->assertTrue(Cache::write('fallback', 'worked', 'tests'));
  113. $this->assertSame('worked', Cache::read('fallback', 'tests'));
  114. $this->assertTrue(Cache::delete('fallback', 'tests'));
  115. Cache::drop('tests');
  116. Cache::drop('tests_fallback');
  117. Cache::drop('tests_fallback_final');
  118. unlink($filename);
  119. }
  120. /**
  121. * Check that no fatal errors are issued doing normal things when Cache.disable is true.
  122. *
  123. * @return void
  124. */
  125. public function testNonFatalErrorsWithCacheDisable()
  126. {
  127. Cache::disable();
  128. $this->_configCache();
  129. $this->assertNull(Cache::write('no_save', 'Noooo!', 'tests'));
  130. $this->assertFalse(Cache::read('no_save', 'tests'));
  131. $this->assertNull(Cache::delete('no_save', 'tests'));
  132. }
  133. /**
  134. * Check that a null instance is returned from engine() when caching is disabled.
  135. *
  136. * @return void
  137. */
  138. public function testNullEngineWhenCacheDisable()
  139. {
  140. $this->_configCache();
  141. Cache::disable();
  142. $result = Cache::engine('tests');
  143. $this->assertInstanceOf('Cake\Cache\Engine\NullEngine', $result);
  144. }
  145. /**
  146. * Test configuring an invalid class fails
  147. *
  148. * @expectedException \RuntimeException
  149. * @expectedExceptionMessage Cache engines must use Cake\Cache\CacheEngine
  150. * @return void
  151. */
  152. public function testConfigInvalidClassType()
  153. {
  154. Cache::setConfig('tests', [
  155. 'className' => '\StdClass'
  156. ]);
  157. Cache::engine('tests');
  158. }
  159. /**
  160. * Test engine init failing causes an error
  161. *
  162. * @expectedException \RuntimeException
  163. * @expectedExceptionMessage not properly configured
  164. * @return void
  165. */
  166. public function testConfigFailedInit()
  167. {
  168. $mock = $this->getMockForAbstractClass('Cake\Cache\CacheEngine', [], '', true, true, true, ['init']);
  169. $mock->method('init')->will($this->returnValue(false));
  170. Cache::setConfig('tests', [
  171. 'engine' => $mock
  172. ]);
  173. Cache::engine('tests');
  174. }
  175. /**
  176. * test configuring CacheEngines in App/libs
  177. *
  178. * @return void
  179. */
  180. public function testConfigWithLibAndPluginEngines()
  181. {
  182. Configure::write('App.namespace', 'TestApp');
  183. Plugin::load('TestPlugin');
  184. $config = ['engine' => 'TestAppCache', 'path' => TMP, 'prefix' => 'cake_test_'];
  185. Cache::setConfig('libEngine', $config);
  186. $engine = Cache::engine('libEngine');
  187. $this->assertInstanceOf('TestApp\Cache\Engine\TestAppCacheEngine', $engine);
  188. $config = ['engine' => 'TestPlugin.TestPluginCache', 'path' => TMP, 'prefix' => 'cake_test_'];
  189. $result = Cache::setConfig('pluginLibEngine', $config);
  190. $engine = Cache::engine('pluginLibEngine');
  191. $this->assertInstanceOf('TestPlugin\Cache\Engine\TestPluginCacheEngine', $engine);
  192. Cache::drop('libEngine');
  193. Cache::drop('pluginLibEngine');
  194. Plugin::unload();
  195. }
  196. /**
  197. * Test write from a config that is undefined.
  198. *
  199. * @expectedException \InvalidArgumentException
  200. * @return void
  201. */
  202. public function testWriteNonExistingConfig()
  203. {
  204. $this->assertFalse(Cache::write('key', 'value', 'totally fake'));
  205. }
  206. /**
  207. * Test write from a config that is undefined.
  208. *
  209. * @expectedException \InvalidArgumentException
  210. * @return void
  211. */
  212. public function testIncrementNonExistingConfig()
  213. {
  214. $this->assertFalse(Cache::increment('key', 1, 'totally fake'));
  215. }
  216. /**
  217. * Test write from a config that is undefined.
  218. *
  219. * @expectedException \InvalidArgumentException
  220. * @return void
  221. */
  222. public function testDecrementNonExistingConfig()
  223. {
  224. $this->assertFalse(Cache::decrement('key', 1, 'totally fake'));
  225. }
  226. /**
  227. * Data provider for valid config data sets.
  228. *
  229. * @return array
  230. */
  231. public static function configProvider()
  232. {
  233. return [
  234. 'Array of data using engine key.' => [[
  235. 'engine' => 'File',
  236. 'path' => TMP . 'tests',
  237. 'prefix' => 'cake_test_'
  238. ]],
  239. 'Array of data using classname key.' => [[
  240. 'className' => 'File',
  241. 'path' => TMP . 'tests',
  242. 'prefix' => 'cake_test_'
  243. ]],
  244. 'Direct instance' => [new FileEngine()],
  245. ];
  246. }
  247. /**
  248. * testConfig method
  249. *
  250. * @dataProvider configProvider
  251. * @return void
  252. */
  253. public function testConfigVariants($config)
  254. {
  255. $this->assertNotContains('test', Cache::configured(), 'test config should not exist.');
  256. Cache::setConfig('tests', $config);
  257. $engine = Cache::engine('tests');
  258. $this->assertInstanceOf('Cake\Cache\Engine\FileEngine', $engine);
  259. $this->assertContains('tests', Cache::configured());
  260. }
  261. /**
  262. * testConfigInvalidEngine method
  263. *
  264. * @expectedException \BadMethodCallException
  265. * @return void
  266. */
  267. public function testConfigInvalidEngine()
  268. {
  269. $config = ['engine' => 'Imaginary'];
  270. Cache::setConfig('test', $config);
  271. Cache::engine('test');
  272. }
  273. /**
  274. * test that trying to configure classes that don't extend CacheEngine fail.
  275. *
  276. * @expectedException \BadMethodCallException
  277. * @return void
  278. */
  279. public function testConfigInvalidObject()
  280. {
  281. $this->getMockBuilder(\StdClass::class)
  282. ->setMockClassName('RubbishEngine')
  283. ->getMock();
  284. Cache::setConfig('test', [
  285. 'engine' => '\RubbishEngine'
  286. ]);
  287. Cache::engine('tests');
  288. }
  289. /**
  290. * Ensure you cannot reconfigure a cache adapter.
  291. *
  292. * @expectedException \BadMethodCallException
  293. * @return void
  294. */
  295. public function testConfigErrorOnReconfigure()
  296. {
  297. Cache::setConfig('tests', ['engine' => 'File', 'path' => TMP]);
  298. Cache::setConfig('tests', ['engine' => 'Apc']);
  299. }
  300. /**
  301. * Test reading configuration.
  302. *
  303. * @return void
  304. */
  305. public function testConfigRead()
  306. {
  307. $config = [
  308. 'engine' => 'File',
  309. 'path' => TMP,
  310. 'prefix' => 'cake_'
  311. ];
  312. Cache::setConfig('tests', $config);
  313. $expected = $config;
  314. $expected['className'] = $config['engine'];
  315. unset($expected['engine']);
  316. $this->assertEquals($expected, Cache::config('tests'));
  317. }
  318. /**
  319. * test config() with dotted name
  320. *
  321. * @return void
  322. */
  323. public function testConfigDottedAlias()
  324. {
  325. Cache::setConfig('cache.dotted', [
  326. 'className' => 'File',
  327. 'path' => TMP,
  328. 'prefix' => 'cache_value_'
  329. ]);
  330. $engine = Cache::engine('cache.dotted');
  331. $this->assertContains('cache.dotted', Cache::configured());
  332. $this->assertNotContains('dotted', Cache::configured());
  333. $this->assertInstanceOf('Cake\Cache\Engine\FileEngine', $engine);
  334. Cache::drop('cache.dotted');
  335. }
  336. /**
  337. * testGroupConfigs method
  338. */
  339. public function testGroupConfigs()
  340. {
  341. Cache::drop('test');
  342. Cache::config('latest', [
  343. 'duration' => 300,
  344. 'engine' => 'File',
  345. 'groups' => ['posts', 'comments'],
  346. ]);
  347. $expected = [
  348. 'posts' => ['latest'],
  349. 'comments' => ['latest'],
  350. ];
  351. $result = Cache::groupConfigs();
  352. $this->assertEquals($expected, $result);
  353. $result = Cache::groupConfigs('posts');
  354. $this->assertEquals(['posts' => ['latest']], $result);
  355. Cache::config('page', [
  356. 'duration' => 86400,
  357. 'engine' => 'File',
  358. 'groups' => ['posts', 'archive'],
  359. ]);
  360. $result = Cache::groupConfigs();
  361. $expected = [
  362. 'posts' => ['latest', 'page'],
  363. 'comments' => ['latest'],
  364. 'archive' => ['page']
  365. ];
  366. $this->assertEquals($expected, $result);
  367. $result = Cache::groupConfigs('archive');
  368. $this->assertEquals(['archive' => ['page']], $result);
  369. Cache::setConfig('archive', [
  370. 'duration' => 86400 * 30,
  371. 'engine' => 'File',
  372. 'groups' => ['posts', 'archive', 'comments'],
  373. ]);
  374. $result = Cache::groupConfigs('archive');
  375. $this->assertEquals(['archive' => ['archive', 'page']], $result);
  376. }
  377. /**
  378. * testGroupConfigsWithCacheInstance method
  379. */
  380. public function testGroupConfigsWithCacheInstance()
  381. {
  382. Cache::drop('test');
  383. $cache = new FileEngine();
  384. $cache->init([
  385. 'duration' => 300,
  386. 'engine' => 'File',
  387. 'groups' => ['users', 'comments'],
  388. ]);
  389. Cache::setConfig('cached', $cache);
  390. $result = Cache::groupConfigs('users');
  391. $this->assertEquals(['users' => ['cached']], $result);
  392. }
  393. /**
  394. * testGroupConfigsThrowsException method
  395. * @expectedException \InvalidArgumentException
  396. */
  397. public function testGroupConfigsThrowsException()
  398. {
  399. Cache::groupConfigs('bogus');
  400. }
  401. /**
  402. * test that configured returns an array of the currently configured cache
  403. * config
  404. *
  405. * @return void
  406. */
  407. public function testConfigured()
  408. {
  409. Cache::drop('default');
  410. $result = Cache::configured();
  411. $this->assertContains('_cake_core_', $result);
  412. $this->assertNotContains('default', $result, 'Unconnected engines should not display.');
  413. }
  414. /**
  415. * test that drop removes cache configs, and that further attempts to use that config
  416. * do not work.
  417. *
  418. * @return void
  419. */
  420. public function testDrop()
  421. {
  422. Configure::write('App.namespace', 'TestApp');
  423. $result = Cache::drop('some_config_that_does_not_exist');
  424. $this->assertFalse($result, 'Drop should not succeed when config is missing.');
  425. Cache::setConfig('unconfigTest', [
  426. 'engine' => 'TestAppCache'
  427. ]);
  428. $this->assertInstanceOf(
  429. 'TestApp\Cache\Engine\TestAppCacheEngine',
  430. Cache::engine('unconfigTest')
  431. );
  432. $this->assertTrue(Cache::drop('unconfigTest'));
  433. }
  434. /**
  435. * testWriteEmptyValues method
  436. *
  437. * @return void
  438. */
  439. public function testWriteEmptyValues()
  440. {
  441. $this->_configCache();
  442. Cache::write('App.falseTest', false, 'tests');
  443. $this->assertSame(Cache::read('App.falseTest', 'tests'), false);
  444. Cache::write('App.trueTest', true, 'tests');
  445. $this->assertSame(Cache::read('App.trueTest', 'tests'), true);
  446. Cache::write('App.nullTest', null, 'tests');
  447. $this->assertSame(Cache::read('App.nullTest', 'tests'), null);
  448. Cache::write('App.zeroTest', 0, 'tests');
  449. $this->assertSame(Cache::read('App.zeroTest', 'tests'), 0);
  450. Cache::write('App.zeroTest2', '0', 'tests');
  451. $this->assertSame(Cache::read('App.zeroTest2', 'tests'), '0');
  452. }
  453. /**
  454. * testWriteEmptyValues method
  455. *
  456. * @expectedException \InvalidArgumentException
  457. * @expectedExceptionMessage An empty value is not valid as a cache key
  458. * @return void
  459. */
  460. public function testWriteEmptyKey()
  461. {
  462. $this->_configCache();
  463. Cache::write(null, 'not null', 'tests');
  464. }
  465. /**
  466. * testReadWriteMany method
  467. *
  468. * @return void
  469. */
  470. public function testReadWriteMany()
  471. {
  472. $this->_configCache();
  473. $data = [
  474. 'App.falseTest' => false,
  475. 'App.trueTest' => true,
  476. 'App.nullTest' => null,
  477. 'App.zeroTest' => 0,
  478. 'App.zeroTest2' => '0'
  479. ];
  480. Cache::writeMany($data, 'tests');
  481. $read = Cache::readMany(array_keys($data), 'tests');
  482. $this->assertSame($read['App.falseTest'], false);
  483. $this->assertSame($read['App.trueTest'], true);
  484. $this->assertSame($read['App.nullTest'], null);
  485. $this->assertSame($read['App.zeroTest'], 0);
  486. $this->assertSame($read['App.zeroTest2'], '0');
  487. }
  488. /**
  489. * testDeleteMany method
  490. *
  491. * @return void
  492. */
  493. public function testDeleteMany()
  494. {
  495. $this->_configCache();
  496. $data = [
  497. 'App.falseTest' => false,
  498. 'App.trueTest' => true,
  499. 'App.nullTest' => null,
  500. 'App.zeroTest' => 0,
  501. 'App.zeroTest2' => '0'
  502. ];
  503. Cache::writeMany(array_merge($data, ['App.keepTest' => 'keepMe']), 'tests');
  504. Cache::deleteMany(array_keys($data), 'tests');
  505. $read = Cache::readMany(array_merge(array_keys($data), ['App.keepTest']), 'tests');
  506. $this->assertSame($read['App.falseTest'], false);
  507. $this->assertSame($read['App.trueTest'], false);
  508. $this->assertSame($read['App.nullTest'], false);
  509. $this->assertSame($read['App.zeroTest'], false);
  510. $this->assertSame($read['App.zeroTest2'], false);
  511. $this->assertSame($read['App.keepTest'], 'keepMe');
  512. }
  513. /**
  514. * Test that failed writes cause errors to be triggered.
  515. *
  516. * @expectedException \PHPUnit\Framework\Error\Error
  517. * @return void
  518. */
  519. public function testWriteTriggerError()
  520. {
  521. Configure::write('App.namespace', 'TestApp');
  522. Cache::setConfig('test_trigger', [
  523. 'engine' => 'TestAppCache',
  524. 'prefix' => ''
  525. ]);
  526. Cache::write('fail', 'value', 'test_trigger');
  527. }
  528. /**
  529. * testCacheDisable method
  530. *
  531. * Check that the "Cache.disable" configuration and a change to it
  532. * (even after a cache config has been setup) is taken into account.
  533. *
  534. * @return void
  535. */
  536. public function testCacheDisable()
  537. {
  538. Cache::enable();
  539. Cache::setConfig('test_cache_disable_1', [
  540. 'engine' => 'File',
  541. 'path' => TMP . 'tests'
  542. ]);
  543. $this->assertTrue(Cache::write('key_1', 'hello', 'test_cache_disable_1'));
  544. $this->assertSame(Cache::read('key_1', 'test_cache_disable_1'), 'hello');
  545. Cache::disable();
  546. $this->assertNull(Cache::write('key_2', 'hello', 'test_cache_disable_1'));
  547. $this->assertFalse(Cache::read('key_2', 'test_cache_disable_1'));
  548. Cache::enable();
  549. $this->assertTrue(Cache::write('key_3', 'hello', 'test_cache_disable_1'));
  550. $this->assertSame('hello', Cache::read('key_3', 'test_cache_disable_1'));
  551. Cache::clear(false, 'test_cache_disable_1');
  552. Cache::disable();
  553. Cache::config('test_cache_disable_2', [
  554. 'engine' => 'File',
  555. 'path' => TMP . 'tests'
  556. ]);
  557. $this->assertNull(Cache::write('key_4', 'hello', 'test_cache_disable_2'));
  558. $this->assertFalse(Cache::read('key_4', 'test_cache_disable_2'));
  559. Cache::enable();
  560. $this->assertTrue(Cache::write('key_5', 'hello', 'test_cache_disable_2'));
  561. $this->assertSame(Cache::read('key_5', 'test_cache_disable_2'), 'hello');
  562. Cache::disable();
  563. $this->assertNull(Cache::write('key_6', 'hello', 'test_cache_disable_2'));
  564. $this->assertFalse(Cache::read('key_6', 'test_cache_disable_2'));
  565. Cache::enable();
  566. Cache::clear(false, 'test_cache_disable_2');
  567. }
  568. /**
  569. * test clearAll() method
  570. *
  571. * @return void
  572. */
  573. public function testClearAll()
  574. {
  575. Cache::config('configTest', [
  576. 'engine' => 'File',
  577. 'path' => TMP . 'tests'
  578. ]);
  579. Cache::config('anotherConfigTest', [
  580. 'engine' => 'File',
  581. 'path' => TMP . 'tests'
  582. ]);
  583. Cache::write('key_1', 'hello', 'configTest');
  584. Cache::write('key_2', 'hello again', 'anotherConfigTest');
  585. $this->assertSame(Cache::read('key_1', 'configTest'), 'hello');
  586. $this->assertSame(Cache::read('key_2', 'anotherConfigTest'), 'hello again');
  587. $result = Cache::clearAll();
  588. $this->assertTrue($result['configTest']);
  589. $this->assertTrue($result['anotherConfigTest']);
  590. $this->assertFalse(Cache::read('key_1', 'configTest'));
  591. $this->assertFalse(Cache::read('key_2', 'anotherConfigTest'));
  592. Cache::drop('configTest');
  593. Cache::drop('anotherConfigTest');
  594. }
  595. /**
  596. * Test toggling enabled state of cache.
  597. *
  598. * @return void
  599. */
  600. public function testEnableDisableEnabled()
  601. {
  602. $this->assertNull(Cache::enable());
  603. $this->assertTrue(Cache::enabled(), 'Should be on');
  604. $this->assertNull(Cache::disable());
  605. $this->assertFalse(Cache::enabled(), 'Should be off');
  606. }
  607. /**
  608. * test remember method.
  609. *
  610. * @return void
  611. */
  612. public function testRemember()
  613. {
  614. $this->_configCache();
  615. $counter = 0;
  616. $cacher = function () use ($counter) {
  617. return 'This is some data ' . $counter;
  618. };
  619. $expected = 'This is some data 0';
  620. $result = Cache::remember('test_key', $cacher, 'tests');
  621. $this->assertEquals($expected, $result);
  622. $counter = 1;
  623. $result = Cache::remember('test_key', $cacher, 'tests');
  624. $this->assertEquals($expected, $result);
  625. }
  626. /**
  627. * Test add method.
  628. *
  629. * @return void
  630. */
  631. public function testAdd()
  632. {
  633. $this->_configCache();
  634. Cache::delete('test_add_key', 'tests');
  635. $result = Cache::add('test_add_key', 'test data', 'tests');
  636. $this->assertTrue($result);
  637. $expected = 'test data';
  638. $result = Cache::read('test_add_key', 'tests');
  639. $this->assertEquals($expected, $result);
  640. $result = Cache::add('test_add_key', 'test data 2', 'tests');
  641. $this->assertFalse($result);
  642. }
  643. /**
  644. * test registry method
  645. *
  646. * @return void
  647. */
  648. public function testRegistry()
  649. {
  650. $this->assertInstanceOf(CacheRegistry::class, Cache::registry());
  651. }
  652. /**
  653. * test registry method setting
  654. *
  655. * @return void
  656. */
  657. public function testRegistrySet()
  658. {
  659. $registry = new CacheRegistry();
  660. Cache::registry($registry);
  661. $this->assertSame($registry, Cache::registry());
  662. }
  663. /**
  664. * Test getting the registry
  665. *
  666. * @return void
  667. */
  668. public function testGetRegistry()
  669. {
  670. $this->assertInstanceOf(CacheRegistry::class, Cache::getRegistry());
  671. }
  672. /**
  673. * Test setting the registry
  674. *
  675. * @return void
  676. */
  677. public function testSetAndGetRegistry()
  678. {
  679. $registry = new CacheRegistry();
  680. Cache::setRegistry($registry);
  681. $this->assertSame($registry, Cache::getRegistry());
  682. }
  683. }