From a4a3d22c522aed13bca9ac56c5c1d0afce47d926 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Wed, 30 Oct 2024 20:00:12 +0200 Subject: [PATCH] updated tests and models --- MangoPay/ApiVirtualAccounts.php | 9 ++++--- MangoPay/InternationalAccount.php | 4 +-- MangoPay/InternationalAccountDetails.php | 4 +-- MangoPay/LocalAccount.php | 6 +++-- MangoPay/LocalAccountDetails.php | 4 +-- MangoPay/VirtualAccount.php | 4 +-- MangoPay/VirtualAccountAddress.php | 3 +-- MangoPay/VirtualAccountAvailabilities.php | 18 ++----------- MangoPay/VirtualAccountAvailability.php | 15 +---------- MangoPay/VirtualAccountCapabilities.php | 8 +++--- MangoPay/VirtualAccountOwner.php | 2 +- MangoPay/VirtualAccountPurpose.php | 2 +- tests/Cases/Base.php | 17 ++++++++++++ tests/Cases/VirtualAccountsTest.php | 32 +++++++++++------------ 14 files changed, 58 insertions(+), 70 deletions(-) diff --git a/MangoPay/ApiVirtualAccounts.php b/MangoPay/ApiVirtualAccounts.php index a64eae3a..a6f5e01d 100644 --- a/MangoPay/ApiVirtualAccounts.php +++ b/MangoPay/ApiVirtualAccounts.php @@ -40,9 +40,10 @@ public function GetAll($walletId, $pagination = null, $sorting = null) * @param string $virtualAccountId * @return \MangoPay\VirtualAccount */ - public function Deactivate($virtualAccount, $walletId, $virtualAccountId) + public function Deactivate($walletId, $virtualAccountId) { - return $this->SaveObject('virtual_account_deactivate', $virtualAccount, '\MangoPay\VirtualAccount', $walletId, $virtualAccountId); + $empty_object = ""; + return $this->SaveObject('virtual_account_deactivate', $empty_object, '\MangoPay\VirtualAccount', $walletId, $virtualAccountId); } /** @@ -50,6 +51,6 @@ public function Deactivate($virtualAccount, $walletId, $virtualAccountId) */ public function GetAvailabilities() { - return $this->GetObject('virtual_account_get_availabilities','\MangoPay\VirtualAccountAvailabilities'); + return $this->GetObject('virtual_account_get_availabilities', '\MangoPay\VirtualAccountAvailabilities'); } -} \ No newline at end of file +} diff --git a/MangoPay/InternationalAccount.php b/MangoPay/InternationalAccount.php index cf18cfab..d1f1f39f 100644 --- a/MangoPay/InternationalAccount.php +++ b/MangoPay/InternationalAccount.php @@ -2,7 +2,7 @@ namespace MangoPay; -class InternationalAccount +class InternationalAccount extends Libraries\Dto { /** * @var string @@ -13,4 +13,4 @@ class InternationalAccount * @var string */ public $Bic; -} \ No newline at end of file +} diff --git a/MangoPay/InternationalAccountDetails.php b/MangoPay/InternationalAccountDetails.php index 168dd40a..f0951ff8 100644 --- a/MangoPay/InternationalAccountDetails.php +++ b/MangoPay/InternationalAccountDetails.php @@ -2,7 +2,7 @@ namespace MangoPay; -class InternationalAccountDetails +class InternationalAccountDetails extends Libraries\Dto { /** * Information about the address associated with the international IBAN account. @@ -15,4 +15,4 @@ class InternationalAccountDetails * @var InternationalAccount */ public $Account; -} \ No newline at end of file +} diff --git a/MangoPay/LocalAccount.php b/MangoPay/LocalAccount.php index c8c03660..d9ed4a24 100644 --- a/MangoPay/LocalAccount.php +++ b/MangoPay/LocalAccount.php @@ -2,15 +2,17 @@ namespace MangoPay; -class LocalAccount +class LocalAccount extends Libraries\Dto { /** * The account number of the account + * @var string */ public $AccountNumber; /** * The sort code of the account. + * @var string */ public $SortCode; -} \ No newline at end of file +} diff --git a/MangoPay/LocalAccountDetails.php b/MangoPay/LocalAccountDetails.php index 55d066a0..e0e51611 100644 --- a/MangoPay/LocalAccountDetails.php +++ b/MangoPay/LocalAccountDetails.php @@ -2,7 +2,7 @@ namespace MangoPay; -class LocalAccountDetails +class LocalAccountDetails extends Libraries\Dto { /** * Information about the address associated with the local IBAN account. @@ -15,4 +15,4 @@ class LocalAccountDetails * @var LocalAccount */ public $Account; -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccount.php b/MangoPay/VirtualAccount.php index f84f9e18..2a9c125f 100644 --- a/MangoPay/VirtualAccount.php +++ b/MangoPay/VirtualAccount.php @@ -73,6 +73,4 @@ class VirtualAccount extends Libraries\EntityBase * @var \MangoPay\VirtualAccountCapabilities */ public $Capabilities; - - -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccountAddress.php b/MangoPay/VirtualAccountAddress.php index 91e8a06e..b409e31e 100644 --- a/MangoPay/VirtualAccountAddress.php +++ b/MangoPay/VirtualAccountAddress.php @@ -28,5 +28,4 @@ class VirtualAccountAddress extends Libraries\Dto * @var string */ public $Country; - -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccountAvailabilities.php b/MangoPay/VirtualAccountAvailabilities.php index 80da0195..60bb2b74 100644 --- a/MangoPay/VirtualAccountAvailabilities.php +++ b/MangoPay/VirtualAccountAvailabilities.php @@ -2,7 +2,7 @@ namespace MangoPay; -class VirtualAccountAvailabilities extends Libraries\EntityBase +class VirtualAccountAvailabilities extends Libraries\Dto { /** * * @var VirtualAccountAvailability[] @@ -13,18 +13,4 @@ class VirtualAccountAvailabilities extends Libraries\EntityBase * * @var VirtualAccountAvailability[] */ public $UserOwned; - - /** - * Get array with mapping which property is object and what type of object - * @return array - */ - public function GetSubObjects() - { - $subObjects = parent::GetSubObjects(); - - $subObjects['Collection'] = '\MangoPay\VirtualAccountAvailability'; - $subObjects['UserOwned'] = '\MangoPay\VirtualAccountAvailability'; - - return $subObjects; - } -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccountAvailability.php b/MangoPay/VirtualAccountAvailability.php index db2f7f2b..667871a5 100644 --- a/MangoPay/VirtualAccountAvailability.php +++ b/MangoPay/VirtualAccountAvailability.php @@ -21,17 +21,4 @@ class VirtualAccountAvailability extends Libraries\EntityBase * @var CurrencyIso[] * */ public $Currencies; - - /** - * Get array with mapping which property is object and what type of object - * @return array - */ - public function GetSubObjects() - { - $subObjects = parent::GetSubObjects(); - - $subObjects['Currencies'] = '\MangoPay\CurrencyIso'; - - return $subObjects; - } -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccountCapabilities.php b/MangoPay/VirtualAccountCapabilities.php index f0835a0c..bc34ec8c 100644 --- a/MangoPay/VirtualAccountCapabilities.php +++ b/MangoPay/VirtualAccountCapabilities.php @@ -2,17 +2,17 @@ namespace MangoPay; -class VirtualAccountCapabilities +class VirtualAccountCapabilities extends Libraries\Dto { /** * Whether local bank wires can be made to this account. - * @var Boolean + * @var bool */ public $LocalPayInAvailable; /** * Whether international bank wires can be made to this account - * @var Boolean + * @var bool */ public $InternationalPayInAvailable; @@ -21,4 +21,4 @@ class VirtualAccountCapabilities * @var CurrencyIso[] */ public $Currencies; -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccountOwner.php b/MangoPay/VirtualAccountOwner.php index 1a6f673f..3c8d7de5 100644 --- a/MangoPay/VirtualAccountOwner.php +++ b/MangoPay/VirtualAccountOwner.php @@ -6,4 +6,4 @@ class VirtualAccountOwner { const Collection = "COLLECTION"; const UserOwned = "USER_OWNED"; -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccountPurpose.php b/MangoPay/VirtualAccountPurpose.php index b952a235..b53cf3fe 100644 --- a/MangoPay/VirtualAccountPurpose.php +++ b/MangoPay/VirtualAccountPurpose.php @@ -6,4 +6,4 @@ class VirtualAccountPurpose { const Collection = "COLLECTION"; const UserOwned = "USER_OWNED"; -} \ No newline at end of file +} diff --git a/tests/Cases/Base.php b/tests/Cases/Base.php index 976b4f36..cecf46bb 100644 --- a/tests/Cases/Base.php +++ b/tests/Cases/Base.php @@ -14,6 +14,7 @@ use MangoPay\ShippingPreference; use MangoPay\Tests\Mocks\MockStorageStrategy; use MangoPay\Ubo; +use MangoPay\VirtualAccount; use PHPUnit\Framework\TestCase; set_time_limit(0); @@ -52,6 +53,7 @@ abstract class Base extends TestCase * @var \MangoPay\Wallet */ public static $JohnsWallet; + public static $johnsVirtualAccount; /** * Test Kyc Document belonging to John * @var \MangoPay\KycDocument @@ -259,6 +261,21 @@ protected function getJohnsWallet() return self::$JohnsWallet; } + protected function getNewVirtualAccount() + { + if (self::$johnsVirtualAccount === null) { + $wallet = $this->getJohnsWallet(); + $virtualAccount = new VirtualAccount(); + $virtualAccount->Country = "FR"; + $virtualAccount->VirtualAccountPurpose = "Collection"; + $virtualAccount->Tag = "create virtual account tag"; + + self::$johnsVirtualAccount = $this->_api->VirtualAccounts->Create($virtualAccount, $wallet->Id); + } + + return self::$johnsVirtualAccount; + } + /** * Creates Pay-In Card Web object * @return \MangoPay\PayIn diff --git a/tests/Cases/VirtualAccountsTest.php b/tests/Cases/VirtualAccountsTest.php index ad33f94a..43eacb8b 100644 --- a/tests/Cases/VirtualAccountsTest.php +++ b/tests/Cases/VirtualAccountsTest.php @@ -17,36 +17,33 @@ class VirtualAccountsTest extends Base public static $johnsVirtualAccount; public function test_VirtualAccount_Create() { - $wallet = $this->getJohnsWallet(); - $virtualAccount = new VirtualAccount(); - $virtualAccount->Country = "FR"; - $virtualAccount->VirtualAccountPurpose = "Collection"; - $virtualAccount->Tag = "create virtual account tag"; - - self::$johnsVirtualAccount = $this->_api->VirtualAccounts->Create($virtualAccount, $wallet->Id); + $virtualAccount = $this->getNewVirtualAccount(); + $wallet = $this -> getJohnsWallet(); - $this->assertNotNull(self::$johnsVirtualAccount); - $this->assertEquals(self::$johnsVirtualAccount->WalletId, $wallet->Id); + $this->assertNotNull($virtualAccount); + $this->assertEquals($virtualAccount->WalletId, $wallet->Id); } public function test_VirtualAccount_Get() { - $wallet = $this->getJohnsWallet(); + $virtualAccount = $this->getNewVirtualAccount(); + $wallet = $this -> getJohnsWallet(); + $fetchedVirtualAccount = $this->_api->VirtualAccounts->Get($wallet->Id, $virtualAccount->Id); - $virtualAccounts = $this->_api->VirtualAccounts->GetAll($wallet->Id); - - $this->assertNotNull($virtualAccounts); - $this->assertTrue(is_array($virtualAccounts), 'Expected an array'); + $this->assertNotNull($fetchedVirtualAccount); + $this->assertEquals($fetchedVirtualAccount->Id, $virtualAccount->Id); } public function test_VirtualAccount_GetAll() { + $this->getNewVirtualAccount(); $wallet = $this->getJohnsWallet(); $virtualAccounts = $this->_api->VirtualAccounts->GetAll($wallet->Id); $this->assertNotNull($virtualAccounts); $this->assertTrue(is_array($virtualAccounts), 'Expected an array'); + $this->assertEquals(1, sizeof($virtualAccounts)); } public function test_VirtualAccount_Get_Availabilities() @@ -60,10 +57,11 @@ public function test_VirtualAccount_Get_Availabilities() public function test_VirtualAccount_Deactivate() { + $virtualAccount = $this->getNewVirtualAccount(); $wallet = $this->getJohnsWallet(); - self::$johnsVirtualAccount->Active = false; - $deactivatedVirtualAccount = $this->_api->VirtualAccounts->Deactivate(self::$johnsVirtualAccount, $wallet->Id, self::$johnsVirtualAccount->Id); + $deactivatedVirtualAccount = $this->_api->VirtualAccounts->Deactivate($wallet->Id, $virtualAccount->Id); $this->assertNotTrue($deactivatedVirtualAccount->Active); + $this->assertEquals('CLOSED', $deactivatedVirtualAccount->Status); } -} \ No newline at end of file +}