From 251ab5247de5935c6d7c4da957d7553b861468ea Mon Sep 17 00:00:00 2001 From: Paul Jones Date: Sun, 21 Jun 2020 07:42:38 +0000 Subject: [PATCH] Fix for MX with priority 0 Author: Paul Jones Date: Sun Jun 21 07:42:38 2020 +0000 --- src/Endpoints/DNS.php | 2 +- tests/Endpoints/DNSTest.php | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) 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');