Skip to content

Commit

Permalink
TRE-7: Index to List
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeBocock committed Nov 11, 2023
1 parent 6222cdf commit 2c5a03f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/Client/AgencyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace JoeBocock\LaunchLibrary\Client;

use JoeBocock\LaunchLibrary\Collection\AgencyIndexCollection;
use JoeBocock\LaunchLibrary\Collection\AgencyListCollection;
use JoeBocock\LaunchLibrary\Request\Agency\ListAgency;

class AgencyClient extends SubClient
Expand Down Expand Up @@ -80,7 +80,7 @@ public function list(
int $totalLaunchCountGTE = null,
int $totalLaunchCountLT = null,
int $totalLaunchCountLTE = null,
): AgencyIndexCollection {
): AgencyListCollection {
$request = new ListAgency(
$this->client->url,
$this->client->version
Expand Down Expand Up @@ -354,7 +354,7 @@ public function list(
$request->setTotalLaunchCountLTE($totalLaunchCountLTE);
}

return new AgencyIndexCollection(
return new AgencyListCollection(
$this->client,
$request,
);
Expand Down
18 changes: 0 additions & 18 deletions src/Collection/AgencyIndexCollection.php

This file was deleted.

18 changes: 18 additions & 0 deletions src/Collection/AgencyListCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace JoeBocock\LaunchLibrary\Collection;

use JoeBocock\LaunchLibrary\Entity\AgencyList;

/**
* @extends Collection<AgencyList>
*/
class AgencyListCollection extends Collection
{
public function current(): AgencyList
{
return parent::current();
}
}
2 changes: 1 addition & 1 deletion src/Entity/AgencyIndex.php → src/Entity/AgencyList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace JoeBocock\LaunchLibrary\Entity;

class AgencyIndex extends Entity
class AgencyList extends Entity
{
public function __construct(
public int $id,
Expand Down
6 changes: 3 additions & 3 deletions src/Request/Agency/ListAgency.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace JoeBocock\LaunchLibrary\Request\Agency;

use JoeBocock\LaunchLibrary\Entity\AgencyIndex;
use JoeBocock\LaunchLibrary\Entity\AgencyList;
use JoeBocock\LaunchLibrary\Request\PaginatedRequest;

class ListAgency extends PaginatedRequest
Expand Down Expand Up @@ -180,7 +180,7 @@ public function getQueryParameters(): array
* }[]
* } $body
*
* @return array<AgencyIndex>
* @return array<AgencyList>
*/
public function hydrate(array $body, array $headers = null): array
{
Expand All @@ -190,7 +190,7 @@ public function hydrate(array $body, array $headers = null): array

if (isset($body['results'])) {
foreach ($body['results'] as $result) {
$results[] = new AgencyIndex(
$results[] = new AgencyList(
$result['id'],
$result['url'],
$result['name'],
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Client/AgencyClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

use JoeBocock\LaunchLibrary\Client;
use JoeBocock\LaunchLibrary\Collection\AgencyIndexCollection;
use JoeBocock\LaunchLibrary\Collection\AgencyListCollection;

it('has values that can be set', function () {
$client = new Client(
Expand Down Expand Up @@ -78,7 +78,7 @@
totalLaunchCountGTE: 1,
totalLaunchCountLT: 1,
totalLaunchCountLTE: 1,
))->toBeInstanceOf(AgencyIndexCollection::class);
))->toBeInstanceOf(AgencyListCollection::class);

$collection->valid();

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Collection/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use JoeBocock\LaunchLibrary\Client;
use JoeBocock\LaunchLibrary\Collection\AgencyIndexCollection;
use JoeBocock\LaunchLibrary\Collection\AgencyListCollection;
use JoeBocock\LaunchLibrary\Collection\Collection;
use JoeBocock\LaunchLibrary\Collection\Config\AgencyTypeCollection;
use JoeBocock\LaunchLibrary\Request\Agency\ListAgency;
Expand Down Expand Up @@ -107,7 +107,7 @@ public function hydrate(array $body, array $headers = null): array
client: new GuzzleHttpClient(['handler' => HandlerStack::create($mock)])
);

expect($collection = $client->agency->list())->toBeInstanceOf(AgencyIndexCollection::class);
expect($collection = $client->agency->list())->toBeInstanceOf(AgencyListCollection::class);

$collection->valid();
$collection->next();
Expand All @@ -125,7 +125,7 @@ public function hydrate(array $body, array $headers = null): array
client: new GuzzleHttpClient(['handler' => HandlerStack::create($mock)])
);

expect($collection = $client->agency->list())->toBeInstanceOf(AgencyIndexCollection::class);
expect($collection = $client->agency->list())->toBeInstanceOf(AgencyListCollection::class);
expect($collection->valid())->toBe(false);
});

Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

use JoeBocock\LaunchLibrary\Client;
use JoeBocock\LaunchLibrary\Collection\AgencyIndexCollection;
use JoeBocock\LaunchLibrary\Collection\AgencyListCollection;
use JoeBocock\LaunchLibrary\Collection\Config\AgencyTypeCollection;
use JoeBocock\LaunchLibrary\Entity\ApiThrottle;
use JoeBocock\LaunchLibrary\Entity\Config\AgencyType;
Expand All @@ -16,7 +16,7 @@
expect($callback($client))->toBeInstanceOf($class);
})->with([
['tests/Fixture/ApiThrottle/Get.json', fn (Client $client) => $client->apiThrottle->get(), ApiThrottle::class],
['tests/Fixture/Agency/Index.json', fn (Client $client) => $client->agency->list(), AgencyIndexCollection::class],
['tests/Fixture/Agency/Index.json', fn (Client $client) => $client->agency->list(), AgencyListCollection::class],
['tests/Fixture/Config/AgencyType/Index.json', fn (Client $client) => $client->config->agencyType->list(), AgencyTypeCollection::class],
['tests/Fixture/Config/AgencyType/Get.json', fn (Client $client) => $client->config->agencyType->get(1), AgencyType::class],
]);
Expand Down

0 comments on commit 2c5a03f

Please sign in to comment.