dimanche 23 octobre 2016

Symfony 3 functional tests - custom request class

I'm writing functional tests for my Symfony 3 application and I have a problem that every method in controller accepts only custom request, not default Request class, which is used in the BrowserKit crawler. How can I mock custom Request class in the Symfony 3 crawler or do it in the other way?

Here is my code:

ListController.php

public function listAction(CustomRequest $request) 
{
return $this->render('list.html.twig');
}

ListControllerTest.php

 $client = static::createClient();
 $crawler = $client->request('GET', '/list/');

When I'm running test I'm receiving:

TypeError: Argument 1 passed to AppBundle\Controller\ListController::listAction() must be an instance of AppBundle\Component\Http\CustomRequest, instance of Symfony\Component\HttpFoundation\Request given

Here is my app.php. Here I'm replacing the stanard request method:

$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = CustomRequest::createFromGlobals();
$response = $kernel->handle($request);
$response->send();

Aucun commentaire:

Enregistrer un commentaire