lundi 9 juillet 2018

Unit test - Expected status code 201 but received 200

I want to testing Controller's method. I using it to ajax request.

public function testBasicTest()
{  

    $response = $this->withHeaders([
    ])->json('POST', 'http://localhost:8000/cities', ['id' => 1]);

    $response
        ->assertStatus(201)
        ->assertJson([
            'created' => true,
        ]);
}

On this example I have this error

Expected status code 201 but received 200. Failed asserting that false is true.

When I'll change expected status to 200 I have this error

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

Aucun commentaire:

Enregistrer un commentaire