diff --git a/src/Helper.php b/src/Helper.php index e1c8ecf..d07740c 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -35,7 +35,8 @@ public static function createResourceRecord( return (new ResourceRecord())->setApiResponse($name); } - ['name' => $name, 'type' => $type, 'ttl' => $ttl, 'content' => $content, 'comments' => $comments] = $name; + $comments = $name['comments'] ?? []; + ['name' => $name, 'type' => $type, 'ttl' => $ttl, 'content' => $content] = $name; } $name = str_replace('@', $zoneName, $name); diff --git a/src/Powerdns.php b/src/Powerdns.php index c186754..1b518ff 100644 --- a/src/Powerdns.php +++ b/src/Powerdns.php @@ -15,7 +15,7 @@ class Powerdns implements PowerdnsInterface /** * The version of this package. This is being used for the user-agent header. */ - public const CLIENT_VERSION = 'v4.5.0'; + public const CLIENT_VERSION = 'v4.5.1'; /** * @var Powerdns The client instance. diff --git a/tests/HelperTest.php b/tests/HelperTest.php index fdcbe63..b31ca12 100644 --- a/tests/HelperTest.php +++ b/tests/HelperTest.php @@ -59,6 +59,27 @@ public function testWithArray(): void self::assertSame('rooti', $result->getComments()[1]->getAccount()); } + public function testWithArrayWithoutOptionalFields(): void + { + $result = Helper::createResourceRecord( + 'unit.test.', + [ + 'name' => '@', + 'type' => RecordType::A, + 'content' => ['127.0.0.1', '127.0.0.2'], + 'ttl' => 1337, + ] + ); + + self::assertSame('unit.test.', $result->getName()); + self::assertSame('A', $result->getType()); + self::assertSame(1337, $result->getTtl()); + self::assertCount(2, $result->getRecords()); + self::assertSame('127.0.0.1', $result->getRecords()[0]->getContent()); + self::assertSame('127.0.0.2', $result->getRecords()[1]->getContent()); + self::assertEmpty($result->getComments()); + } + public function testWithApiResponse(): void { foreach (ZoneTest::API_RESPONSE['rrsets'] as $rrset) {