From 90028dc6a1438cebd114bd910b749c7cb74b30e5 Mon Sep 17 00:00:00 2001 From: Joseph Shanak Date: Wed, 7 Oct 2020 14:45:28 -0500 Subject: [PATCH] Add mapping for assignable_to_pools property of ips index response --- src/Model/Ip/IndexResponse.php | 14 ++++++++++++++ tests/Api/Ip.php | 6 ++++++ tests/Model/Ip/IndexResponseTest.php | 17 +++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/Model/Ip/IndexResponse.php b/src/Model/Ip/IndexResponse.php index 3d461bd..6d8af51 100644 --- a/src/Model/Ip/IndexResponse.php +++ b/src/Model/Ip/IndexResponse.php @@ -28,6 +28,11 @@ final class IndexResponse implements ApiResponse */ private $totalCount; + /** + * @var string[] + */ + private $assignableToPools; + private function __construct() { } @@ -37,6 +42,7 @@ final class IndexResponse implements ApiResponse $model = new self(); $model->items = $data['items']; $model->totalCount = $data['total_count'] ?? 0; + $model->assignableToPools = $data['assignable_to_pools']; return $model; } @@ -49,6 +55,14 @@ final class IndexResponse implements ApiResponse return $this->items; } + /** + * @return string[] + */ + public function getAssignableToPools(): array + { + return $this->assignableToPools; + } + public function getTotalCount(): int { return $this->totalCount; diff --git a/tests/Api/Ip.php b/tests/Api/Ip.php index bca3166..57c8cec 100644 --- a/tests/Api/Ip.php +++ b/tests/Api/Ip.php @@ -28,6 +28,7 @@ class IpTest extends TestCase $this->setRequestUri('/v3/ips'); $this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' { + "assignable_to_pools": ["192.168.0.1"], "items": ["192.161.0.1", "192.168.0.2"], "total_count": 2 } @@ -41,6 +42,7 @@ JSON $this->assertEquals(2, $response->getTotalCount()); $this->assertEquals('192.161.0.1', $response->getItems()[0]); $this->assertEquals('192.168.0.2', $response->getItems()[1]); + $this->assertEquals('192.168.0.1', $response->getAssignableToPools()[0]); } public function testIndexOnlyDedicated() @@ -49,6 +51,7 @@ JSON $this->setRequestUri('/v3/ips?dedicated=1'); $this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' { + "assignable_to_pools": ["192.168.0.1"], "items": ["192.161.0.1"], "total_count": 1 } @@ -61,6 +64,7 @@ JSON $this->assertInstanceOf(IndexResponse::class, $response); $this->assertEquals(1, $response->getTotalCount()); $this->assertEquals('192.161.0.1', $response->getItems()[0]); + $this->assertEquals('192.168.0.1', $response->getAssignableToPools()[0]); } public function testIndexOnlyShared() @@ -69,6 +73,7 @@ JSON $this->setRequestUri('/v3/ips?dedicated=0'); $this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' { + "assignable_to_pools": ["192.168.0.1"], "items": ["192.168.0.2"], "total_count": 1 } @@ -81,5 +86,6 @@ JSON $this->assertInstanceOf(IndexResponse::class, $response); $this->assertEquals(1, $response->getTotalCount()); $this->assertEquals('192.168.0.2', $response->getItems()[0]); + $this->assertEquals('192.168.0.1', $response->getAssignableToPools()[0]); } } diff --git a/tests/Model/Ip/IndexResponseTest.php b/tests/Model/Ip/IndexResponseTest.php index d9893be..90791cf 100644 --- a/tests/Model/Ip/IndexResponseTest.php +++ b/tests/Model/Ip/IndexResponseTest.php @@ -21,6 +21,7 @@ class IndexResponseTest extends BaseModelTest $json = <<<'JSON' { + "assignable_to_pools": ["192.161.0.1"], "items": ["192.161.0.1", "192.168.0.2"], "total_count": 2 } @@ -31,4 +32,20 @@ JSON; $this->assertCount(2, $items); $this->assertEquals('192.161.0.1', $items[0]); } + + public function testCreateWithAssignableToPools() + { + $json = +<<<'JSON' +{ + "assignable_to_pools": ["192.161.0.1"], + "items": ["192.161.0.1", "192.168.0.2"], + "total_count": 2 +} +JSON; + $model = IndexResponse::create(json_decode($json, true)); + $assignableToPools = $model->getAssignableToPools(); + $this->assertCount(1, $assignableToPools); + $this->assertEquals('192.161.0.1', $assignableToPools[0]); + } }