Functional test of a symfony2 controller: How to generate a route Functional test of a symfony2 controller: How to generate a route php php

Functional test of a symfony2 controller: How to generate a route


Symfony2's built in test framework (WebTestCase) only needs the relative path to be able to test applications in different environments:

$client->getContainer()->get('router')->generate('my_route', array(), false);

Symfony simulates an http client and tests against an instance of the Kernel created for that test. There are no web servers involved.

You can read more about how the client simulation works here: http://symfony.com/doc/current/book/testing.html#working-with-the-test-client


As mentioned in Symfony documentation, you should use absolute urls, because change of URLs will impact your end users and thats what you wanna cover in your functional tests too.

"Hardcoding the request URLs is a best practice for functional tests. If the test generates URLs using the Symfony router, it won't detect any change made to the application URLs which may impact the end users."

See more info here: http://symfony.com/doc/current/book/testing.html#working-with-the-test-client