From db62f1db8a44e284ef48a5eb52b6e2299c8599f9 Mon Sep 17 00:00:00 2001 From: Anthony Sterling Date: Mon, 2 Oct 2017 08:48:43 +0100 Subject: [PATCH] Added test coverage for DNS Update I've added a test to cover the updating of a DNS record to help debug Issue #19 --- tests/Endpoints/DNSTest.php | 33 +++++++++++++++++++ tests/Fixtures/Endpoints/updateDNSRecord.json | 24 ++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/Fixtures/Endpoints/updateDNSRecord.json diff --git a/tests/Endpoints/DNSTest.php b/tests/Endpoints/DNSTest.php index 6582ad6..3035b5b 100644 --- a/tests/Endpoints/DNSTest.php +++ b/tests/Endpoints/DNSTest.php @@ -85,4 +85,37 @@ class DNSTest extends TestCase $this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id); } + + public function testUpdateDNSRecord() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateDNSRecord.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('put')->willReturn($response); + + $details = array( + 'type' => 'A', + 'name' => "example.com", + 'content' => "1.2.3.4", + 'ttl' => 120, + 'proxied' => false, + ); + + $mock->expects($this->once()) + ->method('put') + ->with( + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'), + $this->equalTo([]), + $this->equalTo($details) + ); + + $dns = new \Cloudflare\API\Endpoints\DNS($mock); + $result = $dns->updateRecordDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59", $details); + + $this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result->id); + + foreach ($details as $property => $value) { + $this->assertEquals($result->result->{ $property }, $value); + } + } } diff --git a/tests/Fixtures/Endpoints/updateDNSRecord.json b/tests/Fixtures/Endpoints/updateDNSRecord.json new file mode 100644 index 0000000..33253a4 --- /dev/null +++ b/tests/Fixtures/Endpoints/updateDNSRecord.json @@ -0,0 +1,24 @@ +{ + "success": true, + "errors": [ + {} + ], + "messages": [ + {} + ], + "result": { + "id": "372e67954025e0ba6aaa6d586b9e0b59", + "type": "A", + "name": "example.com", + "content": "1.2.3.4", + "proxiable": true, + "proxied": false, + "ttl": 120, + "locked": false, + "zone_id": "023e105f4ecef8ad9ca31a8372d0c353", + "zone_name": "example.com", + "created_on": "2014-01-01T05:20:00.12345Z", + "modified_on": "2014-01-01T05:20:00.12345Z", + "data": {} + } +}