I am trying to test if the filter response has the right JSON data (every item should have the filtered group_code). I tried the following code but it doesn't work.
public function test_filter_items_by_group_code_work_properly()
{
$filterCode = '026';
$response = $this->get($this->ITEMS_URL . '?' . $this->groupAttribute . '='. $filterCode);
$response->assertStatus(200);
$items = $response->json()['data'];
foreach ($items as $item) {
$item_group = strval($item['group_code']);
self::assertJson($item_group, $filterCode);
}
}
I get the following error:
Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Trying to access array offset
on value of type int",
The JSON response structure is like that:
{
"message": "Items fetched successfully.",
"data": {
"current_page": 1,
"data": [
{
"group_code": "026",
...
},
...