Search code examples
phpsymfonyphpunitfunctional-testing

Functional testing MissingMandatoryParametersException if locale in my route


I call a method of my API by its name from a specific test through phpunit and I'm having this error:

exception

'Symfony\Component\Routing\Exception\MissingMandatoryParametersException' with message 'Some mandatory parameters are missing ("_locale") to generate a URL for route "some_route" in ...

src\Symfony\Component\Routing\Generator\UrlGenerator.php:155

When the method I'm calling from my test call generate of Router

Given that I'm using this technique http://symfony.com/doc/current/cookbook/testing/simulating_authentication.html to authenticate but without Client cause I don't need to request URLs. I'm just having my $kernel = static::createKernel(....

And here is my routing.yml

some_route:
   pattern: /{_locale}/id
   default: { _controller: myBundle:myController:myAction }

Do you know how do I fix it ?


Solution

  • Do you know how do I fix it ?

    Pass a value for the _locale parameter (which is in your route and does not have a default value) when generating the route using Router#generate().

    Btw, be aware that it is not considered a good practice if you use Router#generate() in your tests to generate the route to access, use static strings instead.