Php assertJson:在响应中找不到JSON

Php assertJson:在响应中找不到JSON,php,laravel,Php,Laravel,我想编写一个测试来检索一个事件,然后测试Events API集合是否工作 我已经阅读了关于使用Laravel和PHPUnit编写restapi测试的文档。我很难让assertJson通过,因为它返回以下错误: λ vendor\bin\phpunit --filter an_event_can_be_retrieved PHPUnit 8.5.8 by Sebastian Bergmann and contributors. F

我想编写一个测试来检索一个事件,然后测试Events API集合是否工作

我已经阅读了关于使用Laravel和PHPUnit编写restapi测试的文档。我很难让assertJson通过,因为它返回以下错误:

λ vendor\bin\phpunit --filter an_event_can_be_retrieved
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

F                                                                   1 / 1 (100%)

Time: 295 ms, Memory: 20.00 MB

There was 1 failure:

1) Tests\Feature\EventsTest::an_event_can_be_retrieved
Unable to find JSON:

[{
    "id": 1,
    "title": "Accusamus tempore natus ad hic vel tempore.",
    "description": "Quod dolores itaque dicta odio non sit.",
    "address": "1040 Greenholt Turnpike\nEast Kariane, OK 72586-4663",
    "start_date": "03/08/2020",
    "end_date": "03/18/2020",
    "lat": 87.052884,
    "long": 52.871515
}]

within response JSON:

[{
    "id": 1,
    "title": "Accusamus tempore natus ad hic vel tempore.",
    "description": "Quod dolores itaque dicta odio non sit.",
    "address": "1040 Greenholt Turnpike\nEast Kariane, OK 72586-4663",
    "lat": "87.052884",
    "long": "52.871515",
    "start_date": "2020-03-08T00:00:00.000000Z",
    "end_date": "2020-03-18T00:00:00.000000Z",
    "user_id": "1",
    "created_at": "2020-09-09T03:42:04.000000Z",
    "updated_at": "2020-09-09T03:42:04.000000Z",
    "user": {
        "id": 1,
        "name": "Eva Lehner III",
        "email": "cecil.johns@example.org",
        "email_verified_at": "2020-09-09T03:42:04.000000Z",
        "api_token": "A4rUKPw3XsrwSNB3c8s4JwsP51Cw10Ej",
        "created_at": "2020-09-09T03:42:04.000000Z",
        "updated_at": "2020-09-09T03:42:04.000000Z"
    }
}].


Failed asserting that an array has the subset Array &0 (
    'id' => 1
    'title' => 'Accusamus tempore natus ad hic vel tempore.'
    'description' => 'Quod dolores itaque dicta odio non sit.'
    'address' => '1040 Greenholt Turnpike\n
East Kariane, OK 72586-4663'
    'start_date' => '03/08/2020'
    'end_date' => '03/18/2020'
    'lat' => 87.052884
    'long' => 52.871515
).
--- Expected
+++ Actual
@@ @@
   'description' => 'Quod dolores itaque dicta odio non sit.',
   'address' => '1040 Greenholt Turnpike
 East Kariane, OK 72586-4663',
-  'lat' => 87.052884,
-  'long' => 52.871515,
-  'start_date' => '03/08/2020',
-  'end_date' => '03/18/2020',
+  'lat' => '87.052884',
+  'long' => '52.871515',
+  'start_date' => '2020-03-08T00:00:00.000000Z',
+  'end_date' => '2020-03-18T00:00:00.000000Z',
   'user_id' => '1',
   'created_at' => '2020-09-09T03:42:04.000000Z',
   'updated_at' => '2020-09-09T03:42:04.000000Z',

C:\MAMP\htdocs\frontend\vendor\laravel\framework\src\Illuminate\Testing\Constraints\ArraySubset.php:220
C:\MAMP\htdocs\frontend\vendor\laravel\framework\src\Illuminate\Testing\Assert.php:49
C:\MAMP\htdocs\frontend\vendor\laravel\framework\src\Illuminate\Testing\TestResponse.php:497
C:\MAMP\htdocs\frontend\tests\Feature\EventsTest.php:114

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
测试:

事件控制器

public function index()
    {
        return request()->user()->events;
    }
注意:我是Laravel的新手,如果您对如何编写更好的测试单元有任何建议,我将不胜感激

public function index()
    {
        return request()->user()->events;
    }