COM-40 :: Added None Auth class, IPs endpoint and associated tests
This commit is contained in:
18
src/Auth/None.php
Normal file
18
src/Auth/None.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: junade
|
||||
* Date: 04/09/2017
|
||||
* Time: 19:55
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Auth;
|
||||
|
||||
|
||||
class None implements Auth
|
||||
{
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
30
src/Endpoints/IPs.php
Normal file
30
src/Endpoints/IPs.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: junade
|
||||
* Date: 04/09/2017
|
||||
* Time: 19:56
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
|
||||
class IPs implements API
|
||||
{
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
public function get(): \stdClass {
|
||||
$ips = $this->adapter->get('ips', []);
|
||||
$body = json_decode($ips->getBody());
|
||||
|
||||
return $body->result;
|
||||
}
|
||||
|
||||
}
|
||||
20
tests/Auth/NoneTest.php
Normal file
20
tests/Auth/NoneTest.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: junade
|
||||
* Date: 04/09/2017
|
||||
* Time: 20:08
|
||||
*/
|
||||
|
||||
use Cloudflare\API\Auth\None;
|
||||
|
||||
class NoneTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetHeaders()
|
||||
{
|
||||
$auth = new \Cloudflare\API\Auth\None();
|
||||
$headers = $auth->getHeaders();
|
||||
|
||||
$this->assertEquals([], $headers);
|
||||
}
|
||||
}
|
||||
42
tests/Endpoints/IPsTest.php
Normal file
42
tests/Endpoints/IPsTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: junade
|
||||
* Date: 04/09/2017
|
||||
* Time: 20:16
|
||||
*/
|
||||
|
||||
use Cloudflare\API\Endpoints\IPs;
|
||||
|
||||
class IPsTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGet() {
|
||||
$stream = GuzzleHttp\Psr7\stream_for('
|
||||
{
|
||||
"success": true,
|
||||
"errors": [],
|
||||
"messages": [],
|
||||
"result": {
|
||||
"ipv4_cidrs": [
|
||||
"199.27.128.0/21"
|
||||
],
|
||||
"ipv6_cidrs": [
|
||||
"2400:cb00::/32"
|
||||
]
|
||||
}
|
||||
}');
|
||||
$response = new GuzzleHttp\Psr7\Response(200, ['Content-Type' => 'application/json'], $stream);
|
||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||
$mock->method('get')->willReturn($response);
|
||||
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with($this->equalTo('ips'), $this->equalTo([])
|
||||
);
|
||||
|
||||
$ips = new \Cloudflare\API\Endpoints\IPs($mock);
|
||||
$ips = $ips->get();
|
||||
$this->assertObjectHasAttribute("ipv4_cidrs", $ips);
|
||||
$this->assertObjectHasAttribute("ipv6_cidrs", $ips);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user