1414namespace CodeIgniter \Commands \Cache ;
1515
1616use CodeIgniter \Cache \CacheFactory ;
17+ use CodeIgniter \Config \Factories ;
1718use CodeIgniter \Test \CIUnitTestCase ;
1819use CodeIgniter \Test \StreamFilterTrait ;
20+ use Config \Cache ;
1921use Config \Services ;
2022use PHPUnit \Framework \Attributes \Group ;
2123
@@ -27,18 +29,41 @@ final class InfoCacheTest extends CIUnitTestCase
2729{
2830 use StreamFilterTrait;
2931
32+ private Cache $ config ;
33+
3034 protected function setUp (): void
3135 {
3236 parent ::setUp ();
3337
38+ $ this ->config = new Cache ();
39+ $ this ->config ->file ['storePath ' ] = rtrim ($ this ->config ->file ['storePath ' ], DIRECTORY_SEPARATOR )
40+ . DIRECTORY_SEPARATOR . 'FileHandlerCommands ' ;
41+
42+ if (! is_dir ($ this ->config ->file ['storePath ' ])) {
43+ mkdir ($ this ->config ->file ['storePath ' ], 0777 , true );
44+ }
45+
46+ Factories ::injectMock ('config ' , Cache::class, $ this ->config );
47+
3448 // Make sure we are testing with the correct handler (override injections)
35- Services ::injectMock ('cache ' , CacheFactory ::getHandler (config ('Cache ' )));
49+ $ handler = CacheFactory ::getHandler ($ this ->config );
50+ $ handler ->clean ();
51+ Services ::injectMock ('cache ' , $ handler );
3652 }
3753
3854 protected function tearDown (): void
3955 {
40- // restore default cache handler
41- config ('Cache ' )->handler = 'file ' ;
56+ $ this ->config ->handler = 'file ' ;
57+
58+ if (is_dir ($ this ->config ->file ['storePath ' ])) {
59+ CacheFactory ::getHandler ($ this ->config )->clean ();
60+ rmdir ($ this ->config ->file ['storePath ' ]);
61+ }
62+
63+ $ this ->resetFactories ();
64+ $ this ->resetServices ();
65+
66+ parent ::tearDown ();
4267 }
4368
4469 protected function getBuffer (): string
@@ -48,7 +73,7 @@ protected function getBuffer(): string
4873
4974 public function testInfoCacheErrorsOnInvalidHandler (): void
5075 {
51- config ( ' Cache ' ) ->handler = 'redis ' ;
76+ $ this -> config ->handler = 'redis ' ;
5277 cache ()->save ('foo ' , 'bar ' );
5378 command ('cache:info ' );
5479
0 commit comments