From 59f6d72d0a161e6f264f508962067bec611c5a1c Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 09:34:17 -0400 Subject: [PATCH 01/14] Create trait for accessing body property --- src/Traits/BodyAccessorTrait.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/Traits/BodyAccessorTrait.php diff --git a/src/Traits/BodyAccessorTrait.php b/src/Traits/BodyAccessorTrait.php new file mode 100644 index 00000000..92e599f8 --- /dev/null +++ b/src/Traits/BodyAccessorTrait.php @@ -0,0 +1,12 @@ +body; + } +} From 2dd4d8f883df5c146594927d97e0343c25c1ee42 Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 09:45:10 -0400 Subject: [PATCH 02/14] Set body property in cachePurge method of Zones --- src/Endpoints/Zones.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Endpoints/Zones.php b/src/Endpoints/Zones.php index f0e77779..e0ae234b 100644 --- a/src/Endpoints/Zones.php +++ b/src/Endpoints/Zones.php @@ -9,9 +9,12 @@ namespace Cloudflare\API\Endpoints; use Cloudflare\API\Adapter\Adapter; +use Cloudflare\API\Traits\BodyAccessorTrait; class Zones implements API { + use BodyAccessorTrait; + private $adapter; public function __construct(Adapter $adapter) @@ -172,16 +175,16 @@ public function cachePurge(string $zoneID, array $files = null, array $tags = nu if (!is_null($tags)) { $options['tags'] = $tags; } - + if (!is_null($hosts)) { $options['hosts'] = $hosts; } $user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', $options); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } From 4c288c38d7fbc8a564367ab0ff80aa4d00f62c1d Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 09:49:01 -0400 Subject: [PATCH 03/14] Add cachePurge fixture --- tests/Fixtures/Endpoints/cachePurge.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/Fixtures/Endpoints/cachePurge.json diff --git a/tests/Fixtures/Endpoints/cachePurge.json b/tests/Fixtures/Endpoints/cachePurge.json new file mode 100644 index 00000000..bedd2f5c --- /dev/null +++ b/tests/Fixtures/Endpoints/cachePurge.json @@ -0,0 +1,8 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "023e105f4ecef8ad9ca31a8372d0c353" + } +} From a39d6fb17016cf18a930c4956a92b1d8edaeee60 Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 09:53:51 -0400 Subject: [PATCH 04/14] Run php-cs-fixer --- src/Traits/BodyAccessorTrait.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Traits/BodyAccessorTrait.php b/src/Traits/BodyAccessorTrait.php index 92e599f8..add13ad3 100644 --- a/src/Traits/BodyAccessorTrait.php +++ b/src/Traits/BodyAccessorTrait.php @@ -2,7 +2,8 @@ namespace Cloudflare\API\Traits; -trait BodyAccessorTrait { +trait BodyAccessorTrait +{ private $body; public function getBody() From 45df26fec3110a73f844d10504ad8a92566e32ef Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 09:54:38 -0400 Subject: [PATCH 05/14] Add a test for cachePurge --- tests/Endpoints/ZonesTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Endpoints/ZonesTest.php b/tests/Endpoints/ZonesTest.php index 5221eb78..2d17e777 100644 --- a/tests/Endpoints/ZonesTest.php +++ b/tests/Endpoints/ZonesTest.php @@ -210,4 +210,29 @@ public function testCachePurgeHost() $this->assertTrue($result); } + + public function testCachePurge() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurge.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('delete')->willReturn($response); + + $mock->expects($this->once()) + ->method('delete') + ->with( + $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'), + $this->equalTo(['files' => [ + 'https://example.com/file.jpg', + ] + ]) + ); + + $zones = new \Cloudflare\API\Endpoints\Zones($mock); + $result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [ + 'https://example.com/file.jpg', + ]); + + $this->assertTrue($result); + } } From e28fed86d1eb0a2cf765d15e5507049fd4ac97d0 Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 10:02:33 -0400 Subject: [PATCH 06/14] Update ID in cachePurge fixture --- tests/Fixtures/Endpoints/cachePurge.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Fixtures/Endpoints/cachePurge.json b/tests/Fixtures/Endpoints/cachePurge.json index bedd2f5c..06df6ecd 100644 --- a/tests/Fixtures/Endpoints/cachePurge.json +++ b/tests/Fixtures/Endpoints/cachePurge.json @@ -3,6 +3,6 @@ "errors": [], "messages": [], "result": { - "id": "023e105f4ecef8ad9ca31a8372d0c353" + "id": "c2547eb745079dac9320b638f5e225cf483cc5cfdda41" } } From 943b0d85d4263b2701e08ebb33c5b70807dd3075 Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 10:10:00 -0400 Subject: [PATCH 07/14] Add test using getBody trait method --- tests/Endpoints/ZonesTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Endpoints/ZonesTest.php b/tests/Endpoints/ZonesTest.php index 2d17e777..acd0ab50 100644 --- a/tests/Endpoints/ZonesTest.php +++ b/tests/Endpoints/ZonesTest.php @@ -234,5 +234,6 @@ public function testCachePurge() ]); $this->assertTrue($result); + $this->assertEquals('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', $zones->getBody()->result->id); } } From 5bea924c76a1ae48c90dd806773b6b6a48593b7d Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 10:12:51 -0400 Subject: [PATCH 08/14] Set body property in other Zones methods --- src/Endpoints/Zones.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Endpoints/Zones.php b/src/Endpoints/Zones.php index e0ae234b..8595cb6f 100644 --- a/src/Endpoints/Zones.php +++ b/src/Endpoints/Zones.php @@ -42,16 +42,16 @@ public function addZone(string $name, bool $jumpStart = false, string $organizat } $user = $this->adapter->post('zones', $options); - $body = json_decode($user->getBody()); - return $body->result; + $this->body = json_decode($user->getBody()); + return $this->body->result; } public function activationCheck(string $zoneID): bool { $user = $this->adapter->put('zones/' . $zoneID . '/activation_check'); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } @@ -90,9 +90,9 @@ public function listZones( } $user = $this->adapter->get('zones', $query); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return (object)['result' => $body->result, 'result_info' => $body->result_info]; + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; } public function getZoneID(string $name = ''): string @@ -119,7 +119,9 @@ public function getAnalyticsDashboard(string $zoneID, string $since = '-10080', { $response = $this->adapter->get('zones/' . $zoneID . '/analytics/dashboard', ['since' => $since, 'until' => $until, 'continuous' => var_export($continuous, true)]); - return json_decode($response->getBody())->result; + $this->body = $response->getBody(); + + return json_decode($this->body)->result; } /** @@ -133,9 +135,9 @@ public function changeDevelopmentMode(string $zoneID, bool $enable = false): boo { $response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', ['value' => $enable ? 'on' : 'off']); - $body = json_decode($response->getBody()); + $this->body = json_decode($response->getBody()); - if ($body->success) { + if ($this->body->success) { return true; } @@ -152,9 +154,9 @@ public function cachePurgeEverything(string $zoneID): bool { $user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', ['purge_everything' => true]); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } From 0492e9b17bed85bebbec37fb04af8cb4383dcc90 Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 10:16:17 -0400 Subject: [PATCH 09/14] Fix id --- tests/Fixtures/Endpoints/cachePurge.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Fixtures/Endpoints/cachePurge.json b/tests/Fixtures/Endpoints/cachePurge.json index 06df6ecd..bedd2f5c 100644 --- a/tests/Fixtures/Endpoints/cachePurge.json +++ b/tests/Fixtures/Endpoints/cachePurge.json @@ -3,6 +3,6 @@ "errors": [], "messages": [], "result": { - "id": "c2547eb745079dac9320b638f5e225cf483cc5cfdda41" + "id": "023e105f4ecef8ad9ca31a8372d0c353" } } From c60064e5425b672c25e8cab1bbd8dee8b553e9ea Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 10:18:57 -0400 Subject: [PATCH 10/14] Add more assertions for BodyAccessorTrait --- tests/Endpoints/ZonesTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/Endpoints/ZonesTest.php b/tests/Endpoints/ZonesTest.php index acd0ab50..0bda6514 100644 --- a/tests/Endpoints/ZonesTest.php +++ b/tests/Endpoints/ZonesTest.php @@ -46,6 +46,7 @@ public function testAddZone() $zones = new \Cloudflare\API\Endpoints\Zones($mock); $zones->addZone('example.com', true, '01a7362d577a6c3019a474fd6f485823'); + $this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id); } public function testActivationTest() @@ -65,6 +66,7 @@ public function testActivationTest() $result = $zones->activationCheck('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); $this->assertTrue($result); + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id); } public function testListZones() @@ -97,6 +99,7 @@ public function testListZones() $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result[0]->id); } public function testGetZoneID() @@ -122,6 +125,7 @@ public function testGetZoneID() $result = $zones->getZoneID('example.com'); $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result); + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result[0]->id); } public function testGetAnalyticsDashboard() @@ -163,6 +167,7 @@ public function testChangeDevelopmentMode() $result = $zones->changeDevelopmentMode('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true); $this->assertTrue($result); + $this->assertEquals('development_mode', $zones->getBody()->result->id); } public function testCachePurgeEverything() @@ -183,6 +188,7 @@ public function testCachePurgeEverything() $result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); $this->assertTrue($result); + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id); } public function testCachePurgeHost() @@ -209,6 +215,7 @@ public function testCachePurgeHost() $result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [], [], ['dash.cloudflare.com']); $this->assertTrue($result); + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id); } public function testCachePurge() @@ -234,6 +241,6 @@ public function testCachePurge() ]); $this->assertTrue($result); - $this->assertEquals('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', $zones->getBody()->result->id); + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id); } } From d871bdd00701286484ac117953ae60b1a78ad405 Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 10:21:38 -0400 Subject: [PATCH 11/14] Add BodyAccessorTrait to AccessRules --- src/Endpoints/AccessRules.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Endpoints/AccessRules.php b/src/Endpoints/AccessRules.php index b2d7584d..07bc31c2 100644 --- a/src/Endpoints/AccessRules.php +++ b/src/Endpoints/AccessRules.php @@ -4,9 +4,12 @@ use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Configurations\Configurations; +use Cloudflare\API\Traits\BodyAccessorTrait; class AccessRules implements API { + use BodyAccessorTrait; + private $adapter; public function __construct(Adapter $adapter) @@ -78,9 +81,9 @@ public function listRules( } $data = $this->adapter->get('zones/' . $zoneID . '/firewall/access_rules/rules', $query); - $body = json_decode($data->getBody()); + $this->body = json_decode($data->getBody()); - return (object)['result' => $body->result, 'result_info' => $body->result_info]; + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; } public function createRule( @@ -100,9 +103,9 @@ public function createRule( $query = $this->adapter->post('zones/' . $zoneID . '/firewall/access_rules/rules', $options); - $body = json_decode($query->getBody()); + $this->body = json_decode($query->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } @@ -125,9 +128,9 @@ public function updateRule( $query = $this->adapter->patch('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options); - $body = json_decode($query->getBody()); + $this->body = json_decode($query->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } @@ -142,9 +145,9 @@ public function deleteRule(string $zoneID, string $ruleID, string $cascade = 'no $data = $this->adapter->delete('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options); - $body = json_decode($data->getBody()); + $this->body = json_decode($data->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } From 2639331c2b355b6512a3329b7accac020d41c8ac Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 10:48:25 -0400 Subject: [PATCH 12/14] Add BodyAccessorTrait to most classes --- src/Endpoints/CustomHostnames.php | 23 ++++++++++++--------- src/Endpoints/DNS.php | 22 +++++++++++--------- src/Endpoints/IPs.php | 7 +++++-- src/Endpoints/PageRules.php | 23 ++++++++++++--------- src/Endpoints/Railgun.php | 27 ++++++++++++++----------- src/Endpoints/UARules.php | 23 ++++++++++++--------- tests/Endpoints/AccessRulesTest.php | 4 ++++ tests/Endpoints/CustomHostnamesTest.php | 5 +++++ tests/Endpoints/DNSTest.php | 3 +++ tests/Endpoints/IPsTest.php | 6 ++++-- tests/Endpoints/PageRulesTest.php | 5 +++++ tests/Endpoints/RailgunTest.php | 6 ++++++ 12 files changed, 99 insertions(+), 55 deletions(-) diff --git a/src/Endpoints/CustomHostnames.php b/src/Endpoints/CustomHostnames.php index 4b37d1ef..4af5c9ee 100644 --- a/src/Endpoints/CustomHostnames.php +++ b/src/Endpoints/CustomHostnames.php @@ -9,9 +9,12 @@ namespace Cloudflare\API\Endpoints; use Cloudflare\API\Adapter\Adapter; +use Cloudflare\API\Traits\BodyAccessorTrait; class CustomHostnames implements API { + use BodyAccessorTrait; + private $adapter; public function __construct(Adapter $adapter) @@ -40,8 +43,8 @@ public function addHostname(string $zoneID, string $hostname, string $sslMethod ]; $zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', $options); - $body = json_decode($zone->getBody()); - return $body->result; + $this->body = json_decode($zone->getBody()); + return $this->body->result; } /** @@ -88,9 +91,9 @@ public function listHostnames( } $zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames', $query); - $body = json_decode($zone->getBody()); + $this->body = json_decode($zone->getBody()); - return (object)['result' => $body->result, 'result_info' => $body->result_info]; + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; } /** @@ -101,9 +104,9 @@ public function listHostnames( public function getHostname(string $zoneID, string $hostnameID) { $zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID); - $body = json_decode($zone->getBody()); + $this->body = json_decode($zone->getBody()); - return $body->result; + return $this->body->result; } /** @@ -132,8 +135,8 @@ public function updateHostname(string $zoneID, string $hostnameID, string $sslMe ]; $zone = $this->adapter->patch('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID, $options); - $body = json_decode($zone->getBody()); - return $body->result; + $this->body = json_decode($zone->getBody()); + return $this->body->result; } /** @@ -144,7 +147,7 @@ public function updateHostname(string $zoneID, string $hostnameID, string $sslMe public function deleteHostname(string $zoneID, string $hostnameID): \stdClass { $zone = $this->adapter->delete('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID); - $body = json_decode($zone->getBody()); - return $body; + $this->body = json_decode($zone->getBody()); + return $this->body; } } diff --git a/src/Endpoints/DNS.php b/src/Endpoints/DNS.php index dc575660..bf455bdf 100644 --- a/src/Endpoints/DNS.php +++ b/src/Endpoints/DNS.php @@ -9,9 +9,12 @@ namespace Cloudflare\API\Endpoints; use Cloudflare\API\Adapter\Adapter; +use Cloudflare\API\Traits\BodyAccessorTrait; class DNS implements API { + use BodyAccessorTrait; + private $adapter; public function __construct(Adapter $adapter) @@ -57,9 +60,9 @@ public function addRecord( $user = $this->adapter->post('zones/' . $zoneID . '/dns_records', $options); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } @@ -104,31 +107,32 @@ public function listRecords( } $user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return (object)['result' => $body->result, 'result_info' => $body->result_info]; + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; } public function getRecordDetails(string $zoneID, string $recordID): \stdClass { $user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID); - $body = json_decode($user->getBody()); - return $body->result; + $this->body = json_decode($user->getBody()); + return $this->body->result; } public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass { $response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details); - return json_decode($response->getBody()); + $this->body = json_decode($response->getBody()); + return $this->body; } public function deleteRecord(string $zoneID, string $recordID): bool { $user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } diff --git a/src/Endpoints/IPs.php b/src/Endpoints/IPs.php index 46b47651..16ad2fef 100644 --- a/src/Endpoints/IPs.php +++ b/src/Endpoints/IPs.php @@ -9,9 +9,12 @@ namespace Cloudflare\API\Endpoints; use Cloudflare\API\Adapter\Adapter; +use Cloudflare\API\Traits\BodyAccessorTrait; class IPs implements API { + use BodyAccessorTrait; + private $adapter; public function __construct(Adapter $adapter) @@ -22,8 +25,8 @@ public function __construct(Adapter $adapter) public function listIPs(): \stdClass { $ips = $this->adapter->get('ips'); - $body = json_decode($ips->getBody()); + $this->body = json_decode($ips->getBody()); - return $body->result; + return $this->body->result; } } diff --git a/src/Endpoints/PageRules.php b/src/Endpoints/PageRules.php index 43f2b3ae..3e56007a 100644 --- a/src/Endpoints/PageRules.php +++ b/src/Endpoints/PageRules.php @@ -11,9 +11,12 @@ use Cloudflare\API\Adapter\Adapter; use Cloudflare\API\Configurations\PageRulesActions; use Cloudflare\API\Configurations\PageRulesTargets; +use Cloudflare\API\Traits\BodyAccessorTrait; class PageRules implements API { + use BodyAccessorTrait; + private $adapter; public function __construct(Adapter $adapter) @@ -54,9 +57,9 @@ public function createPageRule( $query = $this->adapter->post('zones/' . $zoneID . '/pagerules', $options); - $body = json_decode($query->getBody()); + $this->body = json_decode($query->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } @@ -94,16 +97,16 @@ public function listPageRules( ]; $user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return $body->result; + return $this->body->result; } public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass { $user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID); - $body = json_decode($user->getBody()); - return $body->result; + $this->body = json_decode($user->getBody()); + return $this->body->result; } public function updatePageRule( @@ -134,9 +137,9 @@ public function updatePageRule( $query = $this->adapter->patch('zones/' . $zoneID . '/pagerules', $options); - $body = json_decode($query->getBody()); + $this->body = json_decode($query->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } @@ -147,9 +150,9 @@ public function deletePageRule(string $zoneID, string $ruleID): bool { $user = $this->adapter->delete('zones/' . $zoneID . '/pagerules/' . $ruleID); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } diff --git a/src/Endpoints/Railgun.php b/src/Endpoints/Railgun.php index 7272d691..8ba31820 100644 --- a/src/Endpoints/Railgun.php +++ b/src/Endpoints/Railgun.php @@ -9,9 +9,12 @@ namespace Cloudflare\API\Endpoints; use Cloudflare\API\Adapter\Adapter; +use Cloudflare\API\Traits\BodyAccessorTrait; class Railgun implements API { + use BodyAccessorTrait; + private $adapter; public function __construct(Adapter $adapter) @@ -27,9 +30,9 @@ public function create( ]; $user = $this->adapter->post('railguns', $query); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return $body; + return $this->body; } public function list( @@ -47,27 +50,27 @@ public function list( } $user = $this->adapter->get('railguns', $query); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return (object)['result' => $body->result, 'result_info' => $body->result_info]; + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; } public function get( string $railgunID ): \stdClass { $user = $this->adapter->get('railguns/' . $railgunID); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return $body->result; + return $this->body->result; } public function getZones( string $railgunID ): \stdClass { $user = $this->adapter->get('railguns/' . $railgunID . '/zones'); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return (object)['result' => $body->result, 'result_info' => $body->result_info]; + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; } public function update( @@ -79,18 +82,18 @@ public function update( ]; $user = $this->adapter->patch('railguns/' . $railgunID, $query); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return $body->result; + return $this->body->result; } public function delete( string $railgunID ): bool { $user = $this->adapter->delete('railguns/' . $railgunID); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } diff --git a/src/Endpoints/UARules.php b/src/Endpoints/UARules.php index 2284c0ab..8c7bfd9c 100644 --- a/src/Endpoints/UARules.php +++ b/src/Endpoints/UARules.php @@ -10,9 +10,12 @@ use Cloudflare\API\Configurations\Configurations; use Cloudflare\API\Adapter\Adapter; +use Cloudflare\API\Traits\BodyAccessorTrait; class UARules implements API { + use BodyAccessorTrait; + private $adapter; public function __construct(Adapter $adapter) @@ -31,9 +34,9 @@ public function listRules( ]; $user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return (object)['result' => $body->result, 'result_info' => $body->result_info]; + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; } public function createRule( @@ -58,9 +61,9 @@ public function createRule( $user = $this->adapter->post('zones/' . $zoneID . '/firewall/ua_rules', $options); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } @@ -70,8 +73,8 @@ public function createRule( public function getRuleDetails(string $zoneID, string $blockID): \stdClass { $user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID); - $body = json_decode($user->getBody()); - return $body->result; + $this->body = json_decode($user->getBody()); + return $this->body->result; } public function updateRule( @@ -93,9 +96,9 @@ public function updateRule( $user = $this->adapter->put('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, $options); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } @@ -106,9 +109,9 @@ public function deleteRule(string $zoneID, string $ruleID): bool { $user = $this->adapter->delete('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } diff --git a/tests/Endpoints/AccessRulesTest.php b/tests/Endpoints/AccessRulesTest.php index a7fd24d9..fbe4bd48 100644 --- a/tests/Endpoints/AccessRulesTest.php +++ b/tests/Endpoints/AccessRulesTest.php @@ -28,6 +28,7 @@ public function testListRules() $this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); + $this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $zones->getBody()->result[0]->id); } public function testCreateRule() @@ -58,6 +59,7 @@ public function testCreateRule() $config, 'This rule is on because of an event that occured on date X' ); + $this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id); } public function testUpdateRule() @@ -84,6 +86,7 @@ public function testUpdateRule() 'challenge', 'This rule is on because of an event that occured on date X' ); + $this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id); } public function testDeleteRule() @@ -104,5 +107,6 @@ public function testDeleteRule() $rules = new \Cloudflare\API\Endpoints\AccessRules($mock); $rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '92f17202ed8bd63d69a66b86a49a8f6b'); + $this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $rules->getBody()->result->id); } } diff --git a/tests/Endpoints/CustomHostnamesTest.php b/tests/Endpoints/CustomHostnamesTest.php index a6d9f9b6..faa247fb 100644 --- a/tests/Endpoints/CustomHostnamesTest.php +++ b/tests/Endpoints/CustomHostnamesTest.php @@ -32,6 +32,7 @@ public function testAddHostname() $hostname = new CustomHostnames($mock); $hostname->addHostname('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', 'http', 'dv'); + $this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $hostname->getBody()->result->id); } public function testListHostnames() @@ -64,6 +65,7 @@ public function testListHostnames() $this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); + $this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result[0]->id); } public function testGetHostname() @@ -84,6 +86,7 @@ public function testGetHostname() $this->assertObjectHasAttribute('id', $result); $this->assertObjectHasAttribute('hostname', $result); + $this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result->id); } public function testUpdateHostname() @@ -110,6 +113,7 @@ public function testUpdateHostname() $this->assertObjectHasAttribute('id', $result); $this->assertObjectHasAttribute('hostname', $result); + $this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->result->id); } public function testDeleteHostname() @@ -129,5 +133,6 @@ public function testDeleteHostname() $result = $zones->deleteHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9'); $this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->id); + $this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $zones->getBody()->id); } } diff --git a/tests/Endpoints/DNSTest.php b/tests/Endpoints/DNSTest.php index d82553a5..11c21fa8 100644 --- a/tests/Endpoints/DNSTest.php +++ b/tests/Endpoints/DNSTest.php @@ -63,6 +63,7 @@ public function testListRecords() $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id); } public function testGetDNSRecordDetails() @@ -82,6 +83,7 @@ public function testGetDNSRecordDetails() $result = $dns->getRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id); } public function testUpdateDNSRecord() @@ -110,6 +112,7 @@ public function testUpdateDNSRecord() $result = $dns->updateRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59', $details); $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result->id); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $dns->getBody()->result->id); foreach ($details as $property => $value) { $this->assertEquals($result->result->{ $property }, $value); diff --git a/tests/Endpoints/IPsTest.php b/tests/Endpoints/IPsTest.php index 27b85b5b..1f92804b 100644 --- a/tests/Endpoints/IPsTest.php +++ b/tests/Endpoints/IPsTest.php @@ -21,9 +21,11 @@ public function testListIPs() $this->equalTo('ips') ); - $ips = new \Cloudflare\API\Endpoints\IPs($mock); - $ips = $ips->listIPs(); + $ipsMock = new \Cloudflare\API\Endpoints\IPs($mock); + $ips = $ipsMock->listIPs(); $this->assertObjectHasAttribute('ipv4_cidrs', $ips); $this->assertObjectHasAttribute('ipv6_cidrs', $ips); + $this->assertObjectHasAttribute('ipv4_cidrs', $ipsMock->getBody()->result); + $this->assertObjectHasAttribute('ipv6_cidrs', $ipsMock->getBody()->result); } } diff --git a/tests/Endpoints/PageRulesTest.php b/tests/Endpoints/PageRulesTest.php index b082f60b..f2813fd0 100644 --- a/tests/Endpoints/PageRulesTest.php +++ b/tests/Endpoints/PageRulesTest.php @@ -35,6 +35,7 @@ public function testCreatePageRule() $result = $pageRules->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1); $this->assertTrue($result); + $this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id); } public function testListPageRules() @@ -58,6 +59,7 @@ public function testListPageRules() $pageRules = new \Cloudflare\API\Endpoints\PageRules($mock); $pageRules->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all'); + $this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result[0]->id); } public function testGetPageRuleDetails() @@ -75,6 +77,7 @@ public function testGetPageRuleDetails() $pageRules = new \Cloudflare\API\Endpoints\PageRules($mock); $pageRules->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac'); + $this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id); } public function testUpdatePageRule() @@ -104,6 +107,7 @@ public function testUpdatePageRule() $result = $pageRules->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1); $this->assertTrue($result); + $this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id); } public function testDeletePageRule() @@ -123,5 +127,6 @@ public function testDeletePageRule() $result = $pageRules->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac'); $this->assertTrue($result); + $this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $pageRules->getBody()->result->id); } } diff --git a/tests/Endpoints/RailgunTest.php b/tests/Endpoints/RailgunTest.php index 7d56e1cf..15e210b1 100644 --- a/tests/Endpoints/RailgunTest.php +++ b/tests/Endpoints/RailgunTest.php @@ -34,6 +34,7 @@ public function testcreate() foreach ($details as $property => $value) { $this->assertEquals($result->result->{ $property }, $value); } + $this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result->id); } public function testlist() @@ -59,6 +60,7 @@ public function testlist() $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); + $this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result[0]->id); } public function testget() @@ -78,6 +80,7 @@ public function testget() $result = $railgun->get('e928d310693a83094309acf9ead50448'); $this->assertEquals('e928d310693a83094309acf9ead50448', $result->id); + $this->assertEquals('e928d310693a83094309acf9ead50448', $railgun->getBody()->result->id); } public function testgetZones() @@ -98,6 +101,7 @@ public function testgetZones() $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $railgun->getBody()->result[0]->id); } public function testupdate() @@ -122,6 +126,7 @@ public function testupdate() $result = $waf->update('e928d310693a83094309acf9ead50448', true); $this->assertEquals('e928d310693a83094309acf9ead50448', $result->id); + $this->assertEquals('e928d310693a83094309acf9ead50448', $waf->getBody()->result->id); } public function testdelete() @@ -139,5 +144,6 @@ public function testdelete() $waf = new \Cloudflare\API\Endpoints\Railgun($mock); $waf->delete('e928d310693a83094309acf9ead50448'); + $this->assertEquals('e928d310693a83094309acf9ead50448', $waf->getBody()->result->id); } } From 099f383ef3fed5450835f04a94a6daa4480064a2 Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 11:06:34 -0400 Subject: [PATCH 13/14] Add trait to the rest of the endpoints --- src/Endpoints/User.php | 10 +++++--- src/Endpoints/WAF.php | 35 +++++++++++++++------------- src/Endpoints/ZoneLockdown.php | 23 ++++++++++-------- tests/Endpoints/UARulesTest.php | 5 ++++ tests/Endpoints/UserTest.php | 4 ++++ tests/Endpoints/WAFTest.php | 8 +++++++ tests/Endpoints/ZoneLockdownTest.php | 5 ++++ 7 files changed, 61 insertions(+), 29 deletions(-) diff --git a/src/Endpoints/User.php b/src/Endpoints/User.php index 02b9a8a1..93d38267 100644 --- a/src/Endpoints/User.php +++ b/src/Endpoints/User.php @@ -8,9 +8,12 @@ namespace Cloudflare\API\Endpoints; use Cloudflare\API\Adapter\Adapter; +use Cloudflare\API\Traits\BodyAccessorTrait; class User implements API { + use BodyAccessorTrait; + private $adapter; public function __construct(Adapter $adapter) @@ -21,8 +24,8 @@ public function __construct(Adapter $adapter) public function getUserDetails(): \stdClass { $user = $this->adapter->get('user'); - $body = json_decode($user->getBody()); - return $body->result; + $this->body = json_decode($user->getBody()); + return $this->body->result; } public function getUserID(): string @@ -38,6 +41,7 @@ public function getUserEmail(): string public function updateUserDetails(array $details): \stdClass { $response = $this->adapter->patch('user', $details); - return json_decode($response->getBody()); + $this->body = json_decode($response->getBody()); + return $this->body; } } diff --git a/src/Endpoints/WAF.php b/src/Endpoints/WAF.php index 2088940c..b1e3611f 100644 --- a/src/Endpoints/WAF.php +++ b/src/Endpoints/WAF.php @@ -9,9 +9,12 @@ namespace Cloudflare\API\Endpoints; use Cloudflare\API\Adapter\Adapter; +use Cloudflare\API\Traits\BodyAccessorTrait; class WAF implements API { + use BodyAccessorTrait; + private $adapter; public function __construct(Adapter $adapter) @@ -42,9 +45,9 @@ public function getPackages( } $user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages', $query); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return (object)['result' => $body->result, 'result_info' => $body->result_info]; + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; } @@ -53,9 +56,9 @@ public function getPackageInfo( string $packageID ): \stdClass { $user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return $body->result; + return $this->body->result; } public function getRules( @@ -81,9 +84,9 @@ public function getRules( $query['direction'] = $direction; } $user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules', $query); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return (object)['result' => $body->result, 'result_info' => $body->result_info]; + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; } public function getRuleInfo( @@ -92,9 +95,9 @@ public function getRuleInfo( string $ruleID ): \stdClass { $user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return $body->result; + return $this->body->result; } public function updateRule( @@ -111,9 +114,9 @@ public function updateRule( 'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID, $query ); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return $body->result; + return $this->body->result; } public function getGroups( @@ -143,9 +146,9 @@ public function getGroups( 'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups', $query ); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return (object)['result' => $body->result, 'result_info' => $body->result_info]; + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; } public function getGroupInfo( @@ -154,9 +157,9 @@ public function getGroupInfo( string $groupID ): \stdClass { $user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return $body->result; + return $this->body->result; } public function updateGroup( @@ -173,8 +176,8 @@ public function updateGroup( 'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID, $query ); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return $body->result; + return $this->body->result; } } diff --git a/src/Endpoints/ZoneLockdown.php b/src/Endpoints/ZoneLockdown.php index e42cde2d..aeccb254 100644 --- a/src/Endpoints/ZoneLockdown.php +++ b/src/Endpoints/ZoneLockdown.php @@ -9,9 +9,12 @@ namespace Cloudflare\API\Endpoints; use Cloudflare\API\Adapter\Adapter; +use Cloudflare\API\Traits\BodyAccessorTrait; class ZoneLockdown implements API { + use BodyAccessorTrait; + private $adapter; public function __construct(Adapter $adapter) @@ -30,9 +33,9 @@ public function listLockdowns( ]; $user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - return (object)['result' => $body->result, 'result_info' => $body->result_info]; + return (object)['result' => $this->body->result, 'result_info' => $this->body->result_info]; } public function createLockdown( @@ -57,9 +60,9 @@ public function createLockdown( $user = $this->adapter->post('zones/' . $zoneID . '/firewall/lockdowns', $options); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } @@ -69,8 +72,8 @@ public function createLockdown( public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass { $user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID); - $body = json_decode($user->getBody()); - return $body->result; + $this->body = json_decode($user->getBody()); + return $this->body->result; } public function updateLockdown( @@ -92,9 +95,9 @@ public function updateLockdown( $user = $this->adapter->put('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, $options); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } @@ -105,9 +108,9 @@ public function deleteLockdown(string $zoneID, string $lockdownID): bool { $user = $this->adapter->delete('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID); - $body = json_decode($user->getBody()); + $this->body = json_decode($user->getBody()); - if (isset($body->result->id)) { + if (isset($this->body->result->id)) { return true; } diff --git a/tests/Endpoints/UARulesTest.php b/tests/Endpoints/UARulesTest.php index 666f17d7..2ad17b3e 100644 --- a/tests/Endpoints/UARulesTest.php +++ b/tests/Endpoints/UARulesTest.php @@ -33,6 +33,7 @@ public function testListRules() $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id); } public function testCreateRule() @@ -65,6 +66,7 @@ public function testCreateRule() '372e67954025e0ba6aaa6d586b9e0b59', 'Prevent access from abusive clients identified by this UserAgent to mitigate DDoS attack' ); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id); } public function getRuleDetails() @@ -84,6 +86,7 @@ public function getRuleDetails() $result = $lockdown->getRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id); } public function testUpdateRule() @@ -116,6 +119,7 @@ public function testUpdateRule() $config, 'Restrict access to these endpoints to requests from a known IP address' ); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id); } public function testDeleteRule() @@ -133,5 +137,6 @@ public function testDeleteRule() $rules = new \Cloudflare\API\Endpoints\UARules($mock); $rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id); } } diff --git a/tests/Endpoints/UserTest.php b/tests/Endpoints/UserTest.php index e87343e7..07dc4248 100644 --- a/tests/Endpoints/UserTest.php +++ b/tests/Endpoints/UserTest.php @@ -21,6 +21,7 @@ public function testGetUserDetails() $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $details->id); $this->assertObjectHasAttribute('email', $details); $this->assertEquals('user@example.com', $details->email); + $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id); } public function testGetUserID() @@ -32,6 +33,7 @@ public function testGetUserID() $user = new \Cloudflare\API\Endpoints\User($mock); $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getUserID()); + $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id); } public function testGetUserEmail() @@ -45,6 +47,7 @@ public function testGetUserEmail() $user = new \Cloudflare\API\Endpoints\User($mock); $this->assertEquals('user@example.com', $user->getUserEmail()); + $this->assertEquals('user@example.com', $user->getBody()->result->email); } public function testUpdateUserDetails() @@ -60,5 +63,6 @@ public function testUpdateUserDetails() $user = new \Cloudflare\API\Endpoints\User($mock); $user->updateUserDetails(['email' => 'user2@example.com']); + $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getBody()->result->id); } } diff --git a/tests/Endpoints/WAFTest.php b/tests/Endpoints/WAFTest.php index 18057f39..f0c97aa9 100644 --- a/tests/Endpoints/WAFTest.php +++ b/tests/Endpoints/WAFTest.php @@ -36,6 +36,7 @@ public function testgetPackages() $this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); + $this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $waf->getBody()->result[0]->id); } public function testgetPackageInfo() @@ -55,6 +56,7 @@ public function testgetPackageInfo() $result = $waf->getPackageInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b'); $this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->id); + $this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $waf->getBody()->result->id); } public function testgetRules() @@ -85,6 +87,7 @@ public function testgetRules() $this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); + $this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $waf->getBody()->result[0]->id); } public function testgetRuleInfo() @@ -104,6 +107,7 @@ public function testgetRuleInfo() $result = $waf->getRuleInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023'); $this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id); + $this->assertEquals('f939de3be84e66e757adcdcb87908023', $waf->getBody()->result->id); } public function testupdateRule() @@ -132,6 +136,7 @@ public function testupdateRule() foreach ($details as $property => $value) { $this->assertEquals($result->{ $property }, $value); } + $this->assertEquals('f939de3be84e66e757adcdcb87908023', $waf->getBody()->result->id); } public function getGroups() @@ -162,6 +167,7 @@ public function getGroups() $this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); + $this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result[0]->id); } public function testgetGroupInfo() @@ -181,6 +187,7 @@ public function testgetGroupInfo() $result = $waf->getGroupInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5'); $this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id); + $this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result->id); } public function testupdateGroup() @@ -209,5 +216,6 @@ public function testupdateGroup() foreach ($details as $property => $value) { $this->assertEquals($result->{ $property }, $value); } + $this->assertEquals('de677e5818985db1285d0e80225f06e5', $waf->getBody()->result->id); } } diff --git a/tests/Endpoints/ZoneLockdownTest.php b/tests/Endpoints/ZoneLockdownTest.php index 599b4d6e..2af55ac6 100644 --- a/tests/Endpoints/ZoneLockdownTest.php +++ b/tests/Endpoints/ZoneLockdownTest.php @@ -33,6 +33,7 @@ public function testListLockdowns() $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zones->getBody()->result[0]->id); } public function testAddLockdown() @@ -65,6 +66,7 @@ public function testAddLockdown() '372e67954025e0ba6aaa6d586b9e0b59', 'Restrict access to these endpoints to requests from a known IP address' ); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id); } public function testGetRecordDetails() @@ -84,6 +86,7 @@ public function testGetRecordDetails() $result = $lockdown->getLockdownDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $lockdown->getBody()->result->id); } public function testUpdateLockdown() @@ -116,6 +119,7 @@ public function testUpdateLockdown() $config, 'Restrict access to these endpoints to requests from a known IP address' ); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id); } public function testDeleteLockdown() @@ -136,5 +140,6 @@ public function testDeleteLockdown() $zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock); $zoneLockdown->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $zoneLockdown->getBody()->result->id); } } From 57318b2a561cd884de145784a3c62044928d1790 Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Fri, 19 Oct 2018 11:28:10 -0400 Subject: [PATCH 14/14] Fix lint error --- tests/Endpoints/UARulesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Endpoints/UARulesTest.php b/tests/Endpoints/UARulesTest.php index 2ad17b3e..fec94b51 100644 --- a/tests/Endpoints/UARulesTest.php +++ b/tests/Endpoints/UARulesTest.php @@ -86,7 +86,7 @@ public function getRuleDetails() $result = $lockdown->getRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id); - $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $rules->getBody()->result->id); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $lockdown->getBody()->result->id); } public function testUpdateRule()