To ensure continuity of responses/exceptions with previous interface.
Changes
The order that the GetResponseForExceptionEvent and ExceptionEvent are checked have been swapped. This is because for within Symfony 4.3 & 4.4, ExceptionEvent is an extension of GetResponseForExceptionEvent and therefore would trigger either condition. By ensuring ExceptionEvent comes first, we ensure the correct (non-deprecated) method, getThrowable is called when available.
However, within Symfony 4.3, event though the ExceptionEvent exists, neither it nor its base class, GetResponseForExceptionEvent, implement the getThrowable method. This is why the method_exists check is present, to avoid attempting to call this method.
In addition, to ensure continuity with the InvalidArgumentException that would be thrown by adding type hints, this method will throw an InvalidArgumentException if the input is neither an ExceptionEvent with the getThrowable method, or a GetResponseForExceptionEvent.
Tests
Unit testing the changes proves to be difficult for a number of reasons.
There is seemingly no easy way to ensure a test only runs against a specific version of Symfony
In Symfony 5 the ExceptionEvent class is marked as final, meaning it cannot be mocked via mockery. It may be possible to create an ExceptionEvent, but because that requires an HttpKernel object it may be difficult to ensure all of the elements are in place and mockable to create a working configuration.
It would be feasible to create maze runner e2e tests in order to verify the change, however this would be a significant addition and may take time.
Goal
Changes
The order that the
GetResponseForExceptionEvent
andExceptionEvent
are checked have been swapped. This is because for within Symfony 4.3 & 4.4,ExceptionEvent
is an extension ofGetResponseForExceptionEvent
and therefore would trigger either condition. By ensuringExceptionEvent
comes first, we ensure the correct (non-deprecated) method,getThrowable
is called when available.However, within Symfony 4.3, event though the
ExceptionEvent
exists, neither it nor its base class,GetResponseForExceptionEvent
, implement thegetThrowable
method. This is why themethod_exists
check is present, to avoid attempting to call this method.In addition, to ensure continuity with the
InvalidArgumentException
that would be thrown by adding type hints, this method will throw anInvalidArgumentException
if the input is neither anExceptionEvent
with thegetThrowable
method, or aGetResponseForExceptionEvent
.Tests
Unit testing the changes proves to be difficult for a number of reasons.
There is seemingly no easy way to ensure a test only runs against a specific version of Symfony
In Symfony 5 the
ExceptionEvent
class is marked as final, meaning it cannot be mocked viamockery
. It may be possible to create anExceptionEvent
, but because that requires anHttpKernel
object it may be difficult to ensure all of the elements are in place and mockable to create a working configuration.It would be feasible to create maze runner e2e tests in order to verify the change, however this would be a significant addition and may take time.