Skip to content

Commit 850f218

Browse files
committed
minor symfony#18296 [3.1] fix testing deprecation messages (xabbuh)
This PR was merged into the 3.1-dev branch. Discussion ---------- [3.1] fix testing deprecation messages | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | * always restore the previous error handler * throw `LogicExcetion` when unexpected error type is triggered Commits ------- 0df544f fix testing deprecation messages
2 parents 2946932 + 0df544f commit 850f218

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ public function testAbsolutePathsAreDeprecated($name, $logicalName, $path, $ref)
9191
$deprecations = array();
9292
set_error_handler(function ($type, $msg) use (&$deprecations) {
9393
if (E_USER_DEPRECATED !== $type) {
94-
throw new \LogicException(sprintf('Unexpected error: "%s".', $msg));
94+
restore_error_handler();
95+
96+
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
9597
}
9698

9799
$deprecations[] = $msg;

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,20 +519,24 @@ public function testAliasDefinitionContainsUnsupportedElements()
519519

520520
$deprecations = array();
521521
set_error_handler(function ($type, $msg) use (&$deprecations) {
522-
if (E_USER_DEPRECATED === $type) {
523-
$deprecations[] = $msg;
522+
if (E_USER_DEPRECATED !== $type) {
523+
restore_error_handler();
524+
525+
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
524526
}
527+
528+
$deprecations[] = $msg;
525529
});
526530

527531
$loader->load('legacy_invalid_alias_definition.xml');
528532

533+
restore_error_handler();
534+
529535
$this->assertTrue($container->has('bar'));
530536

531537
$this->assertCount(3, $deprecations);
532538
$this->assertContains('Using the attribute "class" is deprecated for alias definition "bar"', $deprecations[0]);
533539
$this->assertContains('Using the element "tag" is deprecated for alias definition "bar"', $deprecations[1]);
534540
$this->assertContains('Using the element "factory" is deprecated for alias definition "bar"', $deprecations[2]);
535-
536-
restore_error_handler();
537541
}
538542
}

src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ public function testRenderFallbackWithObjectAttributesIsDeprecated()
3232
{
3333
$deprecations = array();
3434
set_error_handler(function ($type, $message) use (&$deprecations) {
35-
if (E_USER_DEPRECATED === $type) {
36-
$deprecations[] = $message;
35+
if (E_USER_DEPRECATED !== $type) {
36+
restore_error_handler();
37+
38+
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
3739
}
40+
41+
$deprecations[] = $message;
3842
});
3943

4044
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo'));
@@ -45,10 +49,10 @@ public function testRenderFallbackWithObjectAttributesIsDeprecated()
4549

4650
$strategy->render($reference, $request);
4751

52+
restore_error_handler();
53+
4854
$this->assertCount(1, $deprecations);
4955
$this->assertContains('Passing objects as part of URI attributes to the ESI and SSI rendering strategies is deprecated', $deprecations[0]);
50-
51-
restore_error_handler();
5256
}
5357

5458
public function testRender()

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,13 @@ public function testParseUnquotedScalarStartingWithPercentCharacter()
260260
{
261261
$deprecations = array();
262262
set_error_handler(function ($type, $msg) use (&$deprecations) {
263-
if (E_USER_DEPRECATED === $type) {
264-
$deprecations[] = $msg;
263+
if (E_USER_DEPRECATED !== $type) {
264+
restore_error_handler();
265+
266+
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
265267
}
268+
269+
$deprecations[] = $msg;
266270
});
267271

268272
Inline::parse('{ foo: %foo }');

0 commit comments

Comments
 (0)