8000 bug #23711 Fix support for PHP 7.2 (Simperfit, nicolas-grekas) · symfony/symfony@5fd0fe6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5fd0fe6

Browse files
committed
bug #23711 Fix support for PHP 7.2 (Simperfit, nicolas-grekas)
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
2 parents 1b1f39a + fdf285b commit 5fd0fe6

File tree

17 files changed

+46
-26
lines changed

17 files changed

+46
-26
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion< 8000 /span>
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ matrix:
2525
- php: 5.5
2626
- php: 5.6
2727
- php: 7.0
28-
env: deps=high
2928
- php: 7.1
29+
env: deps=high
30+
- php: 7.2
3031
env: deps=low
3132
fast_finish: true
3233

src/Symfony/Bridge/Twig/Tests/AppVariableTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public function testEnvironment()
4444
$this->assertEquals('dev', $this->appVariable->getEnvironment());
4545
}
4646

47+
/**
48+
* @runInSeparateProcess
49+
*/
4750
public function testGetSession()
4851
{
4952
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"symfony/asset": "~2.7",
2424
"symfony/finder": "~2.3",
2525
"symfony/form": "~2.7.30|^2.8.23",
26+
"symfony/http-foundation": "~2.7.36|^2.8.29",
2627
"symfony/http-kernel": "~2.3",
2728
"symfony/intl": "~2.3",
2829
"symfony/routing": "~2.2",

src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function testCacheIsFreshAfterCacheClearedWithWarmup()
5555
$finder = new Finder();
5656
$metaFiles = $finder->files()->in($this->kernel->getCacheDir())->name('*.php.meta');
5757
// simply check that cache is warmed up
58-
$this->assertGreaterThanOrEqual(1, count($metaFiles));
58+
$this->assertNotEmpty($metaFiles);
5959
foreach ($metaFiles as $file) {
6060
$configCache = new ConfigCache(substr($file, 0, -5), true);
6161
$this->assertTrue(

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ public function testRedirectToRoute()
143143
$this->assertSame(302, $response->getStatusCode());
144144
}
145145

146+
/**
147+
* @runInSeparateProcess
148+
*/
146149
public function testAddFlash()
147150
{
148151
$flashBag = new FlashBag();

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"symfony/config": "~2.4",
2424
"symfony/event-dispatcher": "~2.5",
2525
"symfony/finder": "^2.0.5",
26-
"symfony/http-foundation": "~2.7",
26+
"symfony/http-foundation": "~2.7.36|^2.8.29",
2727
"symfony/http-kernel": "~2.7.29|^2.8.22",
2828
"symfony/filesystem": "~2.3",
2929
"symfony/routing": "~2.7.24|^2.8.17",

src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public function testNotice()
7979
$this->assertEquals(E_NOTICE, $exception->getSeverity());
8080
$this->assertEquals(__FILE__, $exception->getFile());
8181
$this->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
82-
$this->assertArrayHasKey('foobar', $exception->getContext());
82+
if (\PHP_VERSION_ID < 70200) {
83+
$this->assertArrayHasKey('foobar', $exception->getContext());
84+
}
8385

8486
$trace = $exception->getTrace();
8587
$this->assertEquals(__FILE__, $trace[0]['file']);
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<?php
22

3-
throw new \Exception('boo');
3+
if (!function_exists('__phpunit_run_isolated_test')) {
4+
throw new \Exception('boo');
5+
}

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ public function testExtensionInPhar()
421421
if (extension_loaded('suhosin') && false === strpos(ini_get('suhosin.executor.include.whitelist'), 'phar')) {
422422
$this->markTestSkipped('To run this test, add "phar" to the "suhosin.executor.include.whitelist" settings in your php.ini file.');
423423
}
424+
if (defined('HHVM_VERSION')) {
425+
$this->markTestSkipped('HHVM makes this test conflict with those run in separate processes.');
426+
}
424427

425428
require_once self::$fixturesPath.'/includes/ProjectWithXsdExtensionInPhar.phar';
426429

src/Symfony/Component/Form/Tests/Extension/Csrf/CsrfProvider/LegacyDefaultCsrfProviderTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ class LegacyDefaultCsrfProviderTest extends TestCase
2323
{
2424
protected $provider;
2525

26-
public static function setUpBeforeClass()
27-
{
28-
ini_set('session.save_handler', 'files');
29-
ini_set('session.save_path', sys_get_temp_dir());
30-
}
31-
3226
protected function setUp()
3327
{
3428
$this->provider = new DefaultCsrfProvider('SECRET');

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ class NativeSessionStorage implements SessionStorageInterface
102102
*/
103103
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
104104
{
105-
session_cache_limiter(''); // disable by default because it's managed by HeaderBag (if used)
106-
ini_set('session.use_cookies', 1);
105+
$options += array(
106+
// disable by default because it's managed by HeaderBag (if used)
107+
'cache_limiter' => '',
108+
'use_cookies' => 1,
109+
);
107110

108111
if (\PHP_VERSION_ID >= 50400) {
109112
session_register_shutdown();
@@ -209,6 +212,10 @@ public function regenerate($destroy = false, $lifetime = null)
209212
return false;
210213
}
211214

215+
if (headers_sent()) {
216+
return false;
217+
}
218+
212219
if (null !== $lifetime) {
213220
ini_set('session.cookie_lifetime', $lifetime);
214221
}
@@ -333,6 +340,10 @@ public function isStarted()
333340
*/
334341
public function setOptions(array $options)
335342
{
343+
if (headers_sent()) {
344+
return;
345+
}
346+
336347
$validOptions = array_flip(array(
337348
'cache_limiter', 'cookie_domain', 'cookie_httponly',
338349
'cookie_lifetime', 'cookie_path', 'cookie_secure',
@@ -384,6 +395,10 @@ public function setSaveHandler($saveHandler = null)
384395
throw new \InvalidArgumentException('Must be instance of AbstractProxy or NativeSessionHandler; implement \SessionHandlerInterface; or be null.');
385396
}
386397

398+
if (headers_sent($file, $line)) {
399+
throw new \RuntimeException(sprintf('Failed to set the session handler because headers have already been sent by "%s" at line %d.', $file, $line));
400+
}
401+
387402
// Wrap $saveHandler in proxy and prevent double wrapping of proxy
388403
if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
389404
$saveHandler = new SessionHandlerProxy($saveHandler);

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ public function testSessionDestroy()
269269
$this->assertSame('', $data, 'Destroyed session returns empty string');
270270
}
271271

272+
/**
273+
* @runInSeparateProcess
274+
*/
272275
public function testSessionGC()
273276
{
274277
$previousLifeTime = ini_set('session.gc_maxlifetime', 1000);

src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public function testDefaultLocaleWithoutSession()
3838
public function testLocaleFromRequestAttribute()
3939
{
4040
$request = Request::create('/');
41-
session_name('foo');
42-
$request->cookies->set('foo', 'value');
41+
$request->cookies->set(session_name(), 'value');
4342

4443
$request->attributes->set('_locale', 'es');
4544
$listener = new LocaleListener('fr', null, $this->requestStack);

src/Symfony/Component/HttpKernel/Tests/EventListener/TestSessionListenerTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ public function testDoesNotDeleteCookieIfUsingSessionLifetime()
6262
{
6363
$this->sessionHasBeenStarted();
6464

65-
$params = session_get_cookie_params();
66-
session_set_cookie_params(0, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
65+
@ini_set('session.cookie_lifetime', 0);
6766

6867
$response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST);
6968
$cookies = $response->headers->getCookies();

src/Symfony/Component/HttpKernel/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18 10000 ,7 @@
1818
"require": {
1919
"php": ">=5.3.9",
2020
"symfony/event-dispatcher": "^2.6.7",
21-
"symfony/http-foundation": "~2.7.20|^2.8.13",
21+
"symfony/http-foundation": "~2.7.36|^2.8.29",
2222
"symfony/debug": "^2.6.2",
2323
"psr/log": "~1.0"
2424
},

src/Symfony/Component/Routing/Tests/Fixtures/validresource.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
if (function_exists('__phpunit_run_isolated_test')) {
4+
return;
5+
}
36
/** @var $loader \Symfony\Component\Routing\Loader\PhpFileLoader */
47
/** @var \Symfony\Component\Routing\RouteCollection $collection */
58
$collection = $loader->import('validpattern.php');

src/Symfony/Component/Security/Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ class NativeSessionTokenStorageTest extends TestCase
2929
*/
3030
private $storage;
3131

32-
public static function setUpBeforeClass()
33-
{
34-
ini_set('session.save_handler', 'files');
35-
ini_set('session.save_path', sys_get_temp_dir());
36-
37-
parent::setUpBeforeClass();
38-
}
39-
4032
protected function setUp()
4133
{
4234
$_SESSION = array();

0 commit comments

Comments
 (0)
0