From b4fbaecfeebe4f3d79976914da962a1e55b44949 Mon Sep 17 00:00:00 2001 From: Frank van Hest Date: Fri, 29 Jan 2021 21:23:10 +0100 Subject: [PATCH 1/3] Added support for /servers/{server_id}/zones query parameter dnssec --- src/Powerdns.php | 6 ++++-- tests/PowerdnsTest.php | 14 +++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Powerdns.php b/src/Powerdns.php index 335c9d0..16abb62 100644 --- a/src/Powerdns.php +++ b/src/Powerdns.php @@ -194,15 +194,17 @@ public function deleteZone(string $canonicalDomain): bool /** * Retrieve all zones. * + * @param bool $omitDnssecAndEditedSerialFields When set to true dnssec and edited_serial are omitted * @return Zone[] Array containing the zones + * @link https://doc.powerdns.com/authoritative/http-api/zone.html#get--servers-server_id-zones */ - public function listZones(): array + public function listZones(bool $omitDnssecAndEditedSerialFields = false): array { return array_map( function (array $args) { return new Zone($this->connector, $args['id']); }, - $this->connector->get('zones') + $this->connector->get('zones?dnssec=' . ($omitDnssecAndEditedSerialFields ? 'true': 'false')) ); } diff --git a/tests/PowerdnsTest.php b/tests/PowerdnsTest.php index 75913ba..0dded71 100644 --- a/tests/PowerdnsTest.php +++ b/tests/PowerdnsTest.php @@ -90,10 +90,18 @@ public function testZone(): void $this->assertTrue($powerDns->deleteZone('test.nl.')); } - public function testListZones(): void + public function listZonesArgumentDataProvider(): array + { + return [['true', true], ['false', false]]; + } + + /** + * @dataProvider listZonesArgumentDataProvider + */ + public function testListZones(string $dnssecArgument, bool $listZonesArgument): void { $connector = Mockery::mock(Connector::class); - $connector->shouldReceive('get')->withArgs(['zones'])->once()->andReturn( + $connector->shouldReceive('get')->withArgs(['zones?dnssec=' . $dnssecArgument])->once()->andReturn( [ [ 'account' => '', @@ -124,7 +132,7 @@ public function testListZones(): void $powerDns = new Powerdns(null, null, null, null, $connector); - $response = $powerDns->listZones(); + $response = $powerDns->listZones($listZonesArgument); $this->assertIsArray($response); $this->assertCount(2, $response); foreach ($response as $zone) { From 7fa7b3bcefbb152525d0f4960814a3ba9bb6e2d4 Mon Sep 17 00:00:00 2001 From: Frank van Hest Date: Fri, 29 Jan 2021 21:33:28 +0100 Subject: [PATCH 2/3] Changes after running style/ci --- src/Powerdns.php | 4 +++- tests/PowerdnsTest.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Powerdns.php b/src/Powerdns.php index 16abb62..a3b4198 100644 --- a/src/Powerdns.php +++ b/src/Powerdns.php @@ -195,7 +195,9 @@ public function deleteZone(string $canonicalDomain): bool * Retrieve all zones. * * @param bool $omitDnssecAndEditedSerialFields When set to true dnssec and edited_serial are omitted + * * @return Zone[] Array containing the zones + * * @link https://doc.powerdns.com/authoritative/http-api/zone.html#get--servers-server_id-zones */ public function listZones(bool $omitDnssecAndEditedSerialFields = false): array @@ -204,7 +206,7 @@ public function listZones(bool $omitDnssecAndEditedSerialFields = false): array function (array $args) { return new Zone($this->connector, $args['id']); }, - $this->connector->get('zones?dnssec=' . ($omitDnssecAndEditedSerialFields ? 'true': 'false')) + $this->connector->get('zones?dnssec='.($omitDnssecAndEditedSerialFields ? 'true': 'false')) ); } diff --git a/tests/PowerdnsTest.php b/tests/PowerdnsTest.php index 0dded71..f895534 100644 --- a/tests/PowerdnsTest.php +++ b/tests/PowerdnsTest.php @@ -101,7 +101,7 @@ public function listZonesArgumentDataProvider(): array public function testListZones(string $dnssecArgument, bool $listZonesArgument): void { $connector = Mockery::mock(Connector::class); - $connector->shouldReceive('get')->withArgs(['zones?dnssec=' . $dnssecArgument])->once()->andReturn( + $connector->shouldReceive('get')->withArgs(['zones?dnssec='.$dnssecArgument])->once()->andReturn( [ [ 'account' => '', From 279de458b8ec95538568ade1e53617587ad4c351 Mon Sep 17 00:00:00 2001 From: Frank van Hest Date: Fri, 29 Jan 2021 21:34:49 +0100 Subject: [PATCH 3/3] Changes after running style/ci --- src/Powerdns.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Powerdns.php b/src/Powerdns.php index a3b4198..9fe0f60 100644 --- a/src/Powerdns.php +++ b/src/Powerdns.php @@ -206,7 +206,7 @@ public function listZones(bool $omitDnssecAndEditedSerialFields = false): array function (array $args) { return new Zone($this->connector, $args['id']); }, - $this->connector->get('zones?dnssec='.($omitDnssecAndEditedSerialFields ? 'true': 'false')) + $this->connector->get('zones?dnssec='.($omitDnssecAndEditedSerialFields ? 'true' : 'false')) ); }