Skip to content

Commit

Permalink
Merge pull request #147 from exonet/tsi/hotfix
Browse files Browse the repository at this point in the history
Prevent notice if no comments are passed
  • Loading branch information
Brianvanwessel authored Oct 24, 2023
2 parents 6d94e60 + 9351e89 commit d896b89
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions tests/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d896b89

Please sign in to comment.