8000 Fix PHP 7.2 support · symfony/symfony@e229dd0 · GitHub
[go: up one dir, main page]

Skip to content

Commit e229dd0

Browse files
Amrouche Hamzanicolas-grekas
Amrouche Hamza
authored andcommitted
Fix PHP 7.2 support
1 parent 79c1f5e commit e229dd0

File tree

9 files changed

+69
-18
lines changed

9 files changed

+69
-18
lines changed

.github/build-packages.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
$dirs = $_SERVER['argv'];
1010
array_shift($dirs);
1111
$mergeBase = trim(shell_exec(sprintf('git merge-base %s HEAD', array_shift($dirs))));
12-
1312
$packages = array();
1413
$flags = \PHP_VERSION_ID >= 50400 ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE : 0;
1514

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ matrix:
2727
- php: 7.0
2828
env: deps=high
2929
- php: 7.1
30-
env: deps=low
30+
- php: 7.2
3131
fast_finish: true
3232

3333
cache:
@@ -137,7 +137,7 @@ install:
137137
export SYMFONY_DEPRECATIONS_HELPER=weak &&
138138
cp composer.json composer.json.orig &&
139139
echo -e '{\n"require":{'"$(grep phpunit-bridge composer.json)"'"php":"*"},"minimum-stability":"dev"}' > composer.json &&
140-
php .github/build-packages.php HEAD^ $COMPONENTS &&
140+
(php .github/build-packages.php HEAD^ $COMPONENTS) &&
141141
mv composer.json composer.json.phpunit &&
142142
mv composer.json.orig composer.json
143143
fi
@@ -176,9 +176,9 @@ install:
176176
if [[ $skip ]]; then
177177
echo -e "\\n\\e[1;34mIntermediate PHP version $PHP is skipped for pull requests.\\e[0m"
178178
elif [[ $deps = high ]]; then
179-
echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && $COMPOSER_UP && $PHPUNIT_X$LEGACY'"
179+
echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && ($COMPOSER_UP) && $PHPUNIT_X$LEGACY'"
180180
elif [[ $deps = low ]]; then
181-
echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && $COMPOSER_UP --prefer-lowest --prefer-stable && $PHPUNIT_X'"
181+
echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && ($COMPOSER_UP --prefer-lowest --prefer-stable) && $PHPUNIT_X'"
182182
elif [[ $PHP = hhvm* ]]; then
183183
$PHPUNIT --exclude-group benchmark,intl-data
184184
else

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ class LegacyDefaultCsrfProviderTest extends TestCase
2525

2626
public static function setUpBeforeClass()
2727
{
28-
ini_set('session.save_handler', 'files');
29-
ini_set('session.save_path', sys_get_temp_dir());
28+
if (\PHP_VERSION_ID < 70200) {
29+
ini_set('session.save_handler', 'files');
30+
ini_set('session.save_path', sys_get_temp_dir());
31+
}
3032
}
3133

3234
protected function setUp()

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ class NativeSessionStorage implements SessionStorageInterface
101101
*/
102102
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
103103
{
104-
session_cache_limiter(''); // disable by default because it's managed by HeaderBag (if used)
105-
ini_set('session.use_cookies', 1);
104+
if (empty($options)) {
105+
$options += array('cache_limiter' => 'public');
106+
}
107+
if (1 !== (int) ini_get('session.use_cookies')) {
108+
ini_set('session.use_cookies', 1);
109+
}
106110

107111
if (\PHP_VERSION_ID >= 50400) {
108112
session_register_shutdown();
@@ -345,9 +349,11 @@ public function setOptions(array $options)
345349
'sid_length', 'sid_bits_per_character', 'trans_sid_hosts', 'trans_sid_tags',
346350
));
347351

348-
foreach ($options as $key => $value) {
349-
if (isset($validOptions[$key])) {
350-
ini_set('session.'.$key, $value);
352+
if (PHP_VERSION_ID < 70200 || !headers_sent()) {
353+
foreach ($options as $key => $value) {
354+
if (isset($validOptions[$key])) {
355+
ini_set('session.'.$key, $value);
356+
}
351357
}
352358
}
353359
}
@@ -392,7 +398,7 @@ public function setSaveHandler($saveHandler = null)
392398
}
393399
$this->saveHandler = $saveHandler;
394400

395-
if ($this->saveHandler instanceof \SessionHandlerInterface) {
401+
if ($this->saveHandler instanceof \SessionHandlerInterface && false === headers_sent()) {
396402
if (\PHP_VERSION_ID >= 50400) {
397403
session_set_save_handler($this->saveHandler, false);
398404
} else {

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ public function testSessionDestroy()
271271

272272
public function testSessionGC()
273273
{
274+
if (\PHP_VERSION_ID >= 70200) {
275+
$this->markTestSkipped('PHP version is 7.2');
276+
}
277+
274278
$previousLifeTime = ini_set('session.gc_maxlifetime', 1000);
275279
$pdo = $this->getMemorySqlitePdo();
276280
$storage = new PdoSessionHandler($pdo);
@@ -282,18 +286,52 @@ public function testSessionGC()
282286

283287
$storage->open('', 'sid');
284288
$storage->read('gc_id');
289+
// IN 7.2 this does not work
285290
ini_set('session.gc_maxlifetime', -1); // test that you can set lifetime of a session after it has been read
286291
$storage->write('gc_id', 'data');
287292
$storage->close();
288293
$this->assertEquals(2, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn(), 'No session pruned because gc not called');
294+
$storage->destroy('gc_id');
289295

290296
$storage->open('', 'sid');
291297
$data = $storage->read('gc_id');
292298
$storage->gc(-1);
293299
$storage->close();
294300

295301
ini_set('session.gc_maxlifetime', $previousLifeTime);
302+
$this->assertSame('', $data, 'Session already considered garbage, so not returning data even if it is not pruned yet');
303+
$this->assertEquals(1, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn(), 'Expired session is pruned');
304+
}
305+
306+
public function testSessionGC72()
307+
{
308+
if (\PHP_VERSION_ID <= 70200) {
309+
$this->markTestSkipped('PHP version is not 7.2');
310+
}
311+
312+
$previousLifeTime = false === headers_sent() && ini_set('session.gc_maxlifetime', 1000);
313+
$pdo = $this->getMemorySqlitePdo();
314+
$storage = new PdoSessionHandler($pdo);
315+
316+
$storage->open('', 'sid');
317+
$storage->read('id');
318+
$storage->write('id', 'data');
319+
$storage->close();
320+
321+
$storage->open('', 'sid');
322+
$storage->read('gc_id');
323+
false === headers_sent() && ini_set('session.gc_maxlifetime', -1); // test that you can set lifetime of a session after it has been read
324+
$storage->write('gc_id', 'data');
325+
$storage->close();
326+
$this->assertEquals(2, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn(), 'No session pruned because gc not called');
327+
true === headers_sent() && $storage->destroy('gc_id');
328+
329+
$storage->open('', 'sid');
330+
$data = $storage->read('gc_id');
331+
$storage->gc(-1);
332+
$storage->close();
296333

334+
false === headers_sent() && ini_set('session.gc_maxlifetime', $previousLifeTime);
297335
$this->assertSame('', $data, 'Session already considered garbage, so not returning data even if it is not pruned yet');
298336
$this->assertEquals(1, $pdo->query('SELECT COUNT(*) FROM sessions')->fetchColumn(), 'Expired session is pruned');
299337
}

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function testDefaultSessionCacheLimiter()
152152
{
153153
$this->iniSet('session.cache_limiter', 'nocache');
154154

155-
$storage = new NativeSessionStorage();
155+
$storage = new NativeSessionStorage(array('cache_limiter' => ''));
156156
$this->assertEquals('', ini_get('session.cache_limiter'));
157157
}
158158

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ public function testDefaultLocaleWithoutSession()
3838
public function testLocaleFromRequestAttribute()
3939
{
4040
$request = Request::create('/');
41-
session_name('foo');
41+
42+
if (PHP_VERSION_ID < 70200 || !headers_sent()) {
43+
session_name('foo');
44+
}
45+
4246
$request->cookies->set('foo', 'value');
4347

4448
$request->attributes->set('_locale', 'es');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testDoesNotDeleteCookieIfUsingSessionLifetime()
6363
$this->sessionHasBeenStarted();
6464

6565
$params = session_get_cookie_params();
66-
session_set_cookie_params(0, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
66+
// session_set_cookie_params(0, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
6767

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

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ class NativeSessionTokenStorageTest extends TestCase
3131

3232
public static function setUpBeforeClass()
3333
{
34-
ini_set('session.save_handler', 'files');
35-
ini_set('session.save_path', sys_get_temp_dir());
34+
if (\PHP_VERSION_ID < 70200) {
35+
ini_set('session.save_handler', 'files');
36+
ini_set('session.save_path', sys_get_temp_dir());
37+
}
3638

3739
parent::setUpBeforeClass();
3840
}

0 commit comments

Comments
 (0)
0