engelsystem/tests/Unit/Controllers/Api/LocationsControllerTest.php

36 lines
1.1 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Engelsystem\Test\Unit\Controllers\Api;
use Engelsystem\Controllers\Api\LocationsController;
use Engelsystem\Http\Response;
use Engelsystem\Models\Location;
class LocationsControllerTest extends ApiBaseControllerTest
{
/**
* @covers \Engelsystem\Controllers\Api\LocationsController::index
*/
public function testIndex(): void
{
$items = Location::factory(3)->create();
$controller = new LocationsController(new Response(), $this->url);
$response = $controller->index();
$this->validateApiResponse('/locations', 'get', $response);
$this->assertEquals(['application/json'], $response->getHeader('content-type'));
$this->assertJson($response->getContent());
$data = json_decode($response->getContent(), true);
$this->assertArrayHasKey('data', $data);
$this->assertCount(3, $data['data']);
2023-07-31 20:49:17 +02:00
$this->assertCount(1, collect($data['data'])->filter(function ($item) use ($items) {
return $item['name'] == $items->first()->getAttribute('name');
}));
}
}