Symfony Debug to Error Handler Component
Since symfony 4.4 the symfony/debug
component is deprecated.
The “\Symfony\Component\Debug\ErrorHandler” class is deprecated since Symfony 4.4, use “\Symfony\Component\ErrorHandler\ErrorHandler”
Running unit tests on Mascot, I noticed lots of warnings.
But it was not easy as changing Symfony\Component\Debug\ExceptionHandler
to Symfony\Component\ErrorHandler\ErrorHandler
.
Assume we have something as below
|
|
The Symfony\Component\ErrorHandler\ErrorHandler
has no getHtml
method.
From the symfony docs, if you are in development mode we can use below code.
<?php
if ($_SERVER['APP_DEBUG']) {
Debug::enable();
}
so I started with
<?php
ErrorHandler::register();
But it was throwing all details. I was struggling how to fix this. After many failed experiments, I asked Yonel Ceruto Gonzalez.
Sets the scope at 0 to tell the handler that it is in “non-debug” mode:
$errorHandler->scopeAt(0, true);
However, don't expect the real exception message in non-debug mode, it could reveal sensitive information.
— Yonel Ceruto Gonzalez1
The above information was really helpful to do more experiments. I finally fixed the unit tests with the below code.
|
|
I hope this information may help someone at somepoint of time.
-
Taken from twitter status Yonel Ceruto Gonzalez