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

Fix support for PHP 7.2 #23711

Merged
merged 2 commits into from Oct 10, 2017
Merged

Conversation

Simperfit
Copy link
Contributor

@Simperfit Simperfit commented Jul 29, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets #23671
License MIT
Doc PR -

There are still the deprecation problem with phpunit since it use each().

There are 3 tests linked to session that I don't know how to fix / what to do, do you have any idea @nicolas-grekas ?

@Simperfit Simperfit changed the base branch from master to 2.7 July 29, 2017 09:16
@nicolas-grekas nicolas-grekas changed the title feature: fix symfony test for php 7.2 Fix support for PHP 7.2 Jul 29, 2017
.travis.yml Outdated
@@ -31,6 +31,8 @@ matrix:
env: deps=high
- php: 7.1
env: deps=low
- php: 7.2
env: deps=high
Copy link
Member

Choose a reason for hiding this comment

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

no need to add a new section, 7.1 should be changed to 7.2 just above instead, deps=low

@Simperfit Simperfit changed the title Fix support for PHP 7.2 Fix support for PHP 7.2 on 2.7 Jul 29, 2017
@xabbuh xabbuh added this to the 2.7 milestone Aug 1, 2017
@Simperfit
Copy link
Contributor Author

Simperfit commented Aug 1, 2017

@nicolas-grekas
I've got some ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
on the \Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\PdoSessionHandlerTest::testSessionGC

Could you give me insight on how to fix this ?

I need to look for the seg fault too.

@nicolas-grekas
Copy link
Member

Dunno sorry...

$storage->write('gc_id', 'data');
$storage->close();
$this->assertEquals(2, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn(), 'No session pruned because gc not called');
// @TODO: Really not sure about this at all....
true === headers_sent() && $storage->destroy('gc_id');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess @stof or @ogizanagi could know if there is something better then this dirty hack ?

@@ -348,7 +352,7 @@ public function setOptions(array $options)
));

foreach ($options as $key => $value) {
if (isset($validOptions[$key])) {
if (isset($validOptions[$key]) && false === headers_sent()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

imo you should test for (PHP_VERSION_ID < 70200 || false=== headers_sent()), in order to keep the original (even flawed) behavior...

But that may be dirty actually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's actually a little dirty. Then we should do that in every modified component

@Simperfit Simperfit force-pushed the feature/fix-test-for-7-2 branch 2 times, most recently from d3d321a to 49302f5 Compare August 31, 2017 12:08
$packages = array();
$flags = \PHP_VERSION_ID >= 50400 ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE : 0;

Copy link
Member

Choose a reason for hiding this comment

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

please revert this. These lines were here for readability

.travis.yml Outdated
@@ -141,7 +141,7 @@ install:
export SYMFONY_DEPRECATIONS_HELPER=weak &&
cp composer.json composer.json.orig &&
echo -e '{\n"require":{'"$(grep phpunit-bridge composer.json)"'"php":"*"},"minimum-stability":"dev"}' > composer.json &&
php .github/build-packages.php HEAD^ $COMPONENTS &&
(php .github/build-packages.php HEAD^ $COMPONENTS || true) &&
Copy link
Member

Choose a reason for hiding this comment

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

why ? If this fails, the build will be garbage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it does trigger a fatal on git and because of that trigger a fatal on php

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we have a better way for this, maybe by fixing github/build-packager.php:11

$mergeBase = trim(shell_exec(sprintf('git merge-base %s HEAD', array_shift($dirs))));

that triggers a git fatal then a seg fault than a exit 139 which lead to a build failure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm trying to have the test running and we should be discussing this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/home/travis/.travis/job_stages: line 57: 14926 Segmentation fault      (core dumped) $COMPOSER_UP
The command "if [[ ! $skip ]]; then $COMPOSER_UP; fi" failed and exited with 139 during .

ini_set('session.save_handler', 'files');
ini_set('session.save_path', sys_get_temp_dir());
//ini_set('session.save_handler', 'files');
//ini_set('session.save_path', sys_get_temp_dir());
Copy link
Member

Choose a reason for hiding this comment

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

code should not be commented. If it is not needed anymore, it should be removed

@@ -348,7 +352,7 @@ public function setOptions(array $options)
));

foreach ($options as $key => $value) {
if (isset($validOptions[$key])) {
if (isset($validOptions[$key]) && false === headers_sent()) {
Copy link
Member

Choose a reason for hiding this comment

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

this should not be checked for each option, but only once before the loop.
And it should use !header_sent()

@@ -282,18 +282,20 @@ public function testSessionGC()

$storage->open('', 'sid');
$storage->read('gc_id');
ini_set('session.gc_maxlifetime', -1); // test that you can set lifetime of a session after it has been read
// IN 7.2 this does not work
Copy link
Member

Choose a reason for hiding this comment

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

if this test does not work in PPH 7.2, this case should be extracted to a separate test and be skipped when unapplicable instead of skipping one step (and ensuring other things still work)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree

.travis.yml Outdated
# - php: 5.3
# - php: 5.4
#- php: 5.5
#- php: 5.6
Copy link
Member

Choose a reason for hiding this comment

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

Must be reverted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be reverted

.travis.yml Outdated
- php: 7.0
env: deps=high
Copy link
Member

Choose a reason for hiding this comment

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

must be reverted

.travis.yml Outdated
- php: 7.0
env: deps=high
- php: 7.1
Copy link
Member

Choose a reason for hiding this comment

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

We need to keep a PHP 7.1 job (even though it is not one doing a special handling of deps). Otherwise, Symfony would be untested on 7.1, which is not acceptable.

@@ -35,4 +35,4 @@
"dev-master": "2.7-dev"
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

must be reverted

@@ -38,7 +38,7 @@ public function testDefaultLocaleWithoutSession()
public function testLocaleFromRequestAttribute()
{
$request = Request::create('/');
session_name('foo');
// session_name('foo');
Copy link
Member

Choose a reason for hiding this comment

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

commenting is a no-go. If we don't want this code anymore, it should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know that, I think it's like you said, all of this should be skipped on 7.2

@Simperfit
Copy link
Contributor Author

Thanks @stof for the review ill do the changes

@Simperfit Simperfit force-pushed the feature/fix-test-for-7-2 branch 3 times, most recently from eaa77c6 to 5d4838b Compare September 1, 2017 07:53
@Simperfit
Copy link
Contributor Author

Ok, I couldn't add || true on the phpunit running that would be wrong. But everything is triggering a segfault.

@remicollet maybe you have an idea ?

@stof
Copy link
Member

stof commented Sep 1, 2017

@Simperfit please avoid mentioning me in your commit message when fixing the review. This sends me a notification when pushing the commit to Github. And anytime you amend or rebase the commit, this creates a new commit, and so pushing it sends me another notification.

.travis.yml Outdated
- if [[ ! $skip ]]; then $COMPOSER_UP; fi
- if [[ ! $skip ]]; then ./phpunit install; fi
- if [[ ! $skip ]]; then $COMPOSER_UP || true; fi
- if [[ ! $skip ]]; then ./phpunit install || true; fi
Copy link
Member

Choose a reason for hiding this comment

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

Adding || true is totally a no-go. If the setup of the testsuite fails, we don't want to ignore the failure and try the next step. This would just lead to an output impossible to understand due to weird failures later (trying to use the packages which were not installed properly before)

Copy link
Contributor Author

@Simperfit Simperfit Sep 7, 2017

Choose a reason for hiding this comment

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

Do you know how we could debug this segmentation fault ? I think something needs to be done globally in the script since it does not work even adding OR true

.travis.yml Outdated
- |
# phpinfo
if [[ ! $PHP = hhvm* ]]; then php -i; else hhvm --php -r 'print_r($_SERVER);print_r(ini_get_all());'; fi
if [[ ! $PHP = hhvm* ]]; then php -i || true; else hhvm --php -r 'print_r($_SERVER);print_r(ini_get_all());'; fi
Copy link
Member

Choose a reason for hiding this comment

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

does php -i really fail ? If yes, it means that the PHP shipped in Travis is totally broken, and there is no hope.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it does not fail since it shows the phpinfo(); but it seems that it triggers a segfault

@@ -25,8 +25,10 @@ class LegacyDefaultCsrfProviderTest extends TestCase

public static function setUpBeforeClass()
{
ini_set('session.save_handler', 'files');
ini_set('session.save_path', sys_get_temp_dir());
if (PHP_VERSION_ID < 70200) {
Copy link
Member

Choose a reason for hiding this comment

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

PHP_VERSION_ID should be fully-qualified instead of relying on constant fallback, to allow resolving the version check at compilation time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean ? (PHP_VERSION maybe ?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops, understood

@@ -271,6 +271,10 @@ public function testSessionDestroy()

public function testSessionGC()
{
if (PHP_VERSION_ID === 70200) {
Copy link
Member

Choose a reason for hiding this comment

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

this would make the test run again on 7.2.1. Are you sure about it ?

ini_set('session.save_handler', 'files');
ini_set('session.save_path', sys_get_temp_dir());
//ini_set('session.save_handler', 'files');
//ini_set('session.save_path', sys_get_temp_dir());
Copy link
Member

Choose a reason for hiding this comment

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

commenting code is still a no-go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will remove

@nicolas-grekas nicolas-grekas force-pushed the feature/fix-test-for-7-2 branch 3 times, most recently from 5f48ccd to 25f9519 Compare October 9, 2017 11:24
nicolas-grekas added a commit that referenced this pull request Oct 9, 2017
…ethod (nicolas-grekas)

This PR was merged into the 3.3 branch.

Discussion
----------

[Bridge\PhpUnit] Fix infinite loop when running isolated method

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

May unlock #23003 (ping @paul-m)
And required to make #23711 pass.

Commits
-------

e07c2f1 [Bridge\PhpUnit] Fix infinite loop when running isolated method
@nicolas-grekas nicolas-grekas force-pushed the feature/fix-test-for-7-2 branch 8 times, most recently from cf43c55 to 306cd02 Compare October 9, 2017 17:55
@nicolas-grekas
Copy link
Member

Tests are now green and PR is ready.

@Simperfit
Copy link
Contributor Author

thanks for the help !

@fabpot
Copy link
Member

fabpot commented Oct 10, 2017

Thank you @Simperfit.

@fabpot fabpot merged commit fdf285b into symfony:2.7 Oct 10, 2017
fabpot added a commit that referenced this pull request Oct 10, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

Fix support for PHP 7.2

| Q             | A
| ------------- | ---
| Branch?       |  2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | #23671
| License       | MIT
| Doc PR        | -

There are still the deprecation problem with phpunit since it use `each()`.

There are 3 tests linked to session that I don't know how to fix / what to do, do you have any idea @nicolas-grekas ?

Commits
-------

fdf285b Fix 7.2 compat layer
e229dd0 Fix PHP 7.2 support
This was referenced Nov 10, 2017
@@ -383,6 +394,10 @@ public function setSaveHandler($saveHandler = null)
throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null.');
}

if (headers_sent($file, $line)) {
throw new \RuntimeException(sprintf('Failed to set the session handler because headers have already been sent by "%s" at line %d.', $file, $line));
Copy link
Contributor

@sroze sroze Nov 13, 2017

Choose a reason for hiding this comment

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

@Simperfit @nicolas-grekas why do we throw in here while we return in the other cases? This definitely smells BC break 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants