I try to write tests for my symfony API (symfony version : 3.4).
My symfony project is made to be the API. I use fosRest bundle
I have this error when trying to call an entry point :
Unable to find template "" (looked into: C:\wamp64\www\myproject\src\app/Resources/views, C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Bridge\Twig/Resources/views/Form).
When i run my test with xdebug, it passes in my controller and get the result i need.
In HttpKernel
i see my entity at this line :
$response = \call_user_func_array($controller, $arguments);
But after this line, it goes in the view block and returns me this error.
Is this a config problem ?
entry point in my controller :
/**
* @param $id
* @Get("/metiers/{id}")
* @return \AppBundle\Entity\Metier
*/
public function getMetierAction($id)
{
return $this->getDoctrine()->getManager()->getRepository('AppBundle:Metier')->findOneById($id);
}
Here is my test :
$client = static::createClient([], [
'PHP_AUTH_USER' => 'myuser',
'PHP_AUTH_PW' => 'pa$$word',
]);
$client->request('GET', 'http://myproject.localhost/metiers/1');
$response = $client->getResponse();
$content = json_decode($response->getContent(), true);
my config_test.yml file :
imports:
- { resource: parameters_test.yml }
- { resource: config.yml }
framework:
test: true
security:
firewalls:
# replace 'main' by the name of your own firewall
main:
http_basic: ~
callStack in xdebug :
InvalidArgumentException: Unable to find template "" (looked into: C:\wamp64\www\myproject\src\app/Resources/views, C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Bridge\Twig/Resources/ views/Form). in C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Bridge\Twig\TwigEngine.php on line 127
Call Stack:
0.2183 585024 1. {main}() C:\Users\myuser\AppData\Local\Temp\PHP2E4D.tmp:0
2.2398 2660672 2. __phpunit_run_isolated_test() C:\Users\myuser\AppData\Local\Temp\PHP2E4D.tmp:606
2.2411 2756680 3. Tests\AppBundle\Controller\MetierControllerTest->run(???) C:\Users\myuser\AppData\Local\Temp\PHP2E4D.tmp:327
2.2428 2964136 4. PHPUnit_Framework_TestResult->run(???) C:\wamp64\www\myproject\src\vendor\phpunit\phpunit\src\Framework\TestCase.php:868
2.2473 3000096 5. Tests\AppBundle\Controller\MetierontrollerTest->runBare() C:\wamp64\www\myproject\src\vendor\phpunit\phpunit\src\Framework\TestResult.php:686
2.2532 3017024 6. Tests\AppBundle\Controller\MetierControllerTest->runTest() C:\wamp64\www\myproject\src\vendor\phpunit\phpunit\src\Framework\TestCase.php:913
2.2532 3017320 7. ReflectionMethod->invokeArgs(???, ???) C:\wamp64\www\myproject\src\vendor\phpunit\phpunit\src\Framework\TestCase.php:1062
2.2532 3017328 8. Tests\AppBundle\Controller\MetierControllerTest->testIndex() C:\wamp64\www\myproject\src\vendor\phpunit\phpunit\src\Framework\TestCase.php:1062
2.2532 3017328 9. Tests\AppBundle\Controller\MetierControllerTest->checkRegenerateFacture() C:\wamp64\www\myproject\src\tests\AppBundle\Controller\MetierControllerTest.php:15
5.0054 5866064 10. Symfony\Bundle\FrameworkBundle\Client->request(???, ???, ???, ???, ???, ???, ???) C:\wamp64\www\myproject\src\tests\AppBundle\Controller\MetierControllerTest.php:26
5.0093 5965232 11. Symfony\Bundle\FrameworkBundle\Client->doRequest(???) C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Component\BrowserKit\Client.php:318
5.0093 5965232 12. Symfony\Bundle\FrameworkBundle\Client->doRequest(???) C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Client.php:131
5.0093 5965232 13. AppKernel->handle(???, ???, ???) C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Client.php:68
5.0326 7010312 14. Symfony\Component\HttpKernel\HttpKernel->handle(???, ???, ???) C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php:200
5.0327 7011048 15. Symfony\Component\HttpKernel\HttpKernel->handleRaw(???, ???) C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php:68
23.6599 25210184 16. Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->dispatch(???, ???) C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php:156
29.2349 25323480 17. Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(???, ???) C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher.php:143
29.2350 25323856 18. Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->doDispatch(???, ???, ???) C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\EventDispatcher.php:44
29.2350 25323856 19. Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(???, ???, ???) C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\EventDispatcher.php:212
29.2351 25324416 20. FOS\RestBundle\EventListener\ViewResponseListener->onKernelView(???, ???, ???) C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\Debug\WrappedListener.php:115
29.2360 25354176 21. FOS\RestBundle\View\ViewHandler->handle(???, ???) C:\wamp64\www\myproject\src\vendor\friendsofsymfony\rest-bundle\EventListener\ViewResponseListener.php:132
29.2360 25354176 22. FOS\RestBundle\View\ViewHandler->createResponse(???, ???, ???) C:\wamp64\www\myproject\src\vendor\friendsofsymfony\rest-bundle\View\ViewHandler.php:310
29.2360 25354176 23. FOS\RestBundle\View\ViewHandler->initResponse(???, ???) C:\wamp64\www\myproject\src\vendor\friendsofsymfony\rest-bundle\View\ViewHandler.php:426
29.2360 25354176 24. FOS\RestBundle\View\ViewHandler->renderTemplate(???, ???) C:\wamp64\www\myproject\src\vendor\friendsofsymfony\rest-bundle\View\ViewHandler.php:452
29.2361 25354552 25. Symfony\Bundle\TwigBundle\TwigEngine->render(???, ???) C:\wamp64\www\myproject\src\vendor\friendsofsymfony\rest-bundle\View\ViewHandler.php:373
29.2361 25354552 26. Symfony\Bundle\TwigBundle\TwigEngine->render(???, ???) C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Bundle\TwigBundle\TwigEngine.php:45
29.2361 25354552 27. Symfony\Bundle\TwigBundle\TwigEngine->load(???) C:\wamp64\www\myproject\src\vendor\symfony\symfony\src\Symfony\Bridge\Twig\TwigEngine.php:49