mirror of
https://github.com/ovh/php-ovh.git
synced 2023-11-05 03:20:26 +01:00
Update ApiTest to use a HttpClient instance
Guzzle is still used inside the test logic with middlewares.
This commit is contained in:
parent
5fbcdf06b2
commit
94de85dfaf
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
namespace Ovh\tests;
|
namespace Ovh\tests;
|
||||||
|
|
||||||
|
use Http\Adapter\Guzzle6\Client as HttpClient;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Middleware;
|
use GuzzleHttp\Middleware;
|
||||||
use GuzzleHttp\Psr7\Response;
|
use GuzzleHttp\Psr7\Response;
|
||||||
@ -76,7 +77,8 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->consumer_key = 'consumer';
|
$this->consumer_key = 'consumer';
|
||||||
$this->endpoint = 'ovh-eu';
|
$this->endpoint = 'ovh-eu';
|
||||||
|
|
||||||
$this->client = new Client();
|
$this->guzzle = new Client();
|
||||||
|
$this->client = new HttpClient($this->guzzle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -152,9 +154,8 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testClientCreation()
|
public function testClientCreation()
|
||||||
{
|
{
|
||||||
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key);
|
$api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
|
||||||
|
$this->assertInstanceOf('Http\\Client\\HttpClient', $api->getHttpClient());
|
||||||
$this->assertInstanceOf('\\GuzzleHttp\\Client', $api->getHttpClient());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,7 +165,7 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$delay = 10;
|
$delay = 10;
|
||||||
|
|
||||||
$handlerStack = $this->client->getConfig('handler');
|
$handlerStack = $this->guzzle->getConfig('handler');
|
||||||
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
|
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
@ -191,7 +192,7 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIfConsumerKeyIsReplace()
|
public function testIfConsumerKeyIsReplace()
|
||||||
{
|
{
|
||||||
$handlerStack = $this->client->getConfig('handler');
|
$handlerStack = $this->guzzle->getConfig('handler');
|
||||||
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
|
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
@ -221,10 +222,10 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testInvalidApplicationKey()
|
public function testInvalidApplicationKey()
|
||||||
{
|
{
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
'\GuzzleHttp\Exception\ClientException'
|
'Http\Client\Exception\HttpException'
|
||||||
);
|
);
|
||||||
|
|
||||||
$handlerStack = $this->client->getConfig('handler');
|
$handlerStack = $this->guzzle->getConfig('handler');
|
||||||
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
|
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
@ -254,10 +255,10 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testInvalidRight()
|
public function testInvalidRight()
|
||||||
{
|
{
|
||||||
$this->setExpectedException(
|
$this->setExpectedException(
|
||||||
'\GuzzleHttp\Exception\ClientException'
|
'Http\Client\Exception\HttpException'
|
||||||
);
|
);
|
||||||
|
|
||||||
$handlerStack = $this->client->getConfig('handler');
|
$handlerStack = $this->guzzle->getConfig('handler');
|
||||||
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
$handlerStack->push(Middleware::mapResponse(function (Response $response) {
|
||||||
|
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
@ -288,7 +289,7 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetQueryArgs()
|
public function testGetQueryArgs()
|
||||||
{
|
{
|
||||||
$handlerStack = $this->client->getConfig('handler');
|
$handlerStack = $this->guzzle->getConfig('handler');
|
||||||
$handlerStack->push(Middleware::mapRequest(function (Request $request) {
|
$handlerStack->push(Middleware::mapRequest(function (Request $request) {
|
||||||
if($request->getUri()->getPath() == "/1.0/auth/time") {
|
if($request->getUri()->getPath() == "/1.0/auth/time") {
|
||||||
return $request;
|
return $request;
|
||||||
@ -313,7 +314,7 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetOverlappingQueryArgs()
|
public function testGetOverlappingQueryArgs()
|
||||||
{
|
{
|
||||||
$handlerStack = $this->client->getConfig('handler');
|
$handlerStack = $this->guzzle->getConfig('handler');
|
||||||
$handlerStack->push(Middleware::mapRequest(function (Request $request) {
|
$handlerStack->push(Middleware::mapRequest(function (Request $request) {
|
||||||
if($request->getUri()->getPath() == "/1.0/auth/time") {
|
if($request->getUri()->getPath() == "/1.0/auth/time") {
|
||||||
return $request;
|
return $request;
|
||||||
@ -338,7 +339,7 @@ class ApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetBooleanQueryArgs()
|
public function testGetBooleanQueryArgs()
|
||||||
{
|
{
|
||||||
$handlerStack = $this->client->getConfig('handler');
|
$handlerStack = $this->guzzle->getConfig('handler');
|
||||||
$handlerStack->push(Middleware::mapRequest(function (Request $request) {
|
$handlerStack->push(Middleware::mapRequest(function (Request $request) {
|
||||||
if($request->getUri()->getPath() == "/1.0/auth/time") {
|
if($request->getUri()->getPath() == "/1.0/auth/time") {
|
||||||
return $request;
|
return $request;
|
||||||
|
Loading…
Reference in New Issue
Block a user