@@ -53,7 +53,7 @@ protected function tearDown(): void
5353 {
5454 parent ::tearDown ();
5555
56- if (count ( ob_list_handlers () ) > 1 ) {
56+ if (ob_get_level ( ) > 1 ) {
5757 ob_end_clean ();
5858 }
5959
@@ -761,7 +761,7 @@ public function testPageCacheWithCacheQueryString(
761761 CITestStreamFilter::addErrorFilter ();
762762
763763 // Create cache config with cacheQueryString value from the dataProvider
764- $ cacheConfig = new Cache ( );
764+ $ cacheConfig = config (Cache::class );
765765 $ cacheConfig ->cacheQueryString = $ cacheQueryStringValue ;
766766
767767 // Clear cache before starting the test
@@ -773,15 +773,16 @@ public function testPageCacheWithCacheQueryString(
773773
774774 // Generate request to each URL from the testing array
775775 foreach ($ testingUrls as $ testingUrl ) {
776+ $ this ->resetServices ();
776777 $ _SERVER ['REQUEST_URI ' ] = '/ ' . $ testingUrl ;
777- $ routes = Services::routes (true );
778- $ routes ->add ($ testingUrl , static function () {
779- // Don't cache the page in the run() function because CodeIgniter
780- // class will create default $cacheConfig and overwrite settings
781- // from the dataProvider
782- CodeIgniter::cache (0 );
778+ $ this ->codeigniter = new MockCodeIgniter (new App ());
779+
780+ $ routes = Services::routes (true );
781+ $ routePath = explode ('? ' , $ testingUrl )[0 ];
782+ $ string = 'This is a test page, to check cache configuration ' ;
783+ $ routes ->add ($ routePath , static function () use ($ string ) {
784+ CodeIgniter::cache (60 );
783785 $ response = Services::response ();
784- $ string = 'This is a test page, to check cache configuration ' ;
785786
786787 return $ response ->setBody ($ string );
787788 });
@@ -792,9 +793,15 @@ public function testPageCacheWithCacheQueryString(
792793
793794 // Cache the page output using default caching function and $cacheConfig
794795 // with value from the data provider
796+ ob_start ();
795797 $ this ->codeigniter ->run ();
796- // Cache the page using our own $cacheConfig confugration
797- $ this ->codeigniter ->cachePage ($ cacheConfig );
798+ $ output = ob_get_clean ();
799+
800+ $ this ->assertSame ($ string , $ output );
801+
802+ if (ob_get_level () > 1 ) {
803+ ob_end_clean ();
804+ }
798805 }
799806
800807 // Calculate how much cached items exist in the cache after the test requests
0 commit comments