Skip to content

Commit

Permalink
Add unit tests for read response object
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-puslecki committed Sep 27, 2016
1 parent 6e62b23 commit 71534c9
Show file tree
Hide file tree
Showing 4 changed files with 466 additions and 13 deletions.
2 changes: 1 addition & 1 deletion MangoPay/ApiResponses.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function Get($idempotencyKey)
{
$response = $this->GetObject('responses_get', $idempotencyKey, 'MangoPay\Response');
$className = $this->GetObjectForIdempotencyUrl($response->RequestUrl);
if (is_null($className) || empty($className))
if (is_null($className) || empty($className) || is_null($response->Resource) || empty($response->Resource))
return $response;

$response->Resource = $this->CastResponseToEntity($response->Resource, $className);
Expand Down
4 changes: 2 additions & 2 deletions MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,9 @@ protected function GetObjectForIdempotencyUrl($url){
'temp_immediatepayins_create' => '\MangoPay\TemporaryImmediatePayIn',
'payouts_bankwire_create' => '\MangoPay\PayOut',
'reports_create' => '\MangoPay\ReportRequest',
'transfers_create' => '\MangoPay\Transfer',
'transfers_createrefunds' => '\MangoPay\Refund',
'users_createnaturals' => '\MangoPay\UserNatural',
'transfers_create' => '\MangoPay\Transfer',
'users_createnaturals' => '\MangoPay\UserNatural', // done
'users_createlegals' => '\MangoPay\UserLegal',
'users_createbankaccounts_iban' => '\MangoPay\BankAccount',
'users_createbankaccounts_gb' => '\MangoPay\BankAccount',
Expand Down
10 changes: 6 additions & 4 deletions tests/cases/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ protected function buildNewMangoPayApi() {
$api->Config->ClientId = 'sdk-unit-tests';

// sandbox environment:
$api->Config->BaseUrl = 'https://api.sandbox.mangopay.com';
$api->Config->ClientPassword = 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju';
// $api->Config->BaseUrl = 'https://api.sandbox.mangopay.com';
// $api->Config->ClientPassword = 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju';
$api->Config->BaseUrl = 'https://api-test.mangopay.com';
$api->Config->ClientPassword = '9RMGpwVUwFLK0SurxObJ2yaadDcO0zeKFKxWmthjB93SQjFzy0';

$api->OAuthTokenManager->RegisterCustomStorageStrategy(new \MangoPay\Tests\MockStorageStrategy());

Expand Down Expand Up @@ -566,7 +568,7 @@ protected function getJohnsCardRegistration() {
* Creates card registration object
* @return \MangoPay\CardPreAuthorization
*/
protected function getJohnsCardPreAuthorization() {
protected function getJohnsCardPreAuthorization($idempotencyKey = null) {
$user = $this->getJohn();
$cardRegistration = new \MangoPay\CardRegistration();
$cardRegistration->UserId = $user->Id;
Expand All @@ -585,7 +587,7 @@ protected function getJohnsCardPreAuthorization() {
$cardPreAuthorization->CardId = $getCardRegistration->CardId;
$cardPreAuthorization->SecureModeReturnURL = 'http://test.com';

return $this->_api->CardPreAuthorizations->Create($cardPreAuthorization);
return $this->_api->CardPreAuthorizations->Create($cardPreAuthorization, $idempotencyKey);
}

/**
Expand Down
Loading

0 comments on commit 71534c9

Please sign in to comment.