How to test a controller's function that it is not associated to an URL (components of symfony1)?
I found the way to test an action in symfony2, for example this way:
public function testShow()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/about');
$this->assertTrue($client->getResponse()->getStatusCode() == '200' );
$this->assertTrue($crawler->filter('title:contains("About")')-> >count() > 0);
$this-开发者_运维百科>assertTrue($crawler->filter('h2:contains("About")')-> >count() > 0);
}
As you can see the action that it's been tested is associated to a URL (/about), but how to test a controller's function that it is not associated to an URL (components of symfony1) ?
There is an _internal route you could use. But if you use {% render 'Something' %} then it would be in the rendedren content of other controller.
You can define your contoroller as a service and test it.
Or just create it as plain php object and set container via ->setContainer()
精彩评论