From 5500804299fa29e8120b6c6e9ad3ec03ad4a2a19 Mon Sep 17 00:00:00 2001 From: Konrad Date: Thu, 25 Mar 2021 15:24:12 +0100 Subject: [PATCH] Add totalItemsCount property to FindPointsResponse --- src/Response/FindPointsResponse.php | 14 ++++++++++++-- tests/Integration/Command/FindPointsTest.php | 1 + .../Integration/Command/data/exampleResponse.json | 8 ++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Response/FindPointsResponse.php b/src/Response/FindPointsResponse.php index 1981a5a..d20e2ca 100644 --- a/src/Response/FindPointsResponse.php +++ b/src/Response/FindPointsResponse.php @@ -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 @@ -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( @@ -42,7 +51,8 @@ public static function fromArray(array $arrayResponse): self $arrayResponse['items'] ) ), - $arrayResponse['total_pages'] + $arrayResponse['total_pages'], + $arrayResponse['count'] ); } } diff --git a/tests/Integration/Command/FindPointsTest.php b/tests/Integration/Command/FindPointsTest.php index 96ff9f1..7ccf1b6 100644 --- a/tests/Integration/Command/FindPointsTest.php +++ b/tests/Integration/Command/FindPointsTest.php @@ -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); } diff --git a/tests/Integration/Command/data/exampleResponse.json b/tests/Integration/Command/data/exampleResponse.json index d174188..4f3bb30 100644 --- a/tests/Integration/Command/data/exampleResponse.json +++ b/tests/Integration/Command/data/exampleResponse.json @@ -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", @@ -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 } } \ No newline at end of file