Category: fosrestbundle

Testing Controllers in Symfony 4.4 while using annotations

I’m facing a problem of testing my Controllers in Symfony 4.4 with FOSRestBundle & JMSSserializer. My controllers are pretty simple, usually containing nothing but call to another services, but I’m using ParamConverter, Serializer, Deserializer etc. I’m never sure if fields…

How to use normalizer option in Symfony constraints component

The documentation https://symfony.com/doc/4.4/reference/constraints/Length.html#normalizer states that This option allows to define the PHP callable applied to the given value before checking if it is valid. For example, you may want to pass the ‘trim’ string to apply the trim PHP function…

Symfony "fos_rest.request_body" converter: do not deserialize nested DTO classes

I have a OrderDto class with a nested PointDto class (array of points): class OrderDto { /** * @var PointDto[] * @AssertAll({ * @AssertType(“AppDtoPointDto”) * }) * @AssertValid() */ private array $points; // getters, setters } The PointDto class also…

Adding services to a Controller through "container.service_subscriber" not working as expected

I am trying to use the container.service_subscriber tag on my Controller to make some services available without injecting them through the constructor. In our project we don’t want to use the autowiring and also can’t use the autoconfigure option. The…

Argument 1 passed to FOSRestBundleControllerExceptionController::getStatusCode()

I write in symfony 4 API using FOSRestBundle, unfortunately I get an error with every request: Argument 1 passed to FOSRestBundleControllerExceptionController::getStatusCode() must be an instance of Exception, instance of SymfonyComponentErrorHandlerExceptionFlattenException given, called in D:event-apivendorfriendsofsymfonyrest-bundleControllerExceptionController.php on line 68 I also have…