I
I
Ilya Loopashko2021-09-29 07:04:18
PHPUnit
Ilya Loopashko, 2021-09-29 07:04:18

How to check the value by condition in the response when testing api?

I created a test that checks if the record is created in the database. The answer comes back.

{
  "status": "OK",
  "message": "Запись с таким id обнаружена",
  "data": {
    "work": {
      "id": 14,
      "equipment_id": 64,
      "time_start": "08:00",
      "time_end": "19:59",
      "comment": "08 -> 20",
      "equipment": {
        "id": 64,
        "title": "Car1",

      }
    }
  }
}

The peculiarity is that I always have "time_end" minus a minute, and only 20:00 minus a minute. The rest of the time is always fine.
How to check this value that always comes 19:59?

Test
$this->json('GET', '/api/works/show/1')
            ->assertJson([
                'status' => 'OK',
            ]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Loopashko, 2021-09-29
@deadloop

They always tell me that I would read the documentation, well, I read it and found such a solution.
But maybe there are other ways, I would not mind, thanks.

$response = $this->get('/api/works/show/1');
        $response
            ->assertJson(fn (AssertableJson $json) =>
                $json->has('status')
                    ->has('message')
                    ->has('data.work', fn ($json) =>
                        $json->where('time_end', '19:59')
                            ->etc()
                    )
            );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question