CachesShellTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 3.3.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Shell;
  16. use Cake\Cache\Cache;
  17. use Cake\Shell\CachesShell;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * CachesShell tests.
  21. */
  22. class CachesShellTest extends TestCase
  23. {
  24. /**
  25. * setup method
  26. *
  27. * @return void
  28. */
  29. public function setUp()
  30. {
  31. parent::setUp();
  32. $this->io = $this->getMock('Cake\Console\ConsoleIo');
  33. $this->shell = new CachesShell($this->io);
  34. Cache::config('test', ['engine' => 'File', 'path' => TMP]);
  35. }
  36. /**
  37. * Teardown
  38. *
  39. * @return void
  40. */
  41. public function tearDown()
  42. {
  43. parent::tearDown();
  44. unset($this->io);
  45. unset($this->shell);
  46. Cache::drop('test');
  47. }
  48. /**
  49. * Test that getOptionParser() returns an instance of \Cake\Console\ConsoleOptionParser
  50. *
  51. * @return void
  52. */
  53. public function testGetOptionParser()
  54. {
  55. $this->assertInstanceOf('Cake\Console\ConsoleOptionParser', $this->shell->getOptionParser());
  56. }
  57. /**
  58. * Test that clear() throws \Cake\Console\Exception\StopException if cache prefix is invalid
  59. *
  60. * @return void
  61. */
  62. public function testClearInvalidPrefix()
  63. {
  64. $this->setExpectedException('Cake\Console\Exception\StopException');
  65. $this->shell->clear('foo');
  66. }
  67. /**
  68. * Test that clear() clears the specified cache when a valid prefix is used
  69. *
  70. * @return void
  71. */
  72. public function testClearValidPrefix()
  73. {
  74. Cache::add('key', 'value', 'test');
  75. $this->shell->clear('test');
  76. $this->assertFalse(Cache::read('key', 'test'));
  77. }
  78. /**
  79. * Test that clear() only clears the specified cache
  80. *
  81. * @return void
  82. */
  83. public function testClearIgnoresOtherCaches()
  84. {
  85. Cache::add('key', 'value', 'test');
  86. $this->shell->clear('_cake_core_');
  87. $this->assertEquals('value', Cache::read('key', 'test'));
  88. }
  89. /**
  90. * Test that clearAll() clears values from all defined caches
  91. *
  92. * @return void
  93. */
  94. public function testClearAll()
  95. {
  96. Cache::add('key', 'value1', 'test');
  97. Cache::add('key', 'value3', '_cake_core_');
  98. $this->shell->clearAll();
  99. $this->assertFalse(Cache::read('key', 'test'));
  100. $this->assertFalse(Cache::read('key', '_cake_core_'));
  101. }
  102. }