2023-07-23 13:52:33 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Controllers\Api;
|
|
|
|
|
2023-11-03 19:03:31 +01:00
|
|
|
use Engelsystem\Controllers\Api\LocationsController;
|
2023-07-23 13:52:33 +02:00
|
|
|
use Engelsystem\Http\Response;
|
2023-11-03 19:03:31 +01:00
|
|
|
use Engelsystem\Models\Location;
|
2023-07-23 13:52:33 +02:00
|
|
|
|
2023-11-03 19:03:31 +01:00
|
|
|
class LocationsControllerTest extends ApiBaseControllerTest
|
2023-07-23 13:52:33 +02:00
|
|
|
{
|
|
|
|
/**
|
2023-11-03 19:03:31 +01:00
|
|
|
* @covers \Engelsystem\Controllers\Api\LocationsController::index
|
2023-07-23 13:52:33 +02:00
|
|
|
*/
|
|
|
|
public function testIndex(): void
|
|
|
|
{
|
2023-11-03 19:03:31 +01:00
|
|
|
$items = Location::factory(3)->create();
|
2023-07-23 13:52:33 +02:00
|
|
|
|
2023-11-03 19:03:31 +01:00
|
|
|
$controller = new LocationsController(new Response(), $this->url);
|
2023-07-23 13:52:33 +02:00
|
|
|
|
|
|
|
$response = $controller->index();
|
2023-11-03 19:03:31 +01:00
|
|
|
$this->validateApiResponse('/locations', 'get', $response);
|
2023-07-23 13:52:33 +02:00
|
|
|
|
|
|
|
$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');
|
|
|
|
}));
|
2023-07-23 13:52:33 +02:00
|
|
|
}
|
|
|
|
}
|