-
Notifications
You must be signed in to change notification settings - Fork 23
Description
I am updating a ZF1 app from PHP 5.3 ZF 1.12.20 to PHP 7.4.
I'm using zf1s 1.13.1 on PHP 7.4.8 with PHPUnit 7.5.20 and a Zend_Test_PHPUnit_ControllerTestCase and I'm getting the error
ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
I've taken a closer look. My application is in testing ENV and is testing itself. I have a TestHelper that bootstraps my application in "testing" ENV and a ControllerTestCase class that bootstraps another instance of the application in the setUp method for testing. Bootstraping the second instance fails with the error above.
Here is my setup for the TestHelper which is included for all tests:
...
$application = new Zend_Application(
'testing',
APPLICATION_PATH . DIRECTORY_SEPARATOR.'configs'.DIRECTORY_SEPARATOR.'application.ini'
);
Zend_Session::$_unitTestEnabled = true;
$application->bootstrap();
The setUp() method in the ControllerTestCase class looks like this:
class ConfigurationTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp()
{
$this->bootstrap = new Zend_Application(
'testing',
APPLICATION_PATH . '/configs/application.ini'
);
$someSession = new Zend_Session_Namespace('someSession');
$someSession->data = ....
//more code here
parent::setUp(); // <-- this will bootstrap the test instance, error is here
}
Problem is this code in Zend_Session, starting at line 212:
// set the options the user has requested to set
foreach ($userOptions as $userOptionName => $userOptionValue) {
$userOptionName = strtolower($userOptionName);
// set the ini based values
if (array_key_exists($userOptionName, self::$_defaultOptions)) {
ini_set("session.$userOptionName", $userOptionValue); // <----- error is here
}
As the session was initiated correctly the first time and is up and running, this here is a possible solution:
Shardj/zf1-future@82a4367#diff-dbc2d7706346875f0cbfb79798dfbfdd
What do you think?