Skip to content

Commit

Permalink
Merge pull request #5 from answear/feature/add-total-items-count-in-f…
Browse files Browse the repository at this point in the history
…ind-points-response

Add totalItemsCount property to FindPointsResponse
  • Loading branch information
konradkozaczenko committed Mar 25, 2021
2 parents fcacf45 + 5500804 commit 20149a3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/Response/FindPointsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class FindPointsResponse
{
public ItemCollection $items;
public int $totalPages;
public int $totalItemsCount;

public function __construct(ItemCollection $offices, int $totalPages)
public function __construct(ItemCollection $offices, int $totalPages, int $totalItemsCount)
{
$this->items = $offices;
$this->totalPages = $totalPages;
$this->totalItemsCount = $totalItemsCount;
}

public function getItems(): ItemCollection
Expand All @@ -29,11 +31,18 @@ public function getTotalPages(): int
return $this->totalPages;
}

public function getTotalItemsCount(): int
{
return $this->totalItemsCount;
}

public static function fromArray(array $arrayResponse): self
{
Assert::keyExists($arrayResponse, 'items');
Assert::keyExists($arrayResponse, 'total_pages');
Assert::keyExists($arrayResponse, 'count');
Assert::integer($arrayResponse['total_pages']);
Assert::integer($arrayResponse['count']);

return new self(
new ItemCollection(
Expand All @@ -42,7 +51,8 @@ public static function fromArray(array $arrayResponse): self
$arrayResponse['items']
)
),
$arrayResponse['total_pages']
$arrayResponse['total_pages'],
$arrayResponse['count']
);
}
}
1 change: 1 addition & 0 deletions tests/Integration/Command/FindPointsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function successfulFindPoints(): void
$response = $command->findPoints(new FindPointsRequest());

$this->assertCount(1, $response->getItems());
$this->assertSame(1, $response->getTotalItemsCount());
$this->assertPoint($response);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Integration/Command/data/exampleResponse.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"href": "https://api-pl-points.easypack24.net/v1/points",
"count": 13510,
"count": 1,
"page": 1,
"per_page": 25,
"total_pages": 541,
"total_pages": 1,
"items": [
{
"href": "https://api-pl-points.easypack24.net/v1/points/ADA01M",
Expand Down Expand Up @@ -60,9 +60,9 @@
],
"meta": {
"href": "https://api-pl-points.easypack24.net/v1/points",
"count": 13510,
"count": 1,
"page": 1,
"per_page": 25,
"total_pages": 541
"total_pages": 1
}
}

0 comments on commit 20149a3

Please sign in to comment.