Skip to content

Commit

Permalink
Merge pull request #496 from williamdes/tests
Browse files Browse the repository at this point in the history
Make tests run from PHP 5.6 to 8.1 and support phpunit versions for all the PHP versions
  • Loading branch information
SoloJr authored Aug 10, 2021
2 parents 1b2024f + 238a067 commit 26944fd
Show file tree
Hide file tree
Showing 33 changed files with 162 additions and 211 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Lint files

on: [push]

jobs:
lint-php:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use php 7.1
uses: shivammathur/setup-php@v2
with:
php-version: 7.1
- name: Validate composer.json
run: composer validate
- name: Cache module
uses: actions/cache@v2
with:
path: ~/.composer/cache/
key: composer-cache
- name: Install dependencies
run: composer install --no-interaction
- name: Lint files
run: ./vendor/bin/php-cs-fixer fix --dry-run
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ demos/paymentDirect/MangoPaySdkStorage.tmp.php
composer.lock

.*
!.github
!.php_cs
!.gitignore
!.gitattributes
1 change: 1 addition & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ return $config->setRules([
'@PSR12' => true,
'fully_qualified_strict_types' => true,
'array_syntax' => ['syntax' => 'short'],
'visibility_required' => ['property', 'method'],// 'const' is removed for old PHP compat
])
->setFinder($finder)
;
10 changes: 5 additions & 5 deletions MangoPay/ApiPayIns.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public function GetRecurringRegistration($recurringRegistrationId, $idempotencyK
return $this->GetObject('payins_recurring_registration_get', '\MangoPay\PayInRecurringRegistrationGet', $recurringRegistrationId);
}

/**
* Update recurring payment
* @param PayInRecurringRegistrationUpdate $recurringUpdate
* @return \MangoPay\PayInRecurringRegistrationGet
*/
/**
* Update recurring payment
* @param PayInRecurringRegistrationUpdate $recurringUpdate
* @return \MangoPay\PayInRecurringRegistrationGet
*/
public function UpdateRecurringRegistration($recurringUpdate, $idempotencyKey = null)
{
return $this->SaveObject('payins_recurring_registration_put', $recurringUpdate, '\MangoPay\PayInRecurringRegistrationGet');
Expand Down
8 changes: 4 additions & 4 deletions MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ protected function getLogger()
* Array with REST url and request type
* @var array
*/
private $_methods = array(
'authentication_base' => array('/clients/', RequestType::POST),
'authentication_oauth' => array('/oauth/token/', RequestType::POST),
private $_methods = [
'authentication_base' => ['/clients/', RequestType::POST],
'authentication_oauth' => ['/oauth/token/', RequestType::POST],

'responses_get' => ['/responses/%s', RequestType::GET],

Expand Down Expand Up @@ -201,7 +201,7 @@ protected function getLogger()
'transactions_get_for_card' => ['/cards/%s/transactions', RequestType::GET],
'transactions_get_for_bank_account' => ['/bankaccounts/%s/transactions', RequestType::GET]

);
];

/**
* Constructor
Expand Down
6 changes: 4 additions & 2 deletions MangoPay/Libraries/RestTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,10 @@ private function CheckResponseCode($responseCode, $response)
$error->Errors = $response->errors;
}

foreach ((array) $error->Errors as $key => $val) {
$error->Message .= sprintf(' %s error: %s', $key, $val);
if (is_array($error->Errors)) {
foreach ($error->Errors as $key => $val) {
$error->Message .= sprintf(' %s error: %s', $key, $val);
}
}

throw new ResponseException($this->_requestUrl, $responseCode, $error);
Expand Down
4 changes: 1 addition & 3 deletions MangoPay/PayInRecurring.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php


namespace MangoPay;


class PayInRecurring extends PayIn
{
/**
* @var string
*/
public $RecurringPayinRegistrationId;
}
}
4 changes: 1 addition & 3 deletions MangoPay/PayInRecurringRegistration.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace MangoPay;


class PayInRecurringRegistration extends Libraries\Dto
{
/**
Expand Down Expand Up @@ -80,4 +78,4 @@ class PayInRecurringRegistration extends Libraries\Dto
* @var \MangoPay\Money
*/
public $NextTransactionFees;
}
}
4 changes: 1 addition & 3 deletions MangoPay/PayInRecurringRegistrationGet.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php


namespace MangoPay;


class PayInRecurringRegistrationGet extends PayInRecurringRegistration
{
/**
* @var RecurringPayInCurrentState
*/
public $CurrentState;
}
}
4 changes: 1 addition & 3 deletions MangoPay/PayInRecurringRegistrationRequestResponse.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace MangoPay;


class PayInRecurringRegistrationRequestResponse extends PayInRecurringRegistration
{
/**
Expand Down Expand Up @@ -35,4 +33,4 @@ class PayInRecurringRegistrationRequestResponse extends PayInRecurringRegistrati
* @var int
*/
public $FreeCycles;
}
}
4 changes: 1 addition & 3 deletions MangoPay/PayInRecurringRegistrationUpdate.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace MangoPay;


use MangoPay\Libraries\Dto;

class PayInRecurringRegistrationUpdate extends Dto
Expand All @@ -28,4 +26,4 @@ class PayInRecurringRegistrationUpdate extends Dto
* @var Billing
*/
public $Billing;
}
}
4 changes: 1 addition & 3 deletions MangoPay/RecurringPayInCIT.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace MangoPay;


class RecurringPayInCIT extends Libraries\Dto
{
/**
Expand Down Expand Up @@ -45,4 +43,4 @@ class RecurringPayInCIT extends Libraries\Dto
* @var Money
*/
public $Fees;
}
}
4 changes: 1 addition & 3 deletions MangoPay/RecurringPayInCurrentState.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace MangoPay;


use MangoPay\Libraries\Dto;

class RecurringPayInCurrentState extends Dto
Expand All @@ -27,4 +25,4 @@ class RecurringPayInCurrentState extends Dto
* @var string
*/
public $LastPayinId;
}
}
4 changes: 1 addition & 3 deletions MangoPay/RecurringPayInMIT.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace MangoPay;


class RecurringPayInMIT extends Libraries\Dto
{
/**
Expand All @@ -30,4 +28,4 @@ class RecurringPayInMIT extends Libraries\Dto
* @var string
*/
public $Tag;
}
}
3 changes: 1 addition & 2 deletions MangoPay/UboDeclarationRefusedOrIncompleteReasonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,4 @@ class UboDeclarationRefusedOrIncompleteReasonType
* @see UboDeclaration::$Message
*/
const SpecificCase = 'SPECIFIC_CASE';

}
}
3 changes: 1 addition & 2 deletions MangoPay/UboDeclarationRefusedReasonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
*/
class UboDeclarationRefusedReasonType extends UboDeclarationRefusedOrIncompleteReasonType
{

}
}
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MANGOPAY PHP SDK [![Build Status](https://travis-ci.org/Mangopay/mangopay2-php-sdk.svg?branch=master)](https://travis-ci.org/Mangopay/mangopay2-php-sdk) [![Latest Stable Version](https://poser.pugx.org/mangopay/php-sdk-v2/v/stable)](https://packagist.org/packages/mangopay/php-sdk-v2) [![Total Downloads](https://poser.pugx.org/mangopay/php-sdk-v2/downloads)](https://packagist.org/packages/mangopay/php-sdk-v2) [![License](https://poser.pugx.org/mangopay/php-sdk-v2/license)](https://packagist.org/packages/mangopay/php-sdk-v2)
MANGOPAY PHP SDK [![mangopay2-php-sdk-cd](https://github.com/Mangopay/mangopay2-php-sdk/actions/workflows/build.yaml/badge.svg)](https://github.com/Mangopay/mangopay2-php-sdk/actions/workflows/build.yaml) [![Latest Stable Version](https://poser.pugx.org/mangopay/php-sdk-v2/v/stable)](https://packagist.org/packages/mangopay/php-sdk-v2) [![Total Downloads](https://poser.pugx.org/mangopay/php-sdk-v2/downloads)](https://packagist.org/packages/mangopay/php-sdk-v2) [![License](https://poser.pugx.org/mangopay/php-sdk-v2/license)](https://packagist.org/packages/mangopay/php-sdk-v2)
=================================================

MangopaySDK is a PHP client library to work with [Mangopay REST API](https://docs.mangopay.com/endpoints/v2.01).
Expand All @@ -7,12 +7,12 @@ MangopaySDK is a PHP client library to work with [Mangopay REST API](https://doc
Compatibility Notes
-------------------------------------------------
* Since v2.1 of this SDK, you must be using at least v2.01 of the API ([more information about the changes required](https://docs.mangopay.com/api-v2-01-overview/))
* If you experience problems with authentification and/or the temporary token file following an SDK update (particuarly updating to v2.0 of the SDK), you may need to just delete your temporary file (that you specify with `$api->Config->TemporaryFolder`) - which allows it to be regenerated correctly the next time it's needed
* If you experience problems with authentification and/or the temporary token file following an SDK update (particularly updating to v2.0 of the SDK), you may need to just delete your temporary file (that you specify with `$api->Config->TemporaryFolder`) - which allows it to be regenerated correctly the next time it's needed

Requirements
-------------------------------------------------
To use this SDK, you will need (as a minimum):
* PHP v5.4 (at least 5.6 is recommended)
* PHP 5.6 or newer
* cURL (included and enabled in a standard PHP distribution)
* OpenSSL (included and enabled in a standard PHP distribution)
* [psr/log](https://github.com/php-fig/log) v1.0
Expand Down Expand Up @@ -193,7 +193,7 @@ class MangoPayService
$this->mangoPayApi = new MangoPay\MangoPayApi();
$this->mangoPayApi->Config->ClientId = 'your-client-id';
$this->mangoPayApi->Config->ClientPassword = 'your-client-password';
$this->mangoPayApi->Config->TemporaryFolder = '/some/path/';
$this->mangoPayApi->Config->TemporaryFolder = '/some/path/';
//$this->mangoPayApi->Config->BaseUrl = 'https://api.sandbox.mangopay.com';
}

Expand Down Expand Up @@ -273,13 +273,13 @@ class MangoPayService
$this->mangoPayApi = new MangoPay\MangoPayApi();
$this->mangoPayApi->Config->ClientId = 'your-client-id';
$this->mangoPayApi->Config->ClientPassword = 'your-client-password';
$this->mangoPayApi->Config->TemporaryFolder = '/some/path/';
$this->mangoPayApi->Config->TemporaryFolder = '/some/path/';
//$this->mangoPayApi->Config->BaseUrl = 'https://api.sandbox.mangopay.com';
}

public function verifyRateLimits()
{
// This is an arary of 4 RateLimit objects.
// This is an array of 4 RateLimit objects.
$rateLimits = $this->mangoPayApi->RateLimits;
print "There were " . $rateLimits[0]->CallsMade . " calls made in the last 15 minutes\n";
print "You can do " . $rateLimits[0]->CallsRemaining . " more calls in the next 15 minutes\n";
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^7.3",
"phpunit/phpunit": ">=5.7.27 <10",
"friendsofphp/php-cs-fixer": "^2.18"
}
}
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="mangopay_tests">
<directory>tests/cases/</directory>
<directory>tests/Cases/</directory>
</testsuite>
</testsuites>
</phpunit>
</phpunit>
2 changes: 1 addition & 1 deletion tests/Cases/BankAccountsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function test_BankAccount_GetTransactions()
$transactions = $this->_api->BankAccounts->GetTransactions($bankAccount->Id, $pagination, $filter);

$this->assertNotNull($transactions);
$this->assertInternalType('array', $transactions);
$this->assertTrue(is_array($transactions), 'Expected an array');
}

public function test_create_bank_account_other()
Expand Down
7 changes: 4 additions & 3 deletions tests/Cases/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,12 @@ protected function getNewPayInDirectDebitDirect($userId = null)

/**
* Creates self::$JohnsWalletWithMoney (wallets belonging to John) if not created yet (3DSecure)
* @return \MangoPay\Wallet
* @return array<int,string>
* @phpstan-return {walletId: string, cardId?: string }
*/
protected function getJohnsWalletWithMoneyAndCardId($amount = 1000)
{
$arr = array();
$arr = [];
if (self::$JohnsWalletWithMoney === null) {
$john = $this->getJohn();
// create wallet with money
Expand Down Expand Up @@ -381,7 +382,7 @@ protected function getJohnsWalletWithMoneyAndCardId($amount = 1000)
}

$wall = $this->_api->Wallets->Get(self::$JohnsWalletWithMoney->Id);
$arr["wallet"] = $wall;
$arr["walletId"] = $wall->Id;

return $arr;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Cases/CardsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function test_Card_GetPreAuthorizations()
$preauthorizations = $this->_api->Cards->GetPreAuthorizations($card->Id);

$this->assertNotNull($preauthorizations);
$this->assertInternalType('array', $preauthorizations);
$this->assertTrue(is_array($preauthorizations), 'Expected an array');
}

public function test_Card_GetTransactions()
Expand All @@ -50,7 +50,7 @@ public function test_Card_GetTransactions()
$transactions = $this->_api->Cards->GetTransactions($card->Id, $pagination, $filter);

$this->assertNotNull($transactions);
$this->assertInternalType('array', $transactions);
$this->assertTrue(is_array($transactions), 'Expected an array');
}

public function test_Card_Validate()
Expand Down
5 changes: 1 addition & 4 deletions tests/Cases/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
*/
class ConfigurationTest extends Base
{
/**
* @expectedException MangoPay\Libraries\ResponseException
*/
public function test_confInConstruct()
{
$this->_api->Config->ClientId = "test_asd";
$this->_api->Config->ClientPassword = "00000";

// $this->excpectException('MangoPay\Libraries\ResponseException');
$this->expectException(ResponseException::class);
$this->_api->Users->GetAll();
}
}
Loading

0 comments on commit 26944fd

Please sign in to comment.