Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

apply php 7.2 to travis #92

Closed
wants to merge 6 commits into from
Closed

Conversation

samsonasik
Copy link
Contributor

No description provided.

@samsonasik
Copy link
Contributor Author

Got following errrors under php 7.2:

There were 6 errors:

1) ZendTest\Session\Config\SessionConfigTest::testSavePathCanBeNonDirectoryWhenSaveHandlerNotFiles

Zend\Session\Exception\InvalidArgumentException: Invalid save handler specified: ini_set(): Cannot set 'user' save handler by ini_set() or session_module_name()

/home/travis/build/zendframework/zend-session/src/Config/SessionConfig.php:148

/home/travis/build/zendframework/zend-session/test/Config/SessionConfigTest.php:68

2) ZendTest\Session\Config\SessionConfigTest::testSaveHandlerIsMutable

ini_set(): Cannot set 'user' save handler by ini_set() or session_module_name()

/home/travis/build/zendframework/zend-session/src/Config/SessionConfig.php:97

/home/travis/build/zendframework/zend-session/src/Config/StandardConfig.php:147

/home/travis/build/zendframework/zend-session/src/Config/StandardConfig.php:912

/home/travis/build/zendframework/zend-session/test/Config/SessionConfigTest.php:105

3) ZendTest\Session\Config\SessionConfigTest::testSaveHandlerAltersIniSetting

ini_set(): Cannot set 'user' save handler by ini_set() or session_module_name()

/home/travis/build/zendframework/zend-session/src/Config/SessionConfig.php:97

/home/travis/build/zendframework/zend-session/src/Config/StandardConfig.php:147

/home/travis/build/zendframework/zend-session/src/Config/StandardConfig.php:912

/home/travis/build/zendframework/zend-session/test/Config/SessionConfigTest.php:111

4) ZendTest\Session\Config\SessionConfigTest::testSetOptionSetsIniSetting with data set #2 ('save_handler', 'getOption', 'user')

ini_set(): Cannot set 'user' save handler by ini_set() or session_module_name()

/home/travis/build/zendframework/zend-session/src/Config/SessionConfig.php:97

/home/travis/build/zendframework/zend-session/test/Config/SessionConfigTest.php:972

5) ZendTest\Session\Config\SessionConfigTest::testSetOptionsTranslatesUnderscoreSeparatedKeys with data set #2 ('save_handler', 'getOption', 'user')

ini_set(): Cannot set 'user' save handler by ini_set() or session_module_name()

/home/travis/build/zendframework/zend-session/src/Config/SessionConfig.php:97

/home/travis/build/zendframework/zend-session/src/Config/StandardConfig.php:147

/home/travis/build/zendframework/zend-session/src/Config/StandardConfig.php:116

/home/travis/build/zendframework/zend-session/test/Config/SessionConfigTest.php:1005

6) ZendTest\Session\SaveHandler\MongoDBTest::testReadDestroysExpiredSession

ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

/home/travis/build/zendframework/zend-session/test/SaveHandler/MongoDBTest.php:97

.travis.yml Outdated
env:
- DEPS=latest
allow_failures:
- php: nightly
- php: 7.2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I am right, but somewhere, someone secretly decided to not allow failures on PHP 7.2 any more ;-)
@froschdesign Is it right? 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samsonasik and @webimpress
November 30, 2017 is around the corner therefore it make no sense! 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webimpress @froschdesign I've removed allow_failures->php 7.2, do you think we need to keep the "nightly"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samsonasik I wouldn't do that as long as we don't have PHP 7.3-alpha yet.

@samsonasik
Copy link
Contributor Author

So, any suggestion to get the error gone in php 7.2 ?

@michalbundyra
Copy link
Member

@samsonasik I'd suggest to try session_set_save_handler() method, because error message says:

Cannot set 'user' save handler by ini_set() or session_module_name()

@michalbundyra
Copy link
Member

@samsonasik Hm... oh, no... sorry. No idea for now. This is not gonna work.

@remicollet
Copy link

@weierophinney
Copy link
Member

This is a case where the tests are incorrect; the value "user" was never correct, but previous versions of PHP did not raise an error.

I'll update to provide a mock SessionHandlerInterface implementation.

This patch takes the following approach:

- If "files" is provided in _any_ PHP version, it continues to use
  `ini_set`.
- If "user" is provided in PHP versions prior to 7.2, it continues to
  use `ini_set`.
- Otherwise, it checks to see if the handler provided is a class or
  instance that implements PHP's `SessionHandlerInterface`; if so, it
  uses `session_set_save_handler()` with that instance (instantiating it
  if it is a class name).
- It no longer uses `ini_get()` to retrieve the save handler
  configuration _unless_ it has not been memoized in the instance.

This approach works cross-platform.
*/
public function setSaveHandler($phpSaveHandler)
{
// error_log(sprintf('In %s with %s', __METHOD__, var_export($phpSaveHandler, true)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this comment above?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove; thanks!

// ArrayUtils::merge parameter
if ($oldSessionData instanceof Storage\StorageInterface) {
$oldSessionData = $oldSessionData->toArray();
} elseif ($oldSessionData instanceof \Traversable) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traversable is imported

if ($oldSessionData instanceof Storage\StorageInterface) {
$oldSessionData = $oldSessionData->toArray();
} elseif ($oldSessionData instanceof \Traversable) {
$oldSessionData = iterator_to_array($oldSessionData);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it is sufficient - because it is not recursive.

if ($oldSessionData instanceof \Traversable
|| (! empty($oldSessionData) && is_array($oldSessionData))
) {
if ($oldSessionData instanceof Traversable) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted by @Xerkus in separate PR this is no longer needed

$oldSessionData = $oldSessionData->toArray();
}

if (! empty($oldSessionData) && is_array($oldSessionData)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

! empty is useless

- PHP 7+ environments have it by default, but it's out-of-date
- PHP 5 environments have ext/mongo but not ext/mongodb, so we need to
  install it.

`pecl upgrade` will install if it's not present, and upgrade otherwise.
Once installed, we need to enable it if it is not already.
Test case fails on PHP 7.2 due to headers being sent; run in separate
process.
@weierophinney
Copy link
Member

Single test failure is on 5.6-locked, where the MongoDb SaveHandler implementation's garbage collection test reliably fails; passes on all other environments, however, so I'm going to take it as a pass.

weierophinney added a commit that referenced this pull request Nov 28, 2017
weierophinney added a commit that referenced this pull request Nov 28, 2017
@weierophinney
Copy link
Member

Thanks, @samsonasik, for getting this started!

weierophinney added a commit to weierophinney/zend-session that referenced this pull request Nov 29, 2017
Per zendframework#97, the fix in 2.8.1 (provided by zendframework#92) for having
`SessionConfig::setPhpSaveHandler()` work with PHP 7.2 was too
aggressive, and prevented the ability to set the value to a known
extension, such as redis.

This patch fixes that approach by grabbing a list of known save handlers
from `phpinfo()` (after first stripping `user` from the list), and
comparing the incoming value to that list; if it is in that list, it now
uses `session_module_name()` to set the value.

Tests for this are next to impossible to write, unfortunately, as we
would need to have multiple extensions installed on developer machines
and in Travis. I have instead added tests verifying the various
exceptions thrown, including one thrown when a value is in the known
PHP save handlers list, but fails to be set properly.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants