我想在Behat中为一个以Object作为输入的POST方法编写一个TestScenario。
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
我的方法就像:
/**
* Child Endpoint v1
*
* @url POST child/
* @status 201
*
* @param Child $child JSON data
* @return application/json
* @throws RestException
*/
function insertChild(Child $child){......}
我传递的My JSON对象如下所示:
{
"child": {
"screening_id": "",
"first_name": "",
"last_name": "",
"birth_date": "",
"gender": ""
}
}
现在......当我向Postman提出请求时只有:
{
"screening_id": "",
"first_name": "",
"last_name": "",
"birth_date": "",
"gender": ""
}
它工作正常。 但是,当我运行Behat测试时,它说我为“孩子”指定了无效值。我得到了:
"error": {
"code": 400,
"message": "Bad Request: Invalid value specified for 'child'. Expecting an item of type `v1\\models\\Child`"
}
它可以在任何地方使用,而无需指定“孩子”。只有BeHat没有。