Skip to content

Commit

Permalink
Merge pull request #61 from frankvanhest/performance_improvement_list…
Browse files Browse the repository at this point in the history
…Zones

Added support for /servers/{server_id}/zones query parameter dnssec in PowerDns::listZones
  • Loading branch information
trizz authored Feb 1, 2021
2 parents 9b7cf01 + 279de45 commit f82c712
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/Powerdns.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,19 @@ 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'))
);
}

Expand Down
14 changes: 11 additions & 3 deletions tests/PowerdnsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '',
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f82c712

Please sign in to comment.