split methods to another class to pass CI test

This commit is contained in:
Michael Markoski
2019-05-25 14:59:29 -05:00
parent 63ded280d3
commit 79ca15c066
4 changed files with 296 additions and 274 deletions

View File

@@ -13,42 +13,6 @@ class Crypto implements API
$this->adapter = $adapter; $this->adapter = $adapter;
} }
/**
* Get the SSL setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getSSLSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/ssl'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result->value;
}
return false;
}
/**
* Get SSL Verification Info for a Zone
*
* @param string $zoneID The ID of the zone
* @return array|false
*/
public function getSSLVerificationStatus(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/ssl/verification'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body;
}
return false;
}
/** /**
* Get the Opportunistic Encryption feature for a zone. * Get the Opportunistic Encryption feature for a zone.
* *
@@ -85,108 +49,6 @@ class Crypto implements API
return false; return false;
} }
/**
* Get the HTTPS Redirect setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getHTTPSRedirectSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/always_use_https'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result;
}
return false;
}
/**
* Get the HTTPS Rewrite setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getHTTPSRewritesSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/automatic_https_rewrites'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result;
}
return false;
}
/**
* Update the SSL setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateSSLSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/ssl',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the HTTPS Redirect setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateHTTPSRedirectSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/always_use_https',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the HTTPS Rewrite setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateHTTPSRewritesSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/automatic_https_rewrites',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/** /**
* Update the Oppurtunistic Encryption setting for the zone * Update the Oppurtunistic Encryption setting for the zone
* *

154
src/Endpoints/SSL.php Normal file
View File

@@ -0,0 +1,154 @@
<?php
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class SSL implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
/**
* Get the SSL setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getSSLSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/ssl'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result->value;
}
return false;
}
/**
* Get SSL Verification Info for a Zone
*
* @param string $zoneID The ID of the zone
* @return array|false
*/
public function getSSLVerificationStatus(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/ssl/verification'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body;
}
return false;
}
/**
* Get the HTTPS Redirect setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getHTTPSRedirectSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/always_use_https'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result;
}
return false;
}
/**
* Get the HTTPS Rewrite setting for the zone
*
* @param string $zoneID The ID of the zone
* @return string|false
*/
public function getHTTPSRewritesSetting(string $zoneID)
{
$return = $this->adapter->get(
'zones/' . $zoneID . '/settings/automatic_https_rewrites'
);
$body = json_decode($return->getBody());
if (isset($body->result)) {
return $body->result;
}
return false;
}
/**
* Update the SSL setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateSSLSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/ssl',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the HTTPS Redirect setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateHTTPSRedirectSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/always_use_https',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
/**
* Update the HTTPS Rewrite setting for the zone
*
* @param string $zoneID The ID of the zone
* @param string $value The value of the zone setting
* @return bool
*/
public function updateHTTPSRewritesSetting(string $zoneID, string $value)
{
$return = $this->adapter->patch(
'zones/' . $zoneID . '/settings/automatic_https_rewrites',
[
'value' => $value,
]
);
$body = json_decode($return->getBody());
if (isset($body->success) && $body->success == true) {
return true;
}
return false;
}
}

View File

@@ -2,44 +2,6 @@
class CryptoTest extends TestCase class CryptoTest extends TestCase
{ {
public function testGetSSLSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/ssl')
);
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
$result = $cryptoMock->getSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('off', $result);
}
public function testGetSSLVerificationStatus()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLVerificationStatus.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/ssl/verification')
);
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
$result = $cryptoMock->getSSLVerificationStatus('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertObjectHasAttribute('result', $result);
$this->assertEquals('active', $result->result{0}->certificate_status);
}
public function testGetOpportunisticEncryptionSetting() public function testGetOpportunisticEncryptionSetting()
{ {
@@ -79,104 +41,6 @@ class CryptoTest extends TestCase
$this->assertEquals('off', $result); $this->assertEquals('off', $result);
} }
public function testGetHTTPSRedirectSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRedirectSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/always_use_https')
);
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
$result = $cryptoMock->getHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('off', $result);
}
public function testGetHTTPSRewritesSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRewritesSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/automatic_https_rewrites')
);
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
$result = $cryptoMock->getHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('off', $result);
}
public function testUpdateSSLSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSSLSetting.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/settings/ssl'),
$this->equalTo(['value' => 'full'])
);
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
$result = $cryptoMock->updateSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'full');
$this->assertTrue($result);
}
public function testUpdateHTTPSRedirectSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRedirectSetting.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/settings/always_use_https'),
$this->equalTo(['value' => 'off'])
);
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
$result = $cryptoMock->updateHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
$this->assertTrue($result);
}
public function testUpdateHTTPSRewritesSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRewritesSetting.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/settings/automatic_https_rewrites'),
$this->equalTo(['value' => 'off'])
);
$cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
$result = $cryptoMock->updateHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
$this->assertTrue($result);
}
public function testUpdateOpportunisticEncryptionSetting() public function testUpdateOpportunisticEncryptionSetting()
{ {
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOpportunisticEncryptionSetting.json'); $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOpportunisticEncryptionSetting.json');

142
tests/Endpoints/SSLTest.php Normal file
View File

@@ -0,0 +1,142 @@
<?php
class SSLTest extends TestCase
{
public function testGetSSLSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/ssl')
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->getSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('off', $result);
}
public function testGetSSLVerificationStatus()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLVerificationStatus.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/ssl/verification')
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->getSSLVerificationStatus('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertObjectHasAttribute('result', $result);
$this->assertEquals('active', $result->result{0}->certificate_status);
}
public function testGetHTTPSRedirectSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRedirectSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/always_use_https')
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->getHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('off', $result);
}
public function testGetHTTPSRewritesSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRewritesSetting.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/automatic_https_rewrites')
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->getHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertEquals('off', $result);
}
public function testUpdateSSLSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSSLSetting.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/settings/ssl'),
$this->equalTo(['value' => 'full'])
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->updateSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'full');
$this->assertTrue($result);
}
public function testUpdateHTTPSRedirectSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRedirectSetting.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/settings/always_use_https'),
$this->equalTo(['value' => 'off'])
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->updateHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
$this->assertTrue($result);
}
public function testUpdateHTTPSRewritesSetting()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRewritesSetting.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/settings/automatic_https_rewrites'),
$this->equalTo(['value' => 'off'])
);
$sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
$result = $sslMock->updateHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
$this->assertTrue($result);
}
}