Welcome Guest, Not a member yet? Register   Sign In
Enabling "resetServices" causes "Session ini settings cannot be changed..." error
#1

(This post was last modified: 06-09-2022, 08:43 AM by umizoomi.)

I need to clear sessions between post calls in my test suite and it appears that the best way to do that is to enable resetServices in the $setUpMethods array:
https://github.com/codeigniter4/CodeIgni...-835353623
However, when I do that, I receive the following error:

Code:
ErrorException: ini_set(): Session ini settings cannot be changed after headers have already been sent

C:\sites\www\vendor\codeigniter4\framework\system\Session\Session.php:290
C:\sites\www\vendor\codeigniter4\framework\system\Session\Session.php:228
C:\sites\www\vendor\codeigniter4\framework\system\Config\Services.php:577
C:\sites\www\vendor\codeigniter4\framework\system\Config\BaseService.php:248
C:\sites\www\vendor\codeigniter4\framework\system\Config\BaseService.php:189
C:\sites\www\vendor\codeigniter4\framework\system\Config\Services.php:563
C:\sites\www\vendor\codeigniter4\framework\system\Config\BaseService.php:248
C:\sites\www\vendor\codeigniter4\framework\system\Common.php:929
C:\sites\www\app\Controllers\BaseController.php:77
C:\sites\www\vendor\codeigniter4\framework\system\CodeIgniter.php:810
C:\sites\www\vendor\codeigniter4\framework\system\CodeIgniter.php:410
C:\sites\www\vendor\codeigniter4\framework\system\CodeIgniter.php:326
C:\sites\www\vendor\codeigniter4\framework\system\Test\FeatureTestTrait.php:188
C:\sites\www\vendor\codeigniter4\framework\system\Test\FeatureTestTrait.php:235
C:\sites\www\tests\app\Controllers\ContactPostTest.php:76
C:\sites\www\tests\app\Controllers\ContactPostTest.php:48

Is there a way to set the resetServices to true before the headers have been set?

For reference, I have tried enabling resetServices in the setUpMethods:

PHP Code:
protected $setUpMethods = ["resetServices"]; 

Enabling it in the setUp function:

PHP Code:
protected function setUp(): void
{
    parent::setUp();

    $this->resetServices();


And enabling it directly in one of my functions just before the $this->post call:

PHP Code:
$this->resetServices(); 

And it results in the same error. I have also tried to only reset the single MockSession service in my function:

PHP Code:
Services::resetSingle("mockSession"); 

But that doesn't do anything.

This was done with CI4.1.9 and since CI4.2 enables resetServices by default, I tried upgrading to that, which corrects the issue; however, I am still running into the same error that I was trying to fix with resetServices. You can see more info on that here:

https://stackoverflow.com/q/72539728/1698908
Reply


Messages In This Thread
Enabling "resetServices" causes "Session ini settings cannot be changed..." error - by umizoomi - 06-09-2022, 08:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB