Skip to content

Commit b086124

Browse files
minor #61485 [HttpFoundation] use PHPUnit's native expectUserDeprecationMessage() method (xabbuh)
This PR was merged into the 7.4 branch. Discussion ---------- [HttpFoundation] use PHPUnit's native expectUserDeprecationMessage() method | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT In #58370 I rewrote the tests in `NativeSessionStorageTest` to work around a bug in PHPUnit that didn't allow to have assertions about deprecations triggered in tests that were run in separate processes. Thanks to sebastianbergmann/phpunit#6283 (available in e.g. PHPUnit 12.3.5+) we don't need this workaround anymore. Commits ------- c7b14f8 use PHPUnit's native expectUserDeprecationMessage() method
2 parents d2ccf32 + c7b14f8 commit b086124

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

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

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,10 @@ public function testCacheExpireOption()
227227
#[Group('legacy')]
228228
public function testTransSidTagsOption()
229229
{
230-
$unignoredErrors = [];
230+
$this->expectUserDeprecationMessage('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "trans_sid_tags" option is deprecated and will be ignored in Symfony 8.0.');
231231

232-
$previousErrorHandler = set_error_handler(function ($errno, $errstr) use (&$previousErrorHandler, &$unignoredErrors) {
232+
$previousErrorHandler = set_error_handler(function ($errno, $errstr) use (&$previousErrorHandler) {
233233
if ('ini_set(): Usage of session.trans_sid_tags INI setting is deprecated' !== $errstr) {
234-
$unignoredErrors[] = $errstr;
235-
236234
return $previousErrorHandler ? $previousErrorHandler(...\func_get_args()) : false;
237235
}
238236
});
@@ -245,8 +243,6 @@ public function testTransSidTagsOption()
245243
restore_error_handler();
246244
}
247245

248-
$this->assertCount(1, $unignoredErrors);
249-
$this->assertSame('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "trans_sid_tags" option is deprecated and will be ignored in Symfony 8.0.', $unignoredErrors[0]);
250246
$this->assertSame('a=href', \ini_get('session.trans_sid_tags'));
251247
}
252248

@@ -376,15 +372,13 @@ public function testSaveHandlesNullSessionGracefully()
376372
#[Group('legacy')]
377373
public function testPassingDeprecatedOptions()
378374
{
379-
$unignoredErrors = [];
380-
381-
$previousErrorHandler = set_error_handler(function ($errno, $errstr) use (&$previousErrorHandler, &$unignoredErrors) {
382-
if (!preg_match('/^ini_set\(\):( Disabling| Usage of)? session\..+ is deprecated$/', $errstr)) {
383-
$unignoredErrors[] = $errstr;
384-
385-
return $previousErrorHandler ? $previousErrorHandler(...\func_get_args()) : false;
386-
}
387-
});
375+
$this->expectUserDeprecationMessage('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "sid_length" option is deprecated and will be ignored in Symfony 8.0.');
376+
$this->expectUserDeprecationMessage('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "sid_bits_per_character" option is deprecated and will be ignored in Symfony 8.0.');
377+
$this->expectUserDeprecationMessage('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "referer_check" option is deprecated and will be ignored in Symfony 8.0.');
378+
$this->expectUserDeprecationMessage('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "use_only_cookies" option is deprecated and will be ignored in Symfony 8.0.');
379+
$this->expectUserDeprecationMessage('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "use_trans_sid" option is deprecated and will be ignored in Symfony 8.0.');
380+
$this->expectUserDeprecationMessage('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "trans_sid_hosts" option is deprecated and will be ignored in Symfony 8.0.');
381+
$this->expectUserDeprecationMessage('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "trans_sid_tags" option is deprecated and will be ignored in Symfony 8.0.');
388382

389383
$this->getStorage([
390384
'sid_length' => 42,
@@ -395,14 +389,5 @@ public function testPassingDeprecatedOptions()
395389
'trans_sid_hosts' => 'foo',
396390
'trans_sid_tags' => 'foo',
397391
]);
398-
399-
$this->assertCount(7, $unignoredErrors);
400-
$this->assertContains('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "sid_length" option is deprecated and will be ignored in Symfony 8.0.', $unignoredErrors);
401-
$this->assertContains('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "sid_bits_per_character" option is deprecated and will be ignored in Symfony 8.0.', $unignoredErrors);
402-
$this->assertContains('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "referer_check" option is deprecated and will be ignored in Symfony 8.0.', $unignoredErrors);
403-
$this->assertContains('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "use_only_cookies" option is deprecated and will be ignored in Symfony 8.0.', $unignoredErrors);
404-
$this->assertContains('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "use_trans_sid" option is deprecated and will be ignored in Symfony 8.0.', $unignoredErrors);
405-
$this->assertContains('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "trans_sid_hosts" option is deprecated and will be ignored in Symfony 8.0.', $unignoredErrors);
406-
$this->assertContains('Since symfony/http-foundation 7.2: NativeSessionStorage\'s "trans_sid_tags" option is deprecated and will be ignored in Symfony 8.0.', $unignoredErrors);
407392
}
408393
}

0 commit comments

Comments
 (0)