From b04abe73bcfb3f8b60b5e02f628759468fa5326e Mon Sep 17 00:00:00 2001 From: Kyle Yee Date: Thu, 6 Jun 2019 15:00:57 +0800 Subject: [PATCH] Feature: add pause --- src/Endpoints/Zones.php | 15 +++++++++++++++ tests/Endpoints/ZonesTest.php | 23 +++++++++++++++++++++++ tests/Fixtures/Endpoints/pauseTest.json | 8 ++++++++ 3 files changed, 46 insertions(+) create mode 100644 tests/Fixtures/Endpoints/pauseTest.json diff --git a/src/Endpoints/Zones.php b/src/Endpoints/Zones.php index 8595cb6..22db2ee 100644 --- a/src/Endpoints/Zones.php +++ b/src/Endpoints/Zones.php @@ -58,6 +58,21 @@ class Zones implements API return false; } + public function pause(string $zoneID, bool $paused = true): bool + { + $options = [ + 'paused' => $paused, + ]; + $user = $this->adapter->patch('zones/' . $zoneID, $options); + $this->body = json_decode($user->getBody()); + + if (isset($this->body->result->id)) { + return true; + } + + return false; + } + public function listZones( string $name = '', string $status = '', diff --git a/tests/Endpoints/ZonesTest.php b/tests/Endpoints/ZonesTest.php index 0bda651..a95f690 100644 --- a/tests/Endpoints/ZonesTest.php +++ b/tests/Endpoints/ZonesTest.php @@ -49,6 +49,29 @@ class ZonesTest extends TestCase $this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id); } + public function testPauseTest() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/pauseTest.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('patch')->willReturn($response); + + $mock->expects($this->once()) + ->method('patch') + ->with( + $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41'), + $this->equalTo([ + 'pause' => true, + ]) + ); + + $zones = new \Cloudflare\API\Endpoints\Zones($mock); + $result = $zones->pause('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true); + + $this->assertTrue($result); + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id); + } + public function testActivationTest() { $response = $this->getPsr7JsonResponseForFixture('Endpoints/activationTest.json'); diff --git a/tests/Fixtures/Endpoints/pauseTest.json b/tests/Fixtures/Endpoints/pauseTest.json new file mode 100644 index 0000000..bedd2f5 --- /dev/null +++ b/tests/Fixtures/Endpoints/pauseTest.json @@ -0,0 +1,8 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "023e105f4ecef8ad9ca31a8372d0c353" + } +}