fix testing deprecation messages

* always restore the previous error handler
* throw `LogicExcetion` when unexpected error type is triggered
This commit is contained in:
Christian Flothmann 2016-03-24 14:26:59 +01:00
parent 243e59c108
commit 0df544ff4c
4 changed files with 25 additions and 11 deletions

View File

@ -91,7 +91,9 @@ class TemplateNameParserTest extends TestCase
$deprecations = array();
set_error_handler(function ($type, $msg) use (&$deprecations) {
if (E_USER_DEPRECATED !== $type) {
throw new \LogicException(sprintf('Unexpected error: "%s".', $msg));
restore_error_handler();
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
}
$deprecations[] = $msg;

View File

@ -519,20 +519,24 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$deprecations = array();
set_error_handler(function ($type, $msg) use (&$deprecations) {
if (E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
if (E_USER_DEPRECATED !== $type) {
restore_error_handler();
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
}
$deprecations[] = $msg;
});
$loader->load('legacy_invalid_alias_definition.xml');
restore_error_handler();
$this->assertTrue($container->has('bar'));
$this->assertCount(3, $deprecations);
$this->assertContains('Using the attribute "class" is deprecated for alias definition "bar"', $deprecations[0]);
$this->assertContains('Using the element "tag" is deprecated for alias definition "bar"', $deprecations[1]);
$this->assertContains('Using the element "factory" is deprecated for alias definition "bar"', $deprecations[2]);
restore_error_handler();
}
}

View File

@ -32,9 +32,13 @@ class EsiFragmentRendererTest extends \PHPUnit_Framework_TestCase
{
$deprecations = array();
set_error_handler(function ($type, $message) use (&$deprecations) {
if (E_USER_DEPRECATED === $type) {
$deprecations[] = $message;
if (E_USER_DEPRECATED !== $type) {
restore_error_handler();
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
}
$deprecations[] = $message;
});
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo'));
@ -45,10 +49,10 @@ class EsiFragmentRendererTest extends \PHPUnit_Framework_TestCase
$strategy->render($reference, $request);
restore_error_handler();
$this->assertCount(1, $deprecations);
$this->assertContains('Passing objects as part of URI attributes to the ESI and SSI rendering strategies is deprecated', $deprecations[0]);
restore_error_handler();
}
public function testRender()

View File

@ -260,9 +260,13 @@ class InlineTest extends \PHPUnit_Framework_TestCase
{
$deprecations = array();
set_error_handler(function ($type, $msg) use (&$deprecations) {
if (E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
if (E_USER_DEPRECATED !== $type) {
restore_error_handler();
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
}
$deprecations[] = $msg;
});
Inline::parse('{ foo: %foo }');