Skip to content

Commit f9eb75a

Browse files
feature/DTSERWONE-1083 - V4 Support php versions (#117)
* DTSERWONE-1083 - Enhanced the PHP-SDK to support PHP version build from 5.6 to 8.1 Introduce Hyperwallet URI Template Introduce GitHubAction to test PHP version from 5.6 to latest Address PHP Unit test compatibility
1 parent 5372f7a commit f9eb75a

20 files changed

+260
-48
lines changed

.github/workflows/ci.yml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: PHP SDK CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- master
8+
- support/SDK-V3
9+
- feature/**
10+
- bugfix/**
11+
pull_request:
12+
branches:
13+
- master
14+
- support/SDK-V3
15+
- feature/**
16+
- bugfix/**
17+
18+
jobs:
19+
tests:
20+
name: Tests
21+
runs-on: ${{ matrix.operating-system }}
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
operating-system: ['ubuntu-latest']
26+
php-versions: ['5.6', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
27+
28+
steps:
29+
- uses: actions/checkout@master
30+
31+
- name: Setup PHP
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: ${{ matrix.php-versions }}
35+
coverage: xdebug
36+
37+
- name: Validate composer.json and composer.lock
38+
run: composer validate
39+
40+
- name: Install dependencies
41+
run: composer install --prefer-dist --no-progress --no-suggest
42+
43+
- name: Run test suite
44+
run: |
45+
php --version
46+
./vendor/bin/phpunit -v
47+
48+
code-coverage:
49+
name: Report code coverage
50+
runs-on: ${{ matrix.operating-system }}
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
operating-system: [ 'ubuntu-latest' ]
55+
php-versions: [ '5.6' ]
56+
57+
steps:
58+
- uses: actions/checkout@master
59+
60+
- name: Setup PHP
61+
uses: shivammathur/setup-php@v2
62+
with:
63+
php-version: ${{ matrix.php-versions }}
64+
coverage: xdebug
65+
66+
- name: Validate composer.json and composer.lock
67+
run: composer validate
68+
69+
- name: Install dependencies
70+
run: composer install --prefer-dist --no-progress --no-suggest
71+
72+
- name: Run test suite
73+
run: |
74+
php --version
75+
./vendor/bin/phpunit -v
76+
77+
- name: Upload coverage results to Coveralls
78+
env:
79+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
run: ./vendor/bin/php-coveralls -v --exclude-no-stmt

composer.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"creditcard",
1212
"ach"
1313
],
14-
"homepage": "http://hyperwallet.github.io/php-sdk",
14+
"homepage": "https://github.com/hyperwallet/php-sdk",
1515
"license": "MIT",
1616
"authors": [
1717
{
@@ -20,9 +20,9 @@
2020
}
2121
],
2222
"require": {
23-
"php": ">=5.5.9",
23+
"php": ">=5.6.0",
24+
"ext-json": "*",
2425
"guzzlehttp/guzzle": "^6.2.1 || ^7.0.1",
25-
"guzzlehttp/uri-template": "^0",
2626
"phpseclib/phpseclib": "^2.0.11",
2727
"gree/jose": "^2.2.1"
2828
},
@@ -33,9 +33,9 @@
3333
"psr-4": { "Hyperwallet\\Tests\\" : "tests/Hyperwallet/Tests", "ComposerScript\\" : "src/ComposerScript" }
3434
},
3535
"require-dev": {
36-
"phpunit/phpunit": "^4.8",
37-
"phake/phake": "^2.3",
38-
"satooshi/php-coveralls": "^1.0"
36+
"phpunit/phpunit": "^5.7 || ^7.0.0 || ^9.0",
37+
"phake/phake": "^2.3 || ^4.2",
38+
"php-coveralls/php-coveralls": "^2.5"
3939
},
4040
"scripts": {
4141
"post-install-cmd": "ComposerScript\\RsaOaep256AlgorithmInstaller::install"

phpunit.xml.dist

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
1211
bootstrap="vendor/autoload.php"
1312
>
1413
<testsuites>
@@ -21,4 +20,7 @@
2120
<directory>./src</directory>
2221
</whitelist>
2322
</filter>
23+
<logging>
24+
<log type="coverage-clover" target="build/logs/clover.xml"/>
25+
</logging>
2426
</phpunit>

src/Hyperwallet/Exception/HyperwalletApiException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class HyperwalletApiException extends HyperwalletException {
3131
*/
3232
public function __construct(ErrorResponse $errorResponse, \Exception $previous) {
3333
$message = $errorResponse[0] == null ? "Error message is not defined" : $errorResponse[0]->getMessage();
34-
parent::__construct($message, null, $previous);
34+
parent::__construct($message, 0, $previous);
3535

3636
$this->errorResponse = $errorResponse;
3737
$this->relatedResources = $errorResponse[0] == null ? array() : $errorResponse[0]->getRelatedResources();

src/Hyperwallet/Exception/HyperwalletArgumentException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ class HyperwalletArgumentException extends HyperwalletException {
1212
* Creates a instance of the HyperwalletArgumentException
1313
*
1414
* @param string $message The error message
15-
* @param int|null $code The error code
15+
* @param int $code The error code
1616
* @param \Exception|null $previous The original exception
1717
*/
18-
public function __construct($message, $code = null, \Exception $previous = null) {
18+
public function __construct($message, $code = 0, \Exception $previous = null) {
1919
parent::__construct($message, $code, $previous);
2020
}
2121

src/Hyperwallet/Exception/HyperwalletException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ class HyperwalletException extends \Exception {
1212
* Creates a instance of the HyperwalletException
1313
*
1414
* @param string $message The error message
15-
* @param int|null $code The error code
15+
* @param int $code The error code
1616
* @param \Exception|null $previous The original exception
1717
*/
18-
public function __construct($message, $code = null, \Exception $previous = null) {
18+
public function __construct($message = "", $code = 0, \Exception $previous = null) {
1919
parent::__construct($message, $code, $previous);
2020
}
2121

src/Hyperwallet/Model/HyperwalletVerificationDocument.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ public function getDocuments() {
170170
return $this->documents;
171171
}
172172

173-
public function getIterator() : ArrayIterator {
174-
return new ArrayIterator($this->documents);
173+
public function getIterator() {
174+
return new \ArrayIterator($this->documents);
175175
}
176176

177177
}

src/Hyperwallet/Model/HyperwalletVerificationDocumentReason.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public function getReasons() {
7777
return $this->reasons;
7878
}
7979

80-
public function getIterator() : ArrayIterator {
81-
return new ArrayIterator($this->reasons);
80+
public function getIterator() {
81+
return new \ArrayIterator($this->reasons);
8282
}
8383

8484
}

src/Hyperwallet/Util/ApiClient.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
use GuzzleHttp\Client;
44
use GuzzleHttp\Exception\BadResponseException;
55
use GuzzleHttp\Exception\ConnectException;
6-
use GuzzleHttp\UriTemplate\UriTemplate;
76
use Hyperwallet\Exception\HyperwalletApiException;
87
use Hyperwallet\Exception\HyperwalletException;
98
use Hyperwallet\Model\BaseModel;
109
use Hyperwallet\Response\ErrorResponse;
11-
use Hyperwallet\Util\HyperwalletEncryption;
12-
use Hyperwallet\Util\HyperwalletUUID;
13-
1410

1511
/**
1612
* The internal API client
@@ -24,7 +20,7 @@ class ApiClient {
2420
*
2521
* @var string
2622
*/
27-
const VERSION = '2.2.1';
23+
const VERSION = '2.2.3';
2824

2925
/**
3026
* The Guzzle http client
@@ -155,7 +151,7 @@ public function doGet($partialUrl, array $uriParams, array $query) {
155151
*/
156152
private function doRequest($method, $url, array $urlParams, array $options) {
157153
try {
158-
$uri = new UriTemplate();
154+
$uri = new HyperwalletUriTemplate();
159155
if (!isset($options['headers'])) {
160156
$options[] = array('headers' => array());
161157
}

src/Hyperwallet/Util/HyperwalletUUID.php

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
<?php
22
namespace Hyperwallet\Util;
3-
use GuzzleHttp\Client;
4-
use GuzzleHttp\Exception\BadResponseException;
5-
use GuzzleHttp\Exception\ConnectException;
6-
use GuzzleHttp\UriTemplate\UriTemplate;
7-
use Hyperwallet\Exception\HyperwalletApiException;
3+
84
use Hyperwallet\Exception\HyperwalletException;
9-
use Hyperwallet\Model\BaseModel;
10-
use Hyperwallet\Response\ErrorResponse;
11-
use Composer\Autoload\ClassLoader;
12-
use phpseclib\Crypt\RSA;
13-
use phpseclib\Math\BigInteger;
14-
use phpseclib\Crypt\Hash;
15-
use JOSE_URLSafeBase64;
16-
use JOSE_JWS;
17-
use JOSE_JWE;
18-
use JOSE_JWK;
19-
use JOSE_JWT;
205

216
/**
227
* The encryption service for Hyperwallet client's requests/responses
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace Hyperwallet\Util;
4+
5+
/**
6+
* A simple implementation of https://www.rfc-editor.org/rfc/rfc6570 for expanding Hyperwallet
7+
* Uniform Resource Identifier (URI) Template.
8+
*
9+
* This class was created to allow the Hyperwallet SDK to support by PHP 5.6 and latest version
10+
* @package Hyperwallet\Util
11+
*/
12+
final class HyperwalletUriTemplate
13+
{
14+
15+
/**
16+
* Regex pattern to find variable identifier defined by pair of braces ('{', '}').
17+
* e.g. {var}
18+
*/
19+
const PATTERN = '/\{([^\}]+)\}/';
20+
21+
/**
22+
* Processes URI Template
23+
*
24+
* This implementation will replace simple key defined in pair of braces ('{', '}') and replaced for the associate
25+
* variable value.
26+
*
27+
* E.g. $uriTemplate = `test/{var-a}/{var-b}`, $variables = array('var-a' => 'testA', 'var-b' => 'testB') will return
28+
* test/testA/testB
29+
*
30+
* @param string $uriTemplate the URI Template is a string that
31+
* contains zero or more embedded variable expressions delimited by pair of braces ('{', '}').
32+
* @param array $variables the variable identifiers for associating values within a template
33+
* processor
34+
* @return string
35+
*/
36+
public function expand($uriTemplate, array $variables)
37+
{
38+
if (!$variables || strpos($uriTemplate, '{') === false) {
39+
// skip processing
40+
return $uriTemplate;
41+
}
42+
43+
return \preg_replace_callback(
44+
self::PATTERN,
45+
self::buildProcessMatchResult($variables),
46+
$uriTemplate
47+
);
48+
}
49+
50+
/**
51+
* Evaluates the match result and find the associated value from the defined variables
52+
* @param array $matches the match results
53+
* @param array $variables the variable identifiers for associating values within a template
54+
* processor
55+
* @return mixed
56+
*/
57+
private static function processMatchResult(array $matches, array $variables)
58+
{
59+
if (!isset($variables[$matches[1]])) {
60+
// missing variable definition, return the match key
61+
return $matches[0];
62+
}
63+
64+
return $variables[$matches[1]];
65+
}
66+
67+
/**
68+
* Builds an anonymous functions to process the match result
69+
* @param array $variables
70+
* @return \Closure
71+
*/
72+
private static function buildProcessMatchResult(array $variables)
73+
{
74+
return static function (array $matches) use ($variables) {
75+
return self::processMatchResult($matches, $variables);
76+
};
77+
}
78+
}

tests/Hyperwallet/Tests/HyperwalletTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
use Hyperwallet\Util\ApiClient;
3535
use Hyperwallet\Util\HyperwalletUUID;
3636

37-
class HyperwalletTest extends \PHPUnit_Framework_TestCase {
37+
class HyperwalletTest extends \PHPUnit\Framework\TestCase {
3838

3939
public function testConstructor_throwErrorIfUsernameIsEmpty() {
4040
try {

tests/Hyperwallet/Tests/Model/BaseModelTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use Hyperwallet\Model\BaseModel;
55

6-
class BaseModelTest extends \PHPUnit_Framework_TestCase {
6+
class BaseModelTest extends \PHPUnit\Framework\TestCase {
77

88
public function testMagicGetter() {
99
$data = array(

tests/Hyperwallet/Tests/Model/ModelTestCase.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace Hyperwallet\Tests\Model;
33

4-
abstract class ModelTestCase extends \PHPUnit_Framework_TestCase {
4+
abstract class ModelTestCase extends \PHPUnit\Framework\TestCase {
55

66
/**
77
* @var \ReflectionClass
@@ -25,8 +25,9 @@ abstract class ModelTestCase extends \PHPUnit_Framework_TestCase {
2525

2626
protected abstract function getModelName();
2727

28-
public function setUp() {
29-
parent::setUp();
28+
public function __construct($name = null, array $data = [], $dataName = '')
29+
{
30+
parent::__construct($name, $data, $dataName);
3031
$this->init();
3132
}
3233

tests/Hyperwallet/Tests/Response/ErrorResponseTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Hyperwallet\Model\Error;
55
use Hyperwallet\Response\ErrorResponse;
66

7-
class ErrorResponseTest extends \PHPUnit_Framework_TestCase {
7+
class ErrorResponseTest extends \PHPUnit\Framework\TestCase {
88

99
public function testBodyParsing() {
1010
$errorResponse = new ErrorResponse(200, array(

tests/Hyperwallet/Tests/Response/ListResponseTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use Hyperwallet\Response\ListResponse;
55

6-
class ListResponseTest extends \PHPUnit_Framework_TestCase {
6+
class ListResponseTest extends \PHPUnit\Framework\TestCase {
77

88
public function testBodyParsing_noContent() {
99
$listResponse = new ListResponse(array(), function ($body) {

tests/Hyperwallet/Tests/Util/ApiClientTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Hyperwallet\Util\ApiClient;
1414
use Hyperwallet\Util\HyperwalletEncryption;
1515

16-
class ApiClientTest extends \PHPUnit_Framework_TestCase {
16+
class ApiClientTest extends \PHPUnit\Framework\TestCase {
1717

1818
/**
1919
* @var array

0 commit comments

Comments
 (0)