【发布时间】:2016-03-24 02:32:09
【问题描述】:
我想在 Behat 中为一个将对象作为输入的 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){......}
我传递的 JSON 对象如下所示:
{
"child": {
"screening_id": "",
"first_name": "",
"last_name": "",
"birth_date": "",
"gender": ""
}
}
现在...当我向 Postman 提出请求时,只有:
{
"screening_id": "",
"first_name": "",
"last_name": "",
"birth_date": "",
"gender": ""
}
它工作正常。 但是当我运行 Behat 测试时,它说我为 'child' 指定了一个无效值,我得到:
"error": {
"code": 400,
"message": "Bad Request: Invalid value specified for 'child'. Expecting an item of type `v1\\models\\Child`"
}
它可以在任何地方工作,而无需仅从 BeHat 指定“孩子”。
【问题讨论】:
-
Restler RC5 或 RC6 哪个版本?
-
我使用的是版本 3 RC5