From fd63dd72a9b0329ca050de7ded315eb12c862a4c Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Wed, 19 Jun 2019 14:29:58 +0100 Subject: [PATCH 01/13] Update to Guzzle v6 + Minimum PHP version to 5.5 --- composer.json | 7 +- spec/Judopay/ConfigurationSpec.php | 2 +- spec/Judopay/Model/CollectionSpec.php | 1 - spec/Judopay/Model/ModelObjectBehavior.php | 2 +- spec/Judopay/ModelSpec.php | 1 - spec/Judopay/RequestSpec.php | 14 +- spec/JudopaySpec.php | 1 - spec/SpecHelper.php | 139 ++++++++++++------ src/Judopay.php | 17 ++- src/Judopay/Configuration.php | 37 ++--- src/Judopay/Exception/ApiException.php | 36 +++-- src/Judopay/Model.php | 31 +++- src/Judopay/Model/WebPayments/Transaction.php | 3 +- src/Judopay/Request.php | 135 +++++++++-------- tests/Builders/AbstractModelBuilder.php | 12 +- 15 files changed, 269 insertions(+), 169 deletions(-) diff --git a/composer.json b/composer.json index af9f5d2..8ce5fd3 100644 --- a/composer.json +++ b/composer.json @@ -16,13 +16,14 @@ "repositories": [ ], "require": { - "php": ">=5.4", - "guzzlehttp/guzzle": "~5.0", + "php": ">=5.5", + "guzzlehttp/guzzle": "~6.0", "monolog/monolog": "~1.10", "pimple/pimple": "~3.0", "curl/curl" : ">=0.0.0", "ext-curl": ">=0.0.0", - "ext-openssl": ">=0.0.0" + "ext-openssl": ">=0.0.0", + "ext-json": "*" }, "require-dev": { "phpspec/phpspec": "^2.0", diff --git a/spec/Judopay/ConfigurationSpec.php b/spec/Judopay/ConfigurationSpec.php index e3eb926..f3d00d9 100644 --- a/spec/Judopay/ConfigurationSpec.php +++ b/spec/Judopay/ConfigurationSpec.php @@ -18,7 +18,7 @@ public function it_sets_the_correct_endpoint_url() $this->beConstructedWith(array('useProduction' => true)); /** @var Configuration|ConfigurationSpec $this */ - $this->get('endpointUrl')->shouldBe('https://gw1.judopay.com'); + $this->get('endpointUrl')->shouldBe('https://gw1.judopay.com/'); } public function it_should_allow_a_custom_api_version_to_be_set() diff --git a/spec/Judopay/Model/CollectionSpec.php b/spec/Judopay/Model/CollectionSpec.php index cace64e..f50710a 100644 --- a/spec/Judopay/Model/CollectionSpec.php +++ b/spec/Judopay/Model/CollectionSpec.php @@ -3,7 +3,6 @@ namespace spec\Judopay\Model; use Judopay\Model\Collection; -use Tests\Builders\CardPaymentBuilder; use Tests\Builders\GetTransactionBuilder; use Tests\Builders\RefundBuilder; diff --git a/spec/Judopay/Model/ModelObjectBehavior.php b/spec/Judopay/Model/ModelObjectBehavior.php index 78f672e..d4e7885 100644 --- a/spec/Judopay/Model/ModelObjectBehavior.php +++ b/spec/Judopay/Model/ModelObjectBehavior.php @@ -20,7 +20,7 @@ protected function concoctRequest($fixtureFile) { $request = new Request($this->configuration); - $mockClient = SpecHelper::getMockResponseClient( + $mockClient = SpecHelper::getMockResponseClientFromFixture( 200, $fixtureFile ); diff --git a/spec/Judopay/ModelSpec.php b/spec/Judopay/ModelSpec.php index 568a032..01cc13f 100644 --- a/spec/Judopay/ModelSpec.php +++ b/spec/Judopay/ModelSpec.php @@ -5,7 +5,6 @@ use Judopay\Request; use spec\SpecHelper; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; class ModelSpec extends ObjectBehavior { diff --git a/spec/Judopay/RequestSpec.php b/spec/Judopay/RequestSpec.php index 6c70a02..29f06f5 100644 --- a/spec/Judopay/RequestSpec.php +++ b/spec/Judopay/RequestSpec.php @@ -2,7 +2,7 @@ namespace spec\Judopay; -use GuzzleHttp\Message\Request; +use GuzzleHttp\Psr7\Request; use PHPUnit\Framework\Assert; use spec\SpecHelper; use PhpSpec\ObjectBehavior; @@ -25,14 +25,16 @@ public function it_sends_the_right_authorization_header_for_oauth2() // Create a request $this->beConstructedWith($config); - $request = new Request('get', 'http://example.com'); - /** @var \Judopay\Request $this */ - // Add the auth information to the request - $requestWithAuth = $this->setRequestAuthentication($request); + $headers = $this->getHeaders(); + $request = new Request( + 'get', + 'http://example.com', + $headers->getWrappedObject() + ); // Make sure the Authorization header is correct - Assert::assertEquals('Bearer '.$oauthAccessToken, $request->getHeader('Authorization')); + Assert::assertEquals('Bearer '.$oauthAccessToken, $request->getHeader('Authorization')[0]); } public function getMatchers() diff --git a/spec/JudopaySpec.php b/spec/JudopaySpec.php index 12bac8d..d071355 100644 --- a/spec/JudopaySpec.php +++ b/spec/JudopaySpec.php @@ -3,7 +3,6 @@ namespace spec; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; class JudopaySpec extends ObjectBehavior { diff --git a/spec/SpecHelper.php b/spec/SpecHelper.php index b14032a..3997fae 100644 --- a/spec/SpecHelper.php +++ b/spec/SpecHelper.php @@ -2,77 +2,124 @@ namespace spec; -use GuzzleHttp\Client; -use GuzzleHttp\Event\EmitterInterface; -use GuzzleHttp\Event\SubscriberInterface; -use GuzzleHttp\Message\Response; -use GuzzleHttp\Message\ResponseInterface; -use GuzzleHttp\Subscriber\Mock; use Judopay\Configuration; -use GuzzleHttp\Stream\Stream; -use GuzzleHttp\Subscriber\History; - +use GuzzleHttp\Client; +use GuzzleHttp\Handler\MockHandler; +use GuzzleHttp\HandlerStack; +use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Psr7\Request; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Middleware; +use GuzzleHttp\Psr7; + + +/* + * Test the client without sending the requests + */ class SpecHelper { - public static function getMockResponse($responseCode, $responseBody = null) + /** + * Returns a mock configuration + */ + public static function getConfiguration() { - $mockResponse = new Response($responseCode, null, $responseBody); + $configuration = new Configuration( + array( + 'apiToken' => 'token', + 'apiSecret' => 'secret', + 'judoId' => '123-456', + ) + ); - return $mockResponse; + return $configuration; } - public static function getMockResponseFromFixture($responseCode, $fixtureFile = null) + /** + * Creates a mock Handler with a response in the queue + * @param $mockResponse + * @return HandlerStack + */ + public static function getMockResponseHandler($mockResponse) { - $fixtureContent = null; - if (!empty($fixtureFile)) { - $fixtureContent = file_get_contents(__DIR__.'/fixtures/'.$fixtureFile); - } + $mock = new MockHandler([$mockResponse]); + $handler = HandlerStack::create($mock); + + return $handler; + } + + /** + * Creates a mock client with the provided body + * @param $responseCode + * @param $responseBody + * @return Client + */ + public static function getMockResponseClientFromBody($responseCode, $responseBody) + { + // Create the response + $mockResponse = SpecHelper::getBodyResponse($responseCode, $responseBody); + + // Create the handler with a response + $handlerStack = SpecHelper::getMockResponseHandler($mockResponse); + + $container = []; + $history = Middleware::history($container); + + // Add the history middleware to the handler stack. + $handlerStack->push($history); + + return new Client(['handler' => $handlerStack]); + } - $stream = Stream::factory($fixtureContent); + public static function getBodyResponse($responseCode, $responseBody = null) + { $mockResponse = new Response( - $responseCode, // statusCode - [], // headers - $stream // StreamInterface body + $responseCode, + $responseBody ); return $mockResponse; } - public static function getMockResponseClient($responseCode, $fixtureFile) + /** + * Creates a mock client with the provided fixture + * @param $responseCode + * @param $fixtureFile + * @return Client + */ + public static function getMockResponseClientFromFixture($responseCode, $fixtureFile) { - $client = new Client(); + // Create the response + $mockResponse = SpecHelper::getFixtureResponse($responseCode, $fixtureFile); - $history = new History(); - $client->getEmitter()->attach($history); + // Create the handler with a response + $handlerStack = SpecHelper::getMockResponseHandler($mockResponse); - $mock = new Mock(); + $container = []; + $history = Middleware::history($container); - // Preparing the response for the client - /* @var $mockResponse ResponseInterface */ - $mockResponse = SpecHelper::getMockResponseFromFixture($responseCode, $fixtureFile); - $mock->addResponse($mockResponse); + // Add the history middleware to the handler stack. + $handlerStack->push($history); - // Guzzle event emitter (onBefore) - /** @var EmitterInterface $emitter*/ - $emitter = $client->getEmitter(); - - // Attach the mock to the emitter - $emitter->attach($mock); - - return $client; + return new Client(['handler' => $handlerStack]); } - public static function getConfiguration() + public static function getFixtureResponse($responseCode, $fixtureFile = null) { - $configuration = new Configuration( - array( - 'apiToken' => 'token', - 'apiSecret' => 'secret', - 'judoId' => '123-456', - ) + $fixtureContent = null; + if (!empty($fixtureFile)) { + $fixtureContent = file_get_contents(__DIR__.'/fixtures/'.$fixtureFile); + } + + $stream = Psr7\stream_for($fixtureContent); + + $mockResponse = new Response( + $responseCode, // statusCode + [], // headers + $stream // StreamInterface body ); - return $configuration; + return $mockResponse; } + } diff --git a/src/Judopay.php b/src/Judopay.php index 505c6cb..2a917fa 100644 --- a/src/Judopay.php +++ b/src/Judopay.php @@ -2,6 +2,8 @@ use Judopay\Configuration; use Pimple\Container; +use Judopay\Client; +use Judopay\Request; /** * Main Judopay wrapper @@ -10,8 +12,8 @@ */ class Judopay { - const SDK_VERSION = '2.2.0'; - const API_VERSION = '5.5.0'; + const SDK_VERSION = '4.0.0'; + const API_VERSION = '5.5.1'; /** * Pimple DI container * @var object Pimple\Container @@ -36,8 +38,15 @@ public function __construct($settings = null) function ($c) { /** @var Configuration $configuration */ $configuration = $c['configuration']; - $request = new \Judopay\Request($configuration); - $request->setClient(new \Judopay\Client()); + $request = new Request($configuration); + + // The client is now immutable and needs all the options on creation + $client = new Client([ + 'base_uri' => 'http://httpbin.org', // Base URI is used with relative requests + 'verify' => __DIR__.'/../cert/digicert_sha256_ca.pem' + ]); + + $request->setClient($client); return $request; } diff --git a/src/Judopay/Configuration.php b/src/Judopay/Configuration.php index 4d61b11..2b639bb 100644 --- a/src/Judopay/Configuration.php +++ b/src/Judopay/Configuration.php @@ -2,6 +2,7 @@ namespace Judopay; +use Judopay; use Judopay\Exception\ValidationError; use Psr\Log\NullLogger; @@ -9,28 +10,28 @@ class Configuration { const ENDPOINT_URL = 'endpointUrl'; const USE_PRODUCTION = 'useProduction'; + protected $settings = array(); - protected $valid_config_keys - = array( - 'apiVersion', - 'apiToken', - 'apiSecret', - 'oauthAccessToken', - 'format', - self::ENDPOINT_URL, - 'userAgent', - 'judoId', - self::USE_PRODUCTION, - 'logger', - 'httpLogFormat', - ); + protected $valid_config_keys = array( + 'apiVersion', + 'apiToken', + 'apiSecret', + 'oauthAccessToken', + 'format', + self::ENDPOINT_URL, + 'userAgent', + 'judoId', + self::USE_PRODUCTION, + 'logger', + 'httpLogFormat', + ); public function __construct($settings = null) { // Set sensible defaults - $this->settings['apiVersion'] = \Judopay::API_VERSION; + $this->settings['apiVersion'] = Judopay::API_VERSION; $this->settings['logger'] = new NullLogger(); - $this->settings['userAgent'] = 'Judopay PHP v'.phpversion().' SDK v'.\Judopay::SDK_VERSION; + $this->settings['userAgent'] = 'Judopay PHP v'.phpversion().' SDK v'.Judopay::SDK_VERSION; $this->settings['httpLogFormat'] = "\"{method} {resource} {protocol}/{version}\" ". "{code} Content-Length: {res_header_Content-Length}\n| Response: {response}"; @@ -94,8 +95,8 @@ protected function setEndpointUrl() } else { $this->settings[static::ENDPOINT_URL] = isset($this->settings[static::USE_PRODUCTION]) && $this->settings[static::USE_PRODUCTION] === true - ? 'https://gw1.judopay.com' - : 'https://gw1.judopay-sandbox.com'; + ? 'https://gw1.judopay.com/' + : 'https://gw1.judopay-sandbox.com/'; } } diff --git a/src/Judopay/Exception/ApiException.php b/src/Judopay/Exception/ApiException.php index 74c77e4..7d22082 100644 --- a/src/Judopay/Exception/ApiException.php +++ b/src/Judopay/Exception/ApiException.php @@ -2,10 +2,11 @@ namespace Judopay\Exception; -use GuzzleHttp\Message\ResponseInterface; +use GuzzleHttp\Exception\BadResponseException; use Judopay\Helper\ArrayHelper; +use RuntimeException; -class ApiException extends \RuntimeException +class ApiException extends RuntimeException { const MESSAGE = 'JudoPay ApiException (status code %d, error code %d, category %d) %s%s'; const CATEGORY_UNKNOWN = 0; @@ -23,12 +24,21 @@ class ApiException extends \RuntimeException /** * Factory method - * @param ResponseInterface $response + * @param BadResponseException $exception * @return static */ - public static function factory(ResponseInterface $response) + public static function factory($exception) { - $parsedBody = $response->json(); + $response = $exception->getResponse(); + $responseBody= $response->getBody(); + + // Read the Psr7\Stream + $responseBodyAsString = $responseBody->getContents(); + + $statusCode = $exception->getCode(); + + // Parse the response in an array + $parsedBody = json_decode($responseBodyAsString, true); $category = ArrayHelper::get( $parsedBody, @@ -36,9 +46,17 @@ public static function factory(ResponseInterface $response) static::CATEGORY_UNKNOWN ); - $message = ArrayHelper::get($parsedBody, 'message', get_called_class()); + $message = ArrayHelper::get( + $parsedBody, + 'message', + get_called_class() + ); - $errorCode = ArrayHelper::get($parsedBody, 'code', 0); + $errorCode = ArrayHelper::get( + $parsedBody, + 'code', + 0 + ); $fieldErrors = array(); @@ -60,8 +78,6 @@ public static function factory(ResponseInterface $response) } } - $statusCode = $response->getStatusCode(); - return new static( $message, $errorCode, @@ -91,6 +107,8 @@ public function __construct( $this->statusCode = $statusCode; $this->category = $category; $this->fieldErrors = $fieldErrors; + + parent::__construct(); } /** diff --git a/src/Judopay/Model.php b/src/Judopay/Model.php index e3ff60c..347feeb 100644 --- a/src/Judopay/Model.php +++ b/src/Judopay/Model.php @@ -3,6 +3,7 @@ namespace Judopay; use Judopay\Exception\ValidationError; +use GuzzleHttp\Psr7\Response; /** * Base model class @@ -51,6 +52,21 @@ public function __construct(Request $request) $this->request = $request; } + /** + * Transforms the Guzzle Response to an Array + * @param Response $guzzleResponse + * @return array + **/ + public function getResponseArray($guzzleResponse) + { + // Read the Psr7\Stream + $responseBody = $guzzleResponse->getBody(); + $responseBodyAsString = $responseBody->getContents(); + + // Parse the response to Json + return json_decode($responseBodyAsString, true); + } + /** * Retrieve a list of records * @param int $offset The start point in the sorted list of records from which the results set will start @@ -72,10 +88,9 @@ public function all($offset = 0, $pageSize = 10, $sort = 'time-descending') $response = $this->request->get( $uri - // No attributes ); - return $response->json(); + return $this->getResponseArray($response); } /** @@ -88,9 +103,11 @@ public function find($resourceId) { $this->checkApiMethodIsSupported(__FUNCTION__); - return $this->request - ->get($this->resourcePath.'/'.(int)$resourceId) - ->json(); + $response = $this->request->get( + $this->resourcePath.'/'.(int)$resourceId + ); + + return $this->getResponseArray($response); } /** @@ -108,7 +125,7 @@ public function create() $this->attributeValues ); - return $response->json(); + return $this->getResponseArray($response); } /** @@ -128,7 +145,7 @@ public function validate() $this->attributeValues ); - return $response->json(); + return $this->getResponseArray($response); } /** diff --git a/src/Judopay/Model/WebPayments/Transaction.php b/src/Judopay/Model/WebPayments/Transaction.php index 12a9659..e92c9c2 100644 --- a/src/Judopay/Model/WebPayments/Transaction.php +++ b/src/Judopay/Model/WebPayments/Transaction.php @@ -16,6 +16,7 @@ class Transaction extends Model **/ public function find($reference) { - return $this->request->get($this->resourcePath.'/'.$reference)->json(); + $response = $this->request->get($this->resourcePath.'/'.$reference); + return $this->getResponseArray($response); } } diff --git a/src/Judopay/Request.php b/src/Judopay/Request.php index f25a379..50c2886 100644 --- a/src/Judopay/Request.php +++ b/src/Judopay/Request.php @@ -2,13 +2,13 @@ namespace Judopay; -use GuzzleHttp\Client; use GuzzleHttp\Exception\BadResponseException; -use GuzzleHttp\Message\FutureResponse; -use GuzzleHttp\Message\Request as GuzzleRequest; -use GuzzleHttp\Ring\Future\FutureArray; +use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Client; +use GuzzleHttp\Exception\GuzzleException; use Judopay\Exception\ApiException; + class Request { /** @var Configuration */ @@ -16,7 +16,6 @@ class Request /** @var Client */ protected $client; - public function __construct(Configuration $configuration) { $this->configuration = $configuration; @@ -25,77 +24,99 @@ public function __construct(Configuration $configuration) public function setClient(Client $client) { $this->client = $client; + } - // Set SSL connection - $this->client->setDefaultOption( - 'verify', - __DIR__.'/../../cert/digicert_sha256_ca.pem' - ); + /** + * Sets the headers and the authentication + * @return array + */ + public function getHeaders() + { + return [ + 'api-version' => $this->configuration->get('apiVersion'), + 'Accept' => 'application/json; charset=utf-8', + 'Content-Type' => 'application/json', + 'User-Agent' => $this->configuration->get('userAgent'), + 'Authorization' => $this->getRequestAuthenticationHeader() + ]; } /** * Make a GET request to the specified resource path * @param string $resourcePath * @throws ApiException - * @return FutureArray|FutureResponse + * @return Response */ public function get($resourcePath) { - $endpointUrl = $this->configuration->get('endpointUrl'); + $headers = $this->getHeaders(); - $request = $this->client->createRequest( - 'GET', - $endpointUrl.'/'.$resourcePath, - [ - 'json' => null - ] - ); + try { + $guzzleResponse = $this->client->request( + 'GET', + $resourcePath, + [ + 'headers' => $headers + ] + ); + } + catch (BadResponseException $e){ + throw ApiException::factory($e); + } + catch (GuzzleException $e){ + throw new ApiException($e->getMessage()); + } - return $this->send($request); + return $guzzleResponse; } /** - * Make a POST request to the specified resource path + * Make a POST request to the specified resource path and the provided data * @param string $resourcePath - * @param array $data - * @return FutureArray|FutureResponse + * @param array $data + * @return Response */ public function post($resourcePath, $data) { - $endpointUrl = $this->configuration->get('endpointUrl'); - - $request = $this->client->createRequest( - 'POST', - $endpointUrl.'/'.$resourcePath, - [ - 'json' => $data - ] - ); + $headers = $this->getHeaders(); - return $this->send($request); - } + try { + $guzzleResponse = $this->client->request( + 'POST', + $resourcePath, + [ + 'headers' => $headers, + 'json' => $data + ] + ); + } + catch (BadResponseException $e){ + throw ApiException::factory($e); + } + catch (GuzzleException $e){ + throw new ApiException($e->getMessage()); + } - public function setRequestHeaders(GuzzleRequest $request) - { - $request->setHeader('api-version', $this->configuration->get('apiVersion')); - $request->setHeader('Accept', 'application/json; charset=utf-8'); - $request->setHeader('Content-Type', 'application/json'); - $request->setHeader('User-Agent', $this->configuration->get('userAgent')); + return $guzzleResponse; } - public function setRequestAuthentication(GuzzleRequest $request) + /* + * Gets 'Authorization' header value + */ + private function getRequestAuthenticationHeader() { + // Make sure we have all the required fields $this->configuration->validate(); $oauthAccessToken = $this->configuration->get('oauthAccessToken'); // Do we have an oAuth2 access token? if (!empty($oauthAccessToken)) { - $request->setHeader('Authorization', 'Bearer ' . $oauthAccessToken); - } else { - // Otherwise, use basic authentication - $basicAuth = $this->configuration->get('apiToken'). ":" . $this->configuration->get('apiSecret'); - $request->setHeader('Authorization', 'Basic ' . base64_encode($basicAuth)); + return 'Bearer ' . $oauthAccessToken; } + + // Otherwise, use basic authentication + $basicAuth = $this->configuration->get('apiToken'). ":" . $this->configuration->get('apiSecret'); + return 'Basic ' . base64_encode($basicAuth); } /** @@ -106,26 +127,4 @@ public function getConfiguration() { return $this->configuration; } - - /** - * @param GuzzleRequest $guzzleRequest - * @throws ApiException - * @return FutureArray|FutureResponse - */ - protected function send(GuzzleRequest $guzzleRequest) - { - $this->setRequestHeaders($guzzleRequest); - $this->setRequestAuthentication($guzzleRequest); - - try { - $guzzleResponse = $this->client->send($guzzleRequest); - } catch (BadResponseException $e) { - // Guzzle throws an exception when it encounters a 4xx or 5xx error - // Rethrow the exception so we can raise our custom exception classes - throw ApiException::factory($e->getResponse()); - } - - - return $guzzleResponse; - } } diff --git a/tests/Builders/AbstractModelBuilder.php b/tests/Builders/AbstractModelBuilder.php index 9342fdb..a62d8e1 100644 --- a/tests/Builders/AbstractModelBuilder.php +++ b/tests/Builders/AbstractModelBuilder.php @@ -21,14 +21,22 @@ abstract class AbstractModelBuilder /** * Create a new model object with attributes set - * @param Configuration $configuration + * @param Configuration $configuration> * @return Model Model object */ public function build(Configuration $configuration = null) { + // Token - Secret - JudoId part of the configuration $this->compile(); $request = new Request($configuration ?: new Configuration()); - $request->setClient(new Client()); + + $client = new Client([ + // Base URI is used with relative requests + 'base_uri' => $configuration->get("endpointUrl"), + 'verify' => __DIR__.'/../../cert/digicert_sha256_ca.pem' + ]); + + $request->setClient($client); $modelName = '\Judopay\Model\\'.substr(get_class($this), 15, -7); From 64b70b7671528ada2974dbbbcf16ae9b06d9610d Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Wed, 19 Jun 2019 14:39:56 +0100 Subject: [PATCH 02/13] Removed PHP 5.4 test + phpcbf fix --- .travis.yml | 1 - spec/SpecHelper.php | 2 -- src/Judopay/Request.php | 13 ++++--------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9ef11b1..740bfab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: php php: - - 5.4 - 5.5 - 5.6 - 7.0 diff --git a/spec/SpecHelper.php b/spec/SpecHelper.php index 3997fae..51ba6c5 100644 --- a/spec/SpecHelper.php +++ b/spec/SpecHelper.php @@ -12,7 +12,6 @@ use GuzzleHttp\Middleware; use GuzzleHttp\Psr7; - /* * Test the client without sending the requests */ @@ -121,5 +120,4 @@ public static function getFixtureResponse($responseCode, $fixtureFile = null) return $mockResponse; } - } diff --git a/src/Judopay/Request.php b/src/Judopay/Request.php index 50c2886..b436558 100644 --- a/src/Judopay/Request.php +++ b/src/Judopay/Request.php @@ -8,7 +8,6 @@ use GuzzleHttp\Exception\GuzzleException; use Judopay\Exception\ApiException; - class Request { /** @var Configuration */ @@ -59,11 +58,9 @@ public function get($resourcePath) 'headers' => $headers ] ); - } - catch (BadResponseException $e){ + } catch (BadResponseException $e) { throw ApiException::factory($e); - } - catch (GuzzleException $e){ + } catch (GuzzleException $e) { throw new ApiException($e->getMessage()); } @@ -89,11 +86,9 @@ public function post($resourcePath, $data) 'json' => $data ] ); - } - catch (BadResponseException $e){ + } catch (BadResponseException $e) { throw ApiException::factory($e); - } - catch (GuzzleException $e){ + } catch (GuzzleException $e) { throw new ApiException($e->getMessage()); } From 64dd2650d634f7ecb31bf65140053faa1123dff9 Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Wed, 19 Jun 2019 14:59:31 +0100 Subject: [PATCH 03/13] dist: trusty to support old PHP versions --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 740bfab..e378e86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,6 @@ php: - 7.0 - 7.2 script: ./code_check.sh +dist: trusty install: - composer install \ No newline at end of file From acdea845cc8ca0d84383623f9e5e6adaaa29ee78 Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Wed, 19 Jun 2019 15:15:36 +0100 Subject: [PATCH 04/13] removed cURL as not used by Guzzle6 --- composer.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/composer.json b/composer.json index 8ce5fd3..dc2d1c9 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,6 @@ "guzzlehttp/guzzle": "~6.0", "monolog/monolog": "~1.10", "pimple/pimple": "~3.0", - "curl/curl" : ">=0.0.0", - "ext-curl": ">=0.0.0", "ext-openssl": ">=0.0.0", "ext-json": "*" }, From b6d9bc52dc341806d6a0c96a973838a3d6bf1487 Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Wed, 19 Jun 2019 15:31:43 +0100 Subject: [PATCH 05/13] Trying to use specific curl packages --- .travis.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e378e86..3274e20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,21 @@ language: php + php: - 5.5 - 5.6 - 7.0 - 7.2 -script: ./code_check.sh + +sudo: required + dist: trusty -install: - - composer install \ No newline at end of file + +before_install: sudo apt-get -y install git zip php5-cli php5-curl +install: composer install + +before_script: + - php -r "printf('PHP %s', phpversion());" + - composer self-update + - composer install --no-interaction + +script: ./code_check.sh \ No newline at end of file From 360c4fc49cb06bd2ada66c2e99dd49602c5d0323 Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Wed, 19 Jun 2019 15:38:40 +0100 Subject: [PATCH 06/13] Back to xenial --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3274e20..24654ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,9 +8,8 @@ php: sudo: required -dist: trusty +dist: xenial -before_install: sudo apt-get -y install git zip php5-cli php5-curl install: composer install before_script: From 79f6d702f2c265e053f15e2caf4625a392627056 Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Wed, 19 Jun 2019 15:43:55 +0100 Subject: [PATCH 07/13] Trying precise --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 24654ac..3960b09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ php: sudo: required -dist: xenial +dist: precise install: composer install From 4ed12a2c1a9badfef899d83d7967dab53802ca48 Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Wed, 19 Jun 2019 15:54:17 +0100 Subject: [PATCH 08/13] use the standard Ubuntu Trusty php5-cli and php5-curl packages --- .travis.yml | 3 +++ composer.json | 3 ++- tests/Helpers/ConfigHelper.php | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3960b09..4563396 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,9 @@ sudo: required dist: precise +before_install: + - sudo apt-get -y install git zip php5-cli php5-curl + install: composer install before_script: diff --git a/composer.json b/composer.json index dc2d1c9..d752e3f 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ "monolog/monolog": "~1.10", "pimple/pimple": "~3.0", "ext-openssl": ">=0.0.0", - "ext-json": "*" + "ext-json": "*", + "ext-curl": "*" }, "require-dev": { "phpspec/phpspec": "^2.0", diff --git a/tests/Helpers/ConfigHelper.php b/tests/Helpers/ConfigHelper.php index f595eb3..2db5ffa 100644 --- a/tests/Helpers/ConfigHelper.php +++ b/tests/Helpers/ConfigHelper.php @@ -4,6 +4,10 @@ use Judopay\Configuration; +if (getenv('TRAVIS')) { + $options['curl'][CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1_1; +} + class ConfigHelper { /** From 7f21ed25aa30755382a75ae5e7cf998c80e022a2 Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Wed, 19 Jun 2019 16:04:33 +0100 Subject: [PATCH 09/13] Setting up CURL when retrieving config --- tests/Helpers/ConfigHelper.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/Helpers/ConfigHelper.php b/tests/Helpers/ConfigHelper.php index 2db5ffa..d662da2 100644 --- a/tests/Helpers/ConfigHelper.php +++ b/tests/Helpers/ConfigHelper.php @@ -4,10 +4,6 @@ use Judopay\Configuration; -if (getenv('TRAVIS')) { - $options['curl'][CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1_1; -} - class ConfigHelper { /** @@ -17,6 +13,10 @@ class ConfigHelper */ public static function getConfig(array $settings = array()) { + if (getenv('TRAVIS')) { + $options['curl'][CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1_1; + } + return new Configuration( $settings + array( @@ -35,6 +35,10 @@ public static function getConfig(array $settings = array()) */ public static function getConfigAlt(array $settings = array()) { + if (getenv('TRAVIS')) { + $options['curl'][CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1_1; + } + return new Configuration( $settings + array( @@ -54,6 +58,10 @@ public static function getConfigAlt(array $settings = array()) */ public static function getConfigFromList(array $credentials, array $settings = array()) { + if (getenv('TRAVIS')) { + $options['curl'][CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1_1; + } + return new Configuration( array( 'judoId' => $credentials[0], From 321efe543d2b0fb908a8de2ff8025a4808e14e78 Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Wed, 19 Jun 2019 16:34:15 +0100 Subject: [PATCH 10/13] Dist trusty --- .travis.yml | 7 +------ tests/Helpers/ConfigHelper.php | 12 ------------ 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4563396..6803027 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,12 +6,7 @@ php: - 7.0 - 7.2 -sudo: required - -dist: precise - -before_install: - - sudo apt-get -y install git zip php5-cli php5-curl +dist: trusty install: composer install diff --git a/tests/Helpers/ConfigHelper.php b/tests/Helpers/ConfigHelper.php index d662da2..f595eb3 100644 --- a/tests/Helpers/ConfigHelper.php +++ b/tests/Helpers/ConfigHelper.php @@ -13,10 +13,6 @@ class ConfigHelper */ public static function getConfig(array $settings = array()) { - if (getenv('TRAVIS')) { - $options['curl'][CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1_1; - } - return new Configuration( $settings + array( @@ -35,10 +31,6 @@ public static function getConfig(array $settings = array()) */ public static function getConfigAlt(array $settings = array()) { - if (getenv('TRAVIS')) { - $options['curl'][CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1_1; - } - return new Configuration( $settings + array( @@ -58,10 +50,6 @@ public static function getConfigAlt(array $settings = array()) */ public static function getConfigFromList(array $credentials, array $settings = array()) { - if (getenv('TRAVIS')) { - $options['curl'][CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1_1; - } - return new Configuration( array( 'judoId' => $credentials[0], From 4340b1d1cdad02fd3ea7c7ce7e4658815e5b894f Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Wed, 19 Jun 2019 16:47:40 +0100 Subject: [PATCH 11/13] xenial --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6803027..c139d06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ php: - 7.0 - 7.2 -dist: trusty +dist: xenial install: composer install From c70ba9742430a77ac1c5f7bca65605e4456bb6ef Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Wed, 19 Jun 2019 17:03:17 +0100 Subject: [PATCH 12/13] Dropping 5.5 and adding new recent versions --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c139d06..27be61f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ language: php php: - - 5.5 - 5.6 - 7.0 + - 7.1 - 7.2 + - 7.3 dist: xenial From ddc6cc277637cf5009d1336de44dcceca7b1c904 Mon Sep 17 00:00:00 2001 From: Christophe Surun <32509095+chrisurun@users.noreply.github.com> Date: Thu, 20 Jun 2019 09:20:15 +0100 Subject: [PATCH 13/13] Update AbstractModelBuilder.php --- tests/Builders/AbstractModelBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Builders/AbstractModelBuilder.php b/tests/Builders/AbstractModelBuilder.php index a62d8e1..4f2149e 100644 --- a/tests/Builders/AbstractModelBuilder.php +++ b/tests/Builders/AbstractModelBuilder.php @@ -21,7 +21,7 @@ abstract class AbstractModelBuilder /** * Create a new model object with attributes set - * @param Configuration $configuration> + * @param Configuration $configuration * @return Model Model object */ public function build(Configuration $configuration = null)