|
| 1 | +<?php namespace CodeIgniter\Commands; |
| 2 | + |
| 3 | +use CodeIgniter\CLI\CLI; |
| 4 | +use CodeIgniter\CLI\CommandRunner; |
| 5 | +use CodeIgniter\Config\Config; |
| 6 | +use CodeIgniter\HTTP\UserAgent; |
| 7 | +use CodeIgniter\Test\CIUnitTestCase; |
| 8 | +use CodeIgniter\Test\Filters\CITestStreamFilter; |
| 9 | +use CodeIgniter\Test\Mock\MockAppConfig; |
| 10 | +use Config\Services; |
| 11 | + |
| 12 | +class ClearCacheTest extends CIUnitTestCase |
| 13 | +{ |
| 14 | + protected $streamFilter; |
| 15 | + protected $result; |
| 16 | + |
| 17 | + protected function setUp(): void |
| 18 | + { |
| 19 | + parent::setUp(); |
| 20 | + |
| 21 | + CITestStreamFilter::$buffer = ''; |
| 22 | + $this->streamFilter = stream_filter_append(STDOUT, 'CITestStreamFilter'); |
| 23 | + $this->streamFilter = stream_filter_append(STDERR, 'CITestStreamFilter'); |
| 24 | + } |
| 25 | + |
| 26 | + public function tearDown(): void |
| 27 | + { |
| 28 | + if (! $this->result) |
| 29 | + { |
| 30 | + return; |
| 31 | + } |
| 32 | + |
| 33 | + stream_filter_remove($this->streamFilter); |
| 34 | + } |
| 35 | + |
| 36 | + public function testClearCacheInvalidHandler() |
| 37 | + { |
| 38 | + command('cache:clear junk'); |
| 39 | + $result = CITestStreamFilter::$buffer; |
| 40 | + |
| 41 | + $this->assertStringContainsString('junk is not a valid cache handler.', $result); |
| 42 | + } |
| 43 | + |
| 44 | + public function testClearCacheWorks() |
| 45 | + { |
| 46 | + cache()->save('foo', 'bar'); |
| 47 | + |
| 48 | + $this->assertEquals('bar', cache('foo')); |
| 49 | + |
| 50 | + command('cache:clear'); |
| 51 | + $result = CITestStreamFilter::$buffer; |
| 52 | + |
| 53 | + $this->assertNull(cache('foo')); |
| 54 | + |
| 55 | + $this->assertStringContainsString('Done', $result); |
| 56 | + } |
| 57 | +} |
0 commit comments