Laravel / PHPUnit: Assert json element exists without value definition

I am sending a mail request in a test case, and I want to claim that there is a certain element in the response, let them say with the key "x". In this case, I cannot say seeJson(['x' => whatever]);, because the meaning is unknown to me. and of course I cannot do this with help seeJson(['x']);.

Is there any way to solve this problem?

If it matters: Laravel: v5.2.31 PHPUnit: 5.3.4

+4
source share
2 answers

Although this is far from optimal, I decided to use this code to check the situation:

$this->post(URL, PARAMS)->see('x');

X - , . . a >

UPDATE:

, :

public function testCaseName()

{
    $this->post(route('route.name'), [
        'param1' => 1,
        'param2' => 10,
    ], [
        'headers_if_any' => 'value'
    ]);

    $res_array = (array)json_decode($this->response->content());

    $this->assertArrayHasKey('x', $res_array);
}
+2

- . json.

$this->post('/api/login/', [
        'email' => 'customer3@example.com',
        'password' => '123123123',
    ])->seeJsonStructure([
        'status',
        'result' => [
            'id',
            'email',
            'full_name',
        ],
    ]);
+4

All Articles