mirror of
https://github.com/ovh/php-ovh.git
synced 2023-11-05 03:20:26 +01:00
Merge pull request #106 from WelcomingGroup/master
chore: bump to php 7.4, guzzle 7, phpunit 9
This commit is contained in:
commit
d14a0d1cdb
@ -5,14 +5,10 @@ addons:
|
|||||||
|
|
||||||
language: php
|
language: php
|
||||||
php:
|
php:
|
||||||
- 7.3
|
- 7.4
|
||||||
- 7.2
|
|
||||||
- 7.1
|
|
||||||
- 7.0
|
|
||||||
- 5.6
|
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- composer self-update
|
- composer self-update
|
||||||
- composer install
|
- composer install
|
||||||
|
|
||||||
script: vendor/bin/phing test -Donly.units=true
|
script: vendor/bin/phpunit tests/ApiTest.php
|
||||||
|
@ -3,15 +3,18 @@
|
|||||||
"description": "Wrapper for OVH APIs",
|
"description": "Wrapper for OVH APIs",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"require": {
|
"require": {
|
||||||
"guzzlehttp/guzzle": "^6.0"
|
"php": ">=7.4",
|
||||||
|
"guzzlehttp/guzzle": "^6.0||^7.0",
|
||||||
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {"Ovh\\": "src/"}
|
"psr-4": {"Ovh\\": "src/"}
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "4.*",
|
"phpunit/phpunit": "^9.5",
|
||||||
"phpdocumentor/phpdocumentor": "2.*",
|
"phpdocumentor/phpdocumentor": "v3.0.0",
|
||||||
"squizlabs/php_codesniffer": "2.*",
|
"squizlabs/php_codesniffer": "^3.5",
|
||||||
"phing/phing": "^2.14"
|
"phpdocumentor/graphviz": "^2.0@dev",
|
||||||
|
"symfony/flex": "^1.11"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit colors="true" bootstrap="tests/bootstrap.php">
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||||
|
<coverage>
|
||||||
|
<include>
|
||||||
|
<directory>src</directory>
|
||||||
|
</include>
|
||||||
|
</coverage>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="OVH APIs wrapper">
|
<testsuite name="OVH APIs wrapper">
|
||||||
<directory>tests</directory>
|
<directory>tests</directory>
|
||||||
@ -11,9 +16,4 @@
|
|||||||
<env name="APP_SECRET" value=""/>
|
<env name="APP_SECRET" value=""/>
|
||||||
<env name="CONSUMER" value=""/>
|
<env name="CONSUMER" value=""/>
|
||||||
</php>
|
</php>
|
||||||
<filter>
|
|
||||||
<whitelist>
|
|
||||||
<directory>src</directory>
|
|
||||||
</whitelist>
|
|
||||||
</filter>
|
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
79
src/Api.php
79
src/Api.php
@ -31,8 +31,11 @@
|
|||||||
namespace Ovh;
|
namespace Ovh;
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Exception\ClientException;
|
||||||
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use GuzzleHttp\Psr7\Request;
|
use GuzzleHttp\Psr7\Request;
|
||||||
use GuzzleHttp\Psr7\Response;
|
use GuzzleHttp\Psr7\Response;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper to manage login and exchanges with simpliest Ovh API
|
* Wrapper to manage login and exchanges with simpliest Ovh API
|
||||||
@ -68,42 +71,42 @@ class Api
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $endpoint = null;
|
private ?string $endpoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contain key of the current application
|
* Contain key of the current application
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $application_key = null;
|
private ?string $application_key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contain secret of the current application
|
* Contain secret of the current application
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $application_secret = null;
|
private ?string $application_secret;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contain consumer key of the current application
|
* Contain consumer key of the current application
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $consumer_key = null;
|
private ?string $consumer_key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contain delta between local timestamp and api server timestamp
|
* Contain delta between local timestamp and api server timestamp
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $time_delta = null;
|
private ?string $time_delta;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contain http client connection
|
* Contain http client connection
|
||||||
*
|
*
|
||||||
* @var Client
|
* @var Client
|
||||||
*/
|
*/
|
||||||
private $http_client = null;
|
private ?Client $http_client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new wrapper instance
|
* Construct a new wrapper instance
|
||||||
@ -130,20 +133,15 @@ class Api
|
|||||||
throw new Exceptions\InvalidParameterException("Endpoint parameter is empty");
|
throw new Exceptions\InvalidParameterException("Endpoint parameter is empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preg_match('/^https?:\/\/..*/',$api_endpoint))
|
if (preg_match('/^https?:\/\/..*/', $api_endpoint)) {
|
||||||
{
|
|
||||||
$this->endpoint = $api_endpoint;
|
$this->endpoint = $api_endpoint;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!array_key_exists($api_endpoint, $this->endpoints)) {
|
if (!array_key_exists($api_endpoint, $this->endpoints)) {
|
||||||
throw new Exceptions\InvalidParameterException("Unknown provided endpoint");
|
throw new Exceptions\InvalidParameterException("Unknown provided endpoint");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->endpoint = $this->endpoints[$api_endpoint];
|
$this->endpoint = $this->endpoints[$api_endpoint];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($http_client)) {
|
if (!isset($http_client)) {
|
||||||
$http_client = new Client([
|
$http_client = new Client([
|
||||||
@ -156,13 +154,12 @@ class Api
|
|||||||
$this->application_secret = $application_secret;
|
$this->application_secret = $application_secret;
|
||||||
$this->http_client = $http_client;
|
$this->http_client = $http_client;
|
||||||
$this->consumer_key = $consumer_key;
|
$this->consumer_key = $consumer_key;
|
||||||
$this->time_delta = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate time delta between local machine and API's server
|
* Calculate time delta between local machine and API's server
|
||||||
*
|
*
|
||||||
* @throws \GuzzleHttp\Exception\ClientException if http request is an error
|
* @throws ClientException if http request is an error
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
private function calculateTimeDelta()
|
private function calculateTimeDelta()
|
||||||
@ -189,7 +186,7 @@ class Api
|
|||||||
* @param string $redirection url to redirect on your website after authentication
|
* @param string $redirection url to redirect on your website after authentication
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws \GuzzleHttp\Exception\ClientException if http request is an error
|
* @throws ClientException if http request is an error
|
||||||
*/
|
*/
|
||||||
public function requestCredentials(
|
public function requestCredentials(
|
||||||
array $accessRules,
|
array $accessRules,
|
||||||
@ -223,13 +220,15 @@ class Api
|
|||||||
* @param \stdClass|array|null $content body of the request
|
* @param \stdClass|array|null $content body of the request
|
||||||
* @param bool $is_authenticated if the request use authentication
|
* @param bool $is_authenticated if the request use authentication
|
||||||
*
|
*
|
||||||
* @return array
|
* @param null $headers
|
||||||
* @throws \GuzzleHttp\Exception\ClientException if http request is an error
|
* @return ResponseInterface
|
||||||
|
* @throws Exceptions\InvalidParameterException
|
||||||
|
* @throws GuzzleException
|
||||||
|
* @throws \JsonException
|
||||||
*/
|
*/
|
||||||
protected function rawCall($method, $path, $content = null, $is_authenticated = true, $headers = null)
|
protected function rawCall($method, $path, $content = null, $is_authenticated = true, $headers = null): ResponseInterface
|
||||||
{
|
|
||||||
if ( $is_authenticated )
|
|
||||||
{
|
{
|
||||||
|
if ($is_authenticated) {
|
||||||
if (!isset($this->application_key)) {
|
if (!isset($this->application_key)) {
|
||||||
throw new Exceptions\InvalidParameterException("Application key parameter is empty");
|
throw new Exceptions\InvalidParameterException("Application key parameter is empty");
|
||||||
}
|
}
|
||||||
@ -241,7 +240,7 @@ class Api
|
|||||||
|
|
||||||
$url = $this->endpoint . $path;
|
$url = $this->endpoint . $path;
|
||||||
$request = new Request($method, $url);
|
$request = new Request($method, $url);
|
||||||
if (isset($content) && $method == 'GET') {
|
if (isset($content) && $method === 'GET') {
|
||||||
$query_string = $request->getUri()->getQuery();
|
$query_string = $request->getUri()->getQuery();
|
||||||
|
|
||||||
$query = array();
|
$query = array();
|
||||||
@ -270,20 +269,18 @@ class Api
|
|||||||
$request = $request->withUri($url);
|
$request = $request->withUri($url);
|
||||||
$body = "";
|
$body = "";
|
||||||
} elseif (isset($content)) {
|
} elseif (isset($content)) {
|
||||||
$body = json_encode($content, JSON_UNESCAPED_SLASHES);
|
$body = json_encode($content, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES);
|
||||||
|
|
||||||
$request->getBody()->write($body);
|
$request->getBody()->write($body);
|
||||||
} else {
|
} else {
|
||||||
$body = "";
|
$body = "";
|
||||||
}
|
}
|
||||||
if(!is_array($headers))
|
if (!is_array($headers)) {
|
||||||
{
|
|
||||||
$headers = [];
|
$headers = [];
|
||||||
}
|
}
|
||||||
$headers['Content-Type'] = 'application/json; charset=utf-8';
|
$headers['Content-Type'] = 'application/json; charset=utf-8';
|
||||||
|
|
||||||
if ($is_authenticated) {
|
if ($is_authenticated) {
|
||||||
|
|
||||||
$headers['X-Ovh-Application'] = $this->application_key;
|
$headers['X-Ovh-Application'] = $this->application_key;
|
||||||
|
|
||||||
if (!isset($this->time_delta)) {
|
if (!isset($this->time_delta)) {
|
||||||
@ -311,11 +308,11 @@ class Api
|
|||||||
*
|
*
|
||||||
* @param Response $response
|
* @param Response $response
|
||||||
*
|
*
|
||||||
* @return array
|
* @throws \JsonException
|
||||||
*/
|
*/
|
||||||
private function decodeResponse(Response $response)
|
private function decodeResponse(Response $response)
|
||||||
{
|
{
|
||||||
return json_decode($response->getBody(), true);
|
return json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -326,25 +323,22 @@ class Api
|
|||||||
* @param array headers custom HTTP headers to add on the request
|
* @param array headers custom HTTP headers to add on the request
|
||||||
* @param bool is_authenticated if the request need to be authenticated
|
* @param bool is_authenticated if the request need to be authenticated
|
||||||
*
|
*
|
||||||
* @return array
|
* @throws ClientException if http request is an error
|
||||||
* @throws \GuzzleHttp\Exception\ClientException if http request is an error
|
* @throws \JsonException
|
||||||
*/
|
*/
|
||||||
public function get($path, $content = null, $headers = null, $is_authenticated = true)
|
public function get($path, $content = null, $headers = null, $is_authenticated = true)
|
||||||
{
|
{
|
||||||
if(preg_match('/^\/[^\/]+\.json$/', $path))
|
if (preg_match('/^\/[^\/]+\.json$/', $path)) {
|
||||||
{
|
|
||||||
// Schema description must be access without authentication
|
// Schema description must be access without authentication
|
||||||
return $this->decodeResponse(
|
return $this->decodeResponse(
|
||||||
$this->rawCall("GET", $path, $content, false, $headers)
|
$this->rawCall("GET", $path, $content, false, $headers)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return $this->decodeResponse(
|
return $this->decodeResponse(
|
||||||
$this->rawCall("GET", $path, $content, $is_authenticated, $headers)
|
$this->rawCall("GET", $path, $content, $is_authenticated, $headers)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap call to Ovh APIs for POST requests
|
* Wrap call to Ovh APIs for POST requests
|
||||||
@ -354,8 +348,7 @@ class Api
|
|||||||
* @param array headers custom HTTP headers to add on the request
|
* @param array headers custom HTTP headers to add on the request
|
||||||
* @param bool is_authenticated if the request need to be authenticated
|
* @param bool is_authenticated if the request need to be authenticated
|
||||||
*
|
*
|
||||||
* @return array
|
* @throws ClientException if http request is an error
|
||||||
* @throws \GuzzleHttp\Exception\ClientException if http request is an error
|
|
||||||
*/
|
*/
|
||||||
public function post($path, $content = null, $headers = null, $is_authenticated = true)
|
public function post($path, $content = null, $headers = null, $is_authenticated = true)
|
||||||
{
|
{
|
||||||
@ -372,8 +365,7 @@ class Api
|
|||||||
* @param array headers custom HTTP headers to add on the request
|
* @param array headers custom HTTP headers to add on the request
|
||||||
* @param bool is_authenticated if the request need to be authenticated
|
* @param bool is_authenticated if the request need to be authenticated
|
||||||
*
|
*
|
||||||
* @return array
|
* @throws ClientException if http request is an error
|
||||||
* @throws \GuzzleHttp\Exception\ClientException if http request is an error
|
|
||||||
*/
|
*/
|
||||||
public function put($path, $content, $headers = null, $is_authenticated = true)
|
public function put($path, $content, $headers = null, $is_authenticated = true)
|
||||||
{
|
{
|
||||||
@ -390,8 +382,7 @@ class Api
|
|||||||
* @param array headers custom HTTP headers to add on the request
|
* @param array headers custom HTTP headers to add on the request
|
||||||
* @param bool is_authenticated if the request need to be authenticated
|
* @param bool is_authenticated if the request need to be authenticated
|
||||||
*
|
*
|
||||||
* @return array
|
* @throws ClientException if http request is an error
|
||||||
* @throws \GuzzleHttp\Exception\ClientException if http request is an error
|
|
||||||
*/
|
*/
|
||||||
public function delete($path, $content = null, $headers = null, $is_authenticated = true)
|
public function delete($path, $content = null, $headers = null, $is_authenticated = true)
|
||||||
{
|
{
|
||||||
@ -403,7 +394,7 @@ class Api
|
|||||||
/**
|
/**
|
||||||
* Get the current consumer key
|
* Get the current consumer key
|
||||||
*/
|
*/
|
||||||
public function getConsumerKey()
|
public function getConsumerKey(): ?string
|
||||||
{
|
{
|
||||||
return $this->consumer_key;
|
return $this->consumer_key;
|
||||||
}
|
}
|
||||||
@ -411,7 +402,7 @@ class Api
|
|||||||
/**
|
/**
|
||||||
* Return instance of http client
|
* Return instance of http client
|
||||||
*/
|
*/
|
||||||
public function getHttpClient()
|
public function getHttpClient(): ?Client
|
||||||
{
|
{
|
||||||
return $this->http_client;
|
return $this->http_client;
|
||||||
}
|
}
|
||||||
|
@ -43,5 +43,4 @@ use Exception;
|
|||||||
*/
|
*/
|
||||||
class ApiException extends Exception
|
class ApiException extends Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,5 +43,4 @@ use Exception;
|
|||||||
*/
|
*/
|
||||||
class InvalidParameterException extends Exception
|
class InvalidParameterException extends Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,5 +42,4 @@ use Exception;
|
|||||||
*/
|
*/
|
||||||
class NotLoggedException extends Exception
|
class NotLoggedException extends Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,9 @@
|
|||||||
namespace Ovh\tests;
|
namespace Ovh\tests;
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Exception\ClientException;
|
||||||
use Ovh\Api;
|
use Ovh\Api;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functional tests of Api class
|
* Functional tests of Api class
|
||||||
@ -36,7 +38,7 @@ use Ovh\Api;
|
|||||||
* @package Ovh
|
* @package Ovh
|
||||||
* @category Ovh
|
* @category Ovh
|
||||||
*/
|
*/
|
||||||
class ApiFunctionalTest extends \PHPUnit_Framework_TestCase
|
class ApiFunctionalTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,7 +84,7 @@ class ApiFunctionalTest extends \PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* Define id to create object
|
* Define id to create object
|
||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp() :void
|
||||||
{
|
{
|
||||||
$this->application_key = getenv('APP_KEY');
|
$this->application_key = getenv('APP_KEY');
|
||||||
$this->application_secret = getenv('APP_SECRET');
|
$this->application_secret = getenv('APP_SECRET');
|
||||||
@ -238,7 +240,7 @@ class ApiFunctionalTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testApiGetWithParameters()
|
public function testApiGetWithParameters()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('\\GuzzleHttp\\Exception\\ClientException', '400');
|
$this->expectException(ClientException::class);
|
||||||
|
|
||||||
$this->api->get('/me/accessRestriction/ip', ['foo' => 'bar']);
|
$this->api->get('/me/accessRestriction/ip', ['foo' => 'bar']);
|
||||||
}
|
}
|
||||||
|
@ -28,10 +28,14 @@
|
|||||||
namespace Ovh\tests;
|
namespace Ovh\tests;
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Exception\ClientException;
|
||||||
use GuzzleHttp\Middleware;
|
use GuzzleHttp\Middleware;
|
||||||
|
use GuzzleHttp\Psr7;
|
||||||
use GuzzleHttp\Psr7\Response;
|
use GuzzleHttp\Psr7\Response;
|
||||||
use GuzzleHttp\Psr7\Request;
|
use GuzzleHttp\Psr7\Request;
|
||||||
use Ovh\Api;
|
use Ovh\Api;
|
||||||
|
use Ovh\Exceptions\InvalidParameterException;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Api class
|
* Test Api class
|
||||||
@ -39,7 +43,7 @@ use Ovh\Api;
|
|||||||
* @package Ovh
|
* @package Ovh
|
||||||
* @category Ovh
|
* @category Ovh
|
||||||
*/
|
*/
|
||||||
class ApiTest extends \PHPUnit_Framework_TestCase
|
class ApiTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Client
|
* @var Client
|
||||||
@ -69,7 +73,7 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* Define id to create object
|
* Define id to create object
|
||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp() :void
|
||||||
{
|
{
|
||||||
$this->application_key = 'app_key';
|
$this->application_key = 'app_key';
|
||||||
$this->application_secret = 'app_secret';
|
$this->application_secret = 'app_secret';
|
||||||
@ -116,7 +120,7 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testMissingApplicationKey()
|
public function testMissingApplicationKey()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('\\Ovh\\Exceptions\\InvalidParameterException', 'Application key');
|
$this->expectException(InvalidParameterException::class);
|
||||||
$api = new Api(null, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
|
$api = new Api(null, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
|
||||||
$api->get('/me');
|
$api->get('/me');
|
||||||
}
|
}
|
||||||
@ -126,7 +130,7 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testMissingApplicationSecret()
|
public function testMissingApplicationSecret()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('\\Ovh\\Exceptions\\InvalidParameterException', 'Application secret');
|
$this->expectException(InvalidParameterException::class);
|
||||||
$api = new Api($this->application_key, null, $this->endpoint, $this->consumer_key, $this->client);
|
$api = new Api($this->application_key, null, $this->endpoint, $this->consumer_key, $this->client);
|
||||||
$api->get('/me');
|
$api->get('/me');
|
||||||
}
|
}
|
||||||
@ -142,14 +146,19 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
$request = $request->withUri($request->getUri()
|
return null;
|
||||||
->withHost('httpbin.org')
|
}));
|
||||||
->withPath('/')
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
->withQuery(''));
|
$body = Psr7\Utils::streamFor('{}');
|
||||||
return $request;
|
|
||||||
|
return $response
|
||||||
|
->withStatus(200)
|
||||||
|
->withHeader('Content-Type', 'application/json; charset=utf-8')
|
||||||
|
->withBody($body);
|
||||||
}));
|
}));
|
||||||
$api = new Api(NULL, NULL, $this->endpoint, $this->consumer_key, $this->client);
|
$api = new Api(NULL, NULL, $this->endpoint, $this->consumer_key, $this->client);
|
||||||
$api->get('/1.0/unauthcall', null, null, false);
|
$api->get('/unauthcall', null, null, false);
|
||||||
|
$this->assertEquals(1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,7 +166,7 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testMissingApiEndpoint()
|
public function testMissingApiEndpoint()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('\\Ovh\\Exceptions\\InvalidParameterException', 'Endpoint');
|
$this->expectException(InvalidParameterException::class);
|
||||||
new Api($this->application_key, $this->application_secret, null, $this->consumer_key, $this->client);
|
new Api($this->application_key, $this->application_secret, null, $this->consumer_key, $this->client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +175,7 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testBadApiEndpoint()
|
public function testBadApiEndpoint()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('\\Ovh\\Exceptions\\InvalidParameterException', 'Unknown');
|
$this->expectException(InvalidParameterException::class);
|
||||||
new Api($this->application_key, $this->application_secret, 'i_am_invalid', $this->consumer_key, $this->client);
|
new Api($this->application_key, $this->application_secret, 'i_am_invalid', $this->consumer_key, $this->client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,11 +199,11 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
$handlerStack = $this->client->getConfig('handler');
|
$handlerStack = $this->client->getConfig('handler');
|
||||||
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
|
|
||||||
$body = $response->getBody();
|
$body = Psr7\Utils::streamFor(time() - 10);
|
||||||
$body->write(time() - 10);
|
|
||||||
|
|
||||||
return $response
|
return $response
|
||||||
->withStatus(200)
|
->withStatus(200)
|
||||||
|
->withHeader('Content-Type', 'application/json; charset=utf-8')
|
||||||
->withBody($body);
|
->withBody($body);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -217,16 +226,19 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
$handlerStack = $this->client->getConfig('handler');
|
$handlerStack = $this->client->getConfig('handler');
|
||||||
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
|
|
||||||
$body = $response->getBody();
|
$body = Psr7\Utils::streamFor('{"validationUrl":"https://api.ovh.com/login/?credentialToken=token","consumerKey":"consumer_remote","state":"pendingValidation"}');
|
||||||
$body->write('{"validationUrl":"https://api.ovh.com/login/?credentialToken=token","consumerKey":"consumer_remote","state":"pendingValidation"}');
|
|
||||||
|
|
||||||
return $response
|
return $response
|
||||||
->withStatus(200)
|
->withStatus(200)
|
||||||
|
->withHeader('Content-Type', 'application/json; charset=utf-8')
|
||||||
->withBody($body);
|
->withBody($body);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
$property = self::getPrivateProperty('consumer_key');
|
$property = self::getPrivateProperty('consumer_key');
|
||||||
|
|
||||||
|
$this->assertEquals('consumer', $this->consumer_key);
|
||||||
|
$this->assertNotEquals('consumer_remote', $this->consumer_key);
|
||||||
|
|
||||||
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
|
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
|
||||||
$accessRules = [json_decode(' { "method": "GET", "path": "/*" } ')];
|
$accessRules = [json_decode(' { "method": "GET", "path": "/*" } ')];
|
||||||
|
|
||||||
@ -235,6 +247,7 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
$consumer_key = $property->getValue($api);
|
$consumer_key = $property->getValue($api);
|
||||||
|
|
||||||
$this->assertEquals($consumer_key, $credentials["consumerKey"]);
|
$this->assertEquals($consumer_key, $credentials["consumerKey"]);
|
||||||
|
$this->assertEquals('consumer_remote', $credentials["consumerKey"]);
|
||||||
$this->assertNotEquals($consumer_key, $this->consumer_key);
|
$this->assertNotEquals($consumer_key, $this->consumer_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,15 +256,13 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testInvalidApplicationKey()
|
public function testInvalidApplicationKey()
|
||||||
{
|
{
|
||||||
$this->setExpectedException(
|
|
||||||
'\GuzzleHttp\Exception\ClientException'
|
$this->expectException(ClientException::class);
|
||||||
);
|
|
||||||
|
|
||||||
$handlerStack = $this->client->getConfig('handler');
|
$handlerStack = $this->client->getConfig('handler');
|
||||||
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
|
|
||||||
$body = $response->getBody();
|
$body = Psr7\Utils::streamFor('{\"message\":\"Invalid application key\"}');
|
||||||
$body->write('{\"message\":\"Invalid application key\"}');
|
|
||||||
|
|
||||||
return $response
|
return $response
|
||||||
->withStatus(401, 'POUET')
|
->withStatus(401, 'POUET')
|
||||||
@ -276,15 +287,12 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testInvalidRight()
|
public function testInvalidRight()
|
||||||
{
|
{
|
||||||
$this->setExpectedException(
|
$this->expectException(ClientException::class);
|
||||||
'\GuzzleHttp\Exception\ClientException'
|
|
||||||
);
|
|
||||||
|
|
||||||
$handlerStack = $this->client->getConfig('handler');
|
$handlerStack = $this->client->getConfig('handler');
|
||||||
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
|
|
||||||
$body = $response->getBody();
|
$body = Psr7\Utils::streamFor('{\"message\":\"Invalid credentials\"}');
|
||||||
$body->write('{\"message\":\"Invalid credentials\"}');
|
|
||||||
|
|
||||||
return $response
|
return $response
|
||||||
->withStatus(403)
|
->withStatus(403)
|
||||||
@ -326,9 +334,14 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
->withQuery(''));
|
->withQuery(''));
|
||||||
return $request;
|
return $request;
|
||||||
}));
|
}));
|
||||||
//$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
// return $response;
|
$body = Psr7\Utils::streamFor('123456789991');
|
||||||
//}));
|
|
||||||
|
return $response
|
||||||
|
->withStatus(200)
|
||||||
|
->withHeader('Content-Type', 'application/json; charset=utf-8')
|
||||||
|
->withBody($body);
|
||||||
|
}));
|
||||||
|
|
||||||
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
|
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
|
||||||
$api->get('/me/api/credential?applicationId=49', ['status' => 'pendingValidation']);
|
$api->get('/me/api/credential?applicationId=49', ['status' => 'pendingValidation']);
|
||||||
@ -354,9 +367,14 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
->withQuery(''));
|
->withQuery(''));
|
||||||
return $request;
|
return $request;
|
||||||
}));
|
}));
|
||||||
//$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
// return $response;
|
$body = Psr7\Utils::streamFor('123456789991');
|
||||||
//}));
|
|
||||||
|
return $response
|
||||||
|
->withStatus(200)
|
||||||
|
->withHeader('Content-Type', 'application/json; charset=utf-8')
|
||||||
|
->withBody($body);
|
||||||
|
}));
|
||||||
|
|
||||||
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
|
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
|
||||||
$api->get('/me/api/credential?applicationId=49&status=pendingValidation', ['status' => 'expired', 'test' => "success"]);
|
$api->get('/me/api/credential?applicationId=49&status=pendingValidation', ['status' => 'expired', 'test' => "success"]);
|
||||||
@ -382,9 +400,14 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
->withQuery(''));
|
->withQuery(''));
|
||||||
return $request;
|
return $request;
|
||||||
}));
|
}));
|
||||||
//$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
// return $response;
|
$body = Psr7\Utils::streamFor('123456789991');
|
||||||
//}));
|
|
||||||
|
return $response
|
||||||
|
->withStatus(200)
|
||||||
|
->withHeader('Content-Type', 'application/json; charset=utf-8')
|
||||||
|
->withBody($body);
|
||||||
|
}));
|
||||||
|
|
||||||
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
|
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
|
||||||
$api->get('/me/api/credential', ['dryRun' => true, 'notDryRun' => false]);
|
$api->get('/me/api/credential', ['dryRun' => true, 'notDryRun' => false]);
|
||||||
@ -416,9 +439,14 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
->withQuery(''));
|
->withQuery(''));
|
||||||
return $request;
|
return $request;
|
||||||
}));
|
}));
|
||||||
//$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
// return $response;
|
$body = Psr7\Utils::streamFor('123456789991');
|
||||||
//}));
|
|
||||||
|
return $response
|
||||||
|
->withStatus(200)
|
||||||
|
->withHeader('Content-Type', 'application/json; charset=utf-8')
|
||||||
|
->withBody($body);
|
||||||
|
}));
|
||||||
|
|
||||||
$api = new Api($this->application_key, $this->application_secret, 'ovh-ca', $this->consumer_key, $this->client);
|
$api = new Api($this->application_key, $this->application_secret, 'ovh-ca', $this->consumer_key, $this->client);
|
||||||
$api->get('/me/api/credential');
|
$api->get('/me/api/credential');
|
||||||
@ -450,9 +478,14 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
->withQuery(''));
|
->withQuery(''));
|
||||||
return $request;
|
return $request;
|
||||||
}));
|
}));
|
||||||
//$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
// return $response;
|
$body = Psr7\Utils::streamFor('123456789991');
|
||||||
//}));
|
|
||||||
|
return $response
|
||||||
|
->withStatus(200)
|
||||||
|
->withHeader('Content-Type', 'application/json; charset=utf-8')
|
||||||
|
->withBody($body);
|
||||||
|
}));
|
||||||
|
|
||||||
$api = new Api($this->application_key, $this->application_secret, 'http://api.ovh.com/1.0', $this->consumer_key, $this->client);
|
$api = new Api($this->application_key, $this->application_secret, 'http://api.ovh.com/1.0', $this->consumer_key, $this->client);
|
||||||
$api->get('/me/api/credential');
|
$api->get('/me/api/credential');
|
||||||
@ -484,9 +517,14 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
->withQuery(''));
|
->withQuery(''));
|
||||||
return $request;
|
return $request;
|
||||||
}));
|
}));
|
||||||
//$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
// return $response;
|
$body = Psr7\Utils::streamFor('123456789991');
|
||||||
//}));
|
|
||||||
|
return $response
|
||||||
|
->withStatus(200)
|
||||||
|
->withHeader('Content-Type', 'application/json; charset=utf-8')
|
||||||
|
->withBody($body);
|
||||||
|
}));
|
||||||
|
|
||||||
$api = new Api($this->application_key, $this->application_secret, 'https://api.ovh.com/1.0', $this->consumer_key, $this->client);
|
$api = new Api($this->application_key, $this->application_secret, 'https://api.ovh.com/1.0', $this->consumer_key, $this->client);
|
||||||
$api->get('/me/api/credential');
|
$api->get('/me/api/credential');
|
||||||
@ -514,10 +552,16 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
return $request;
|
return $request;
|
||||||
}));
|
}));
|
||||||
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
return $response->withStatus(200);
|
$body = Psr7\Utils::streamFor('{"validationUrl":"https://api.ovh.com/login/?credentialToken=token","consumerKey":"consumer_remote","state":"pendingValidation"}');
|
||||||
|
|
||||||
|
return $response
|
||||||
|
->withStatus(200)
|
||||||
|
->withHeader('Content-Type', 'application/json; charset=utf-8')
|
||||||
|
->withBody($body);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
|
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
|
||||||
$api->requestCredentials([]);
|
$api->requestCredentials([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user