diff --git a/src/Endpoints/DNS.php b/src/Endpoints/DNS.php index c3609e9..a9f7474 100644 --- a/src/Endpoints/DNS.php +++ b/src/Endpoints/DNS.php @@ -56,7 +56,7 @@ class DNS implements API $options['ttl'] = $ttl; } - if (!empty($priority)) { + if (is_numeric($priority)) { $options['priority'] = (int)$priority; } diff --git a/tests/Endpoints/DNSTest.php b/tests/Endpoints/DNSTest.php index 27f6030..2eec553 100644 --- a/tests/Endpoints/DNSTest.php +++ b/tests/Endpoints/DNSTest.php @@ -32,6 +32,57 @@ class DNSTest extends TestCase $dns->addRecord('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com', '127.0.0.1', '120', false); } + public function testAddMXRecordPriority10() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/addRecord.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('post')->willReturn($response); + + $mock->expects($this->once()) + ->method('post') + ->with( + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'), + $this->equalTo([ + 'type' => 'MX', + 'name' => 'example.com', + 'content' => '127.0.0.1', + 'ttl' => 120, + 'proxied' => false, + 'priority' => 10, + ]) + ); + + $dns = new \Cloudflare\API\Endpoints\DNS($mock); + $dns->addRecord('023e105f4ecef8ad9ca31a8372d0c353', 'MX', 'example.com', '127.0.0.1', '120', false, 10); + } + + public function testAddMXRecordPriority0() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/addRecord.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('post')->willReturn($response); + + $mock->expects($this->once()) + ->method('post') + ->with( + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'), + $this->equalTo([ + 'type' => 'MX', + 'name' => 'example.com', + 'content' => '127.0.0.1', + 'ttl' => 120, + 'proxied' => false, + 'priority' => 0, + ]) + ); + + $dns = new \Cloudflare\API\Endpoints\DNS($mock); + $dns->addRecord('023e105f4ecef8ad9ca31a8372d0c353', 'MX', 'example.com', '127.0.0.1', '120', false, 0); + } + + public function testListRecords() { $response = $this->getPsr7JsonResponseForFixture('Endpoints/listRecords.json');