| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- declare(strict_types=1);
- /**
- * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- * @link https://cakephp.org CakePHP(tm) Project
- * @since 3.3.0
- * @license https://opensource.org/licenses/mit-license.php MIT License
- */
- namespace Cake\Test\TestCase\Command;
- use Cake\Cache\Cache;
- use Cake\Console\Shell;
- use Cake\TestSuite\ConsoleIntegrationTestCase;
- /**
- * Cache Commands tests.
- */
- class CacheCommandsTest extends ConsoleIntegrationTestCase
- {
- /**
- * setup method
- *
- * @return void
- */
- public function setUp(): void
- {
- parent::setUp();
- Cache::setConfig('test', ['engine' => 'File', 'path' => CACHE]);
- $this->setAppNamespace();
- $this->useCommandRunner();
- }
- /**
- * Teardown
- *
- * @return void
- */
- public function tearDown(): void
- {
- parent::tearDown();
- Cache::drop('test');
- }
- /**
- * Test help output
- *
- * @return void
- */
- public function testClearHelp()
- {
- $this->exec('cache clear -h');
- $this->assertExitCode(Shell::CODE_SUCCESS);
- $this->assertOutputContains('engine to clear');
- }
- /**
- * Test help output
- *
- * @return void
- */
- public function testClearAllHelp()
- {
- $this->exec('cache clear_all -h');
- $this->assertExitCode(Shell::CODE_SUCCESS);
- $this->assertOutputContains('Clear all');
- }
- /**
- * Test list output
- *
- * @return void
- */
- public function testList()
- {
- $this->exec('cache list');
- $this->assertExitCode(Shell::CODE_SUCCESS);
- $this->assertOutputContains('- test');
- $this->assertOutputContains('- _cake_core_');
- $this->assertOutputContains('- _cake_model_');
- }
- /**
- * Test help output
- *
- * @return void
- */
- public function testListHelp()
- {
- $this->exec('cache list -h');
- $this->assertExitCode(Shell::CODE_SUCCESS);
- $this->assertOutputContains('Show a list');
- }
- /**
- * Test that clear() throws \Cake\Console\Exception\StopException if cache prefix is invalid
- *
- * @return void
- */
- public function testClearInvalidPrefix()
- {
- $this->exec('cache clear foo');
- $this->assertExitCode(Shell::CODE_ERROR);
- $this->assertErrorContains('The "foo" cache configuration does not exist');
- }
- /**
- * Test that clear() clears the specified cache when a valid prefix is used
- *
- * @return void
- */
- public function testClearValidPrefix()
- {
- Cache::add('key', 'value', 'test');
- $this->exec('cache clear test');
- $this->assertExitCode(Shell::CODE_SUCCESS);
- $this->assertNull(Cache::read('key', 'test'));
- }
- /**
- * Test that clear() only clears the specified cache
- *
- * @return void
- */
- public function testClearIgnoresOtherCaches()
- {
- Cache::add('key', 'value', 'test');
- $this->exec('cache clear _cake_core_');
- $this->assertExitCode(Shell::CODE_SUCCESS);
- $this->assertSame('value', Cache::read('key', 'test'));
- }
- /**
- * Test that clearAll() clears values from all defined caches
- *
- * @return void
- */
- public function testClearAll()
- {
- Cache::add('key', 'value1', 'test');
- Cache::add('key', 'value3', '_cake_core_');
- $this->exec('cache clear_all');
- $this->assertExitCode(Shell::CODE_SUCCESS);
- $this->assertNull(Cache::read('key', 'test'));
- $this->assertNull(Cache::read('key', '_cake_core_'));
- }
- }
|