Skip to content

Commit 6f777ed

Browse files
committed
fix testing deprecation messages
* always restore the previous error handler * throw `LogicExcetion` when unexpected error type is triggered
1 parent f7b4a49 commit 6f777ed

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Tests/ContainerBuilderTest.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,27 @@ public function testDefinitions()
6161

6262
public function testCreateDeprecatedService()
6363
{
64-
$definition = new Definition('stdClass');
65-
$definition->setDeprecated(true);
64+
$deprecations = array();
65+
set_error_handler(function ($type, $msg) use (&$deprecations) {
66+
if (E_USER_DEPRECATED !== $type) {
67+
restore_error_handler();
6668

67-
$that = $this;
68-
$wasTriggered = false;
69+
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
70+
}
6971

70-
set_error_handler(function ($errno, $errstr) use ($that, &$wasTriggered) {
71-
$that->assertSame(E_USER_DEPRECATED, $errno);
72-
$that->assertSame('The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.', $errstr);
73-
$wasTriggered = true;
72+
$deprecations[] = $msg;
7473
});
7574

75+
$definition = new Definition('stdClass');
76+
$definition->setDeprecated(true);
77+
7678
$builder = new ContainerBuilder();
7779
$builder->createService($definition, 'deprecated_foo');
7880

7981
restore_error_handler();
8082

81-
$this->assertTrue($wasTriggered);
83+
$this->assertCount(1, $deprecations);
84+
$this->assertContains('The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.', $deprecations[0]);
8285
}
8386

8487
public function testRegister()

0 commit comments

Comments
 (0)