2015-08-14 30 views
0

我通過phpunit叫我的API的方法,通過它的名字來自一個特定的測試,我有這樣的錯誤:功能測試MissingMandatoryParametersException如果locale在我的路線

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

當方法我從打電話的Router

我的測試呼叫generate由於我使用這種技術http://symfony.com/doc/current/cookbook/testing/simulating_authentication.html進行認證,但不Client,因爲我並不需要將請求的URL。我只是有我$kernel = static::createKernel(....

And here is my routing.yml

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

你知不知道我該如何解決?

回答

1

Do you know how do I fix it ?

通作_locale參數的值(這是你的路線,並沒有默認值)生成使用Router#generate()路由時。

順便說一句,請注意,如果您在測試中使用Router#generate()來生成訪問路由,請改爲使用靜態字符串,這並不是一種好的做法。

+0

調用'Router#generate()'的方法是一種服務的方法 – smarber