我想测试正在执行ajax请求的Controller方法
public function testBasicTest()
{
$response = $this->withHeaders([
])->json('POST', 'http://localhost:8000/cities', ['id' => 1]);
$response
->assertStatus(201)
->assertJson([
'created' => true,
]);
}
在此示例中,我遇到此错误:
预期的状态码201,但收到200。 无法断言false为真。
当预期状态更改为200时,我收到此错误:
There was 1 failure:
1) Tests\Unit\ExampleTest::testBasicTest
Unable to find JSON:
[{
"created": true
}]
within response JSON:
[[
{
"id": 1,
"name": "London",
"created_at": "2018-07-02 12:05:18",
"updated_at": "2018-07-02 12:05:18"
},
{
"id": 2,
"name": "Berlin",
"created_at": "2018-07-02 12:05:18",
"updated_at": "2018-07-02 12:05:18"
},
{
"id": 3,
"name": "Paris",
"created_at": "2018-07-02 12:05:18",
"updated_at": "2018-07-02 12:05:18"
},
]].
Failed asserting that an array has the subset Array &0 (
'created' => true
).
--- Expected
+++ Actual
@@ @@
- [created] => 1