I want to write a TestScenario in Behat for a POST Method that takes an Object as input.
Feature: Testing The ChildController Endpoint
Scenario: Trying to create an Child by POSTing vars with an existing Id
Given that I want to make a new "Child"
And the request is sent as JSON
And its "screening_id" is "999888777666"
And his "first_name" is "John"
And his "last_name" is "Doe"
And his "birth_date" is "1979-01-01"
And his "gender" is "m"
When I request "/v1/child"
Then the response status code should be 409
And the response should be JSON
And the response has a "error" property
My Method is like:
/**
* Child Endpoint v1
*
* @url POST child/
* @status 201
*
* @param Child $child JSON data
* @return application/json
* @throws RestException
*/
function insertChild(Child $child){......}
My JSON Object that I pass looks like this:
{
"child": {
"screening_id": "",
"first_name": "",
"last_name": "",
"birth_date": "",
"gender": ""
}
}
Now... when I make a request with Postman with only:
{
"screening_id": "",
"first_name": "",
"last_name": "",
"birth_date": "",
"gender": ""
}
it works fine. But when I'm running the Behat Test, it says that I specified an invalid value for 'child' and I get:
"error": {
"code": 400,
"message": "Bad Request: Invalid value specified for 'child'. Expecting an item of type `v1\\models\\Child`"
}
It works from everywhere without specifying the 'child' only from BeHat not.