Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow unit testing sessions with PHP 7.2 #11

Merged
merged 1 commit into from
Aug 9, 2019

Conversation

AndreasMalecki
Copy link

This small fix will avoid errors with PHP 7.2 in unit tests caused by the following ini_set.

@Shardj
Copy link
Owner

Shardj commented Aug 8, 2019

Hi @AndreasMalecki, sorry I didn't get back to you sooner, I've been away. I can't see any issue with this really, I don't use this functionality myself though so when I run it $_defaultOptionsSet and self::$_unitTestEnabled are always false so it makes no difference to me.

However I don't want to make the change without understanding why it's needed. Could you post the error you're getting and a short explanation as to why the change is needed? From what I can tell, if you've set the session to say this runtime is a unit test then you don't want the default ini_set's to be run?

@SvenRtbg
Copy link

SvenRtbg commented Aug 9, 2019

When running inside unit tests, and if you are basically initializing the whole application, Zend will also initialize the session settings that are configured. This will inevitably call ini_set() for the session settings, and this will trigger a warning that these settings cannot be changed anymore because headers are already sent.

Zend-Session has this $_unitTestEnabled property in order to allow testing session stuff without really calling PHP session functions, so you set this property to true in the test bootstrap or setUp() and can do session related activities without starting the real session - because on command line, doing real sessions is weird. Zend-Session acts as a wrapper around the core PHP session functions, and without calling them, no $_SESSION will be populated, but you are not supposed to access that in the first place, but should go via the relevant Zend_Session_Namespace object, which will continue to work in this scenario.

So TLDR: Calling ini_set() will trigger a warning, and the supposed setup in CLI tests is to set $_unitTestEnabled to true in order to prevent using the real PHP session.

@Shardj Shardj merged commit 3f24279 into Shardj:master Aug 9, 2019
@Shardj Shardj changed the title Allow unit testing with PHP 7.2 Allow unit testing sessions with PHP 7.2 Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants