Skip to content

Commit

Permalink
feat: added city to query airport response
Browse files Browse the repository at this point in the history
  • Loading branch information
amvid committed Sep 1, 2024
1 parent f71137e commit 2fc43a1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/Airport/Action/Query/QueryAirportsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function run(QueryAirportsActionRequest $request): QueryAirportsActionRes
$res[] = new QueryChildrenAirportResponse(
$cityTitle . ' (Any)',
$cityIata,
$cityTitle,
$countryTitle,
$regions[$countryTitle],
$subregions[$countryTitle],
Expand All @@ -71,6 +72,7 @@ public function run(QueryAirportsActionRequest $request): QueryAirportsActionRes
$res[$parentIndex]->children[] = new QueryAirportResponse(
$airport->getTitle(),
$airport->getIata(),
$airport->getCity()->getTitle(),
$countryTitle,
$regions[$countryTitle],
$subregions[$countryTitle],
Expand All @@ -81,6 +83,7 @@ public function run(QueryAirportsActionRequest $request): QueryAirportsActionRes
$res[] = new QueryAirportResponse(
$airport->getTitle(),
$airport->getIata(),
$airport->getCity()->getTitle(),
$countryTitle,
$regions[$countryTitle],
$subregions[$countryTitle],
Expand Down
4 changes: 3 additions & 1 deletion src/Airport/Controller/Response/QueryAirportResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ class QueryAirportResponse
{
public string $title;
public string $iata;
public string $city;
public string $country;
public ?string $region = null;
public ?string $subregion = null;

public function __construct(string $title, string $iata, string $country, ?string $region = null, ?string $subregion = null)
public function __construct(string $title, string $iata, string $city, string $country, ?string $region = null, ?string $subregion = null)
{

$this->title = $title;
$this->iata = $iata;
$this->city = $city;
$this->country = $country;
$this->region = $region;
$this->subregion = $subregion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ class QueryChildrenAirportResponse
{
public string $title;
public string $iata;
public string $city;
public string $country;
public ?string $subregion = null;
public ?string $region = null;

/** @var array<QueryAirportResponse> */
public array $children = [];

public function __construct(string $title, string $iata, string $country, ?string $region = null, ?string $subregion = null, array $children = [])
public function __construct(string $title, string $iata, string $city, string $country, ?string $region = null, ?string $subregion = null, array $children = [])
{
$this->title = $title;
$this->iata = $iata;
$this->city = $city;
$this->country = $country;
$this->subregion = $subregion;
$this->region = $region;
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/Airport/Action/Query/QueryAirportsActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ public function testShouldReturnAirports(): void
$action = new QueryAirportsAction($this->airportRepository);
$response = $action->run($this->request);

$country = $airport->getCity()->getCountry();
$city = $airport->getCity();
$country = $city->getCountry();
$subregion = $country->getSubregion();
$region = $subregion->getRegion();

$this->assertCount(1, $response->airports);
$this->assertEquals($airport->getTitle(), $response->airports[0]->title);
$this->assertEquals($airport->getIata(), $response->airports[0]->iata);
$this->assertEquals($city->getTitle(), $response->airports[0]->city);
$this->assertEquals($country->getTitle(), $response->airports[0]->country);
$this->assertEquals($subregion->getTitle(), $response->airports[0]->subregion);
$this->assertEquals($region->getTitle(), $response->airports[0]->region);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ public function testValidInstantiation(): void
{
$airport = AirportDummy::get();

$country = $airport->getCity()->getCountry();
$city = $airport->getCity();
$country = $city->getCountry();
$subregion = $country->getSubregion();
$region = $subregion->getRegion();

$actual = new QueryAirportResponse(
$airport->getTitle(),
$airport->getIata(),
$airport->getCity()->getCountry()->getTitle(),
$city->getTitle(),
$country->getTitle(),
$region->getTitle(),
$subregion->getTitle(),
);

$this->assertEquals($airport->getTitle(), $actual->title);
$this->assertEquals($airport->getIata(), $actual->iata);
$this->assertEquals($airport->getCity()->getCountry()->getTitle(), $actual->country);
$this->assertEquals($city->getTitle(), $actual->city);
$this->assertEquals($country->getTitle(), $actual->country);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,38 @@ class QueryChildrenAirportResponseTest extends TestCase
public function testValidInstantiation(): void
{
$airport = AirportDummy::get();
$country = $airport->getCity()->getCountry();
$city = $airport->getCity();
$country = $city->getCountry();
$subregion = $country->getSubregion();
$region = $subregion->getRegion();

$children = new QueryAirportResponse(
$airport->getTitle(),
$airport->getIata(),
$airport->getCity()->getCountry()->getTitle(),
$city->getTitle(),
$country->getTitle(),
$region->getTitle(),
$subregion->getTitle(),
);

$actual = new QueryChildrenAirportResponse(
$airport->getTitle(),
$airport->getIata(),
$airport->getCity()->getCountry()->getTitle(),
$city->getTitle(),
$country->getTitle(),
$region->getTitle(),
$subregion->getTitle(),
[$children]
);

$this->assertEquals($airport->getTitle(), $actual->title);
$this->assertEquals($airport->getIata(), $actual->iata);
$this->assertEquals($airport->getCity()->getCountry()->getTitle(), $actual->country);
$this->assertEquals($city->getTitle(), $actual->city);
$this->assertEquals($country->getTitle(), $actual->country);

$this->assertEquals($airport->getTitle(), $actual->children[0]->title);
$this->assertEquals($airport->getIata(), $actual->children[0]->iata);
$this->assertEquals($airport->getCity()->getCountry()->getTitle(), $actual->children[0]->country);
$this->assertEquals($city->getTitle(), $actual->children[0]->city);
$this->assertEquals($country->getTitle(), $actual->children[0]->country);
}
}

0 comments on commit 2fc43a1

Please sign in to comment.