i have been struggling for 2 days now. I already searched online but can’t find an answer.
I have created a simple API with request Validation, but i can’t test the route i have created because when i send a body it appears to be always empty. Below my testCase for example
public function testChangeStateOnZoneWithInvalidData(): void
{
$client = static::createClient();
$parameters = []; // Corps de la requête JSON vide
$client->request(
'POST',
'/api/zone/1',
[], // Pas de paramètres GET
[], // Pas de fichiers
[
'CONTENT_TYPE' => 'application/json',
'ACCEPT' => 'application/json',
],
json_encode($parameters) // Corps de la requête JSON
);
dump($client->getRequest()->getContent());
$response = $client->getResponse();
// Afficher la réponse pour le débogage
// dump($response->getContent()); s
// Vérifiez si la réponse est un JSON valide
$this->assertJson($response->getContent(), 'Response is not valid JSON');
// Vérifiez le code de statut
$this->assertEquals(400, $response->getStatusCode(), 'Expected status code 400');
}
Anyone could help me to find a workaroud or to help to do something good.
New contributor
D3xime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.