Symfony 6.4 WebTestCase emty body #6521
-
Hello everyone, i am having some problems with phpUnit WebTestCase, i want to test a route created on my own with POST method, but when i try to send a body i got an error that saying an empty body is sent which is false because i set a body in my test. I have added the link to the stackoverflow questions i have posted. I really need help, i can't get over that and i tried to ask ClaudeAi ChatGPT but none have the solutions for my problems. if you are more details answer me i will be happy to respond to your question. https://stackoverflow.com/questions/78871456/symfony-6-4-webtestcase-emty-body In hope you can help me, thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi D3xime, I'm not sure where you're getting that signature from of calling As per the docs: https://symfony.com/doc/6.4/http_client.html#uploading-data , it also has built-in JSON support, so try like this: $client->request(
'POST',
'/api/zone/1',
[
'headers' => ['Accept' => 'application/json'],
'json' => $parameters,
]
); I also notice you wrote the header as |
Beta Was this translation helpful? Give feedback.
Oh I see. Seeing as you're using APIP, it's probably worth extending ApiTestCase rather than WebTestCase? https://github.com/api-platform/core/blob/main/src/Symfony/Bundle/Test/ApiTestCase.php#L37 that would use HttpClientInterface, and have other benefits as described in the APIP docs: https://api-platform.com/docs/core/testing/
I'm not particularly familiar with Symfony's BrowserKit, but if you want to keep using it instead, a couple of things I notice:
jsonRequest
method that would simplify things: https://symfony.com/doc/current/components/browser_kit.html#making-requests