Skip to content

Commit

Permalink
Ensure test account has enough money on it. (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Apr 5, 2018
1 parent de3ba20 commit 7e1cddd
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions tests/BunqSdkTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use bunq\Model\Generated\Endpoint\Avatar;
use bunq\Model\Generated\Endpoint\CashRegister;
use bunq\Model\Generated\Endpoint\MonetaryAccountBank;
use bunq\Model\Generated\Endpoint\RequestInquiry;
use bunq\Model\Generated\Object\Amount;
use bunq\Model\Generated\Object\Pointer;
use bunq\Util\BunqEnumApiEnvironmentType;
use bunq\Util\FileUtil;
Expand Down Expand Up @@ -36,7 +38,7 @@ class BunqSdkTestBase extends TestCase
/**
* MonetaryAccount constants.
*/
const MOMENTARY_ACCOUNT_CURRENCY = 'EUR';
const MONETARY_ACCOUNT_CURRENCY = 'EUR';
const MONETARY_ACCOUNT_DESCRIPTION = 'test account php';
const MONETARY_ACCOUNT_BALANCE_THRESHOLD = 0.00;

Expand Down Expand Up @@ -75,6 +77,13 @@ class BunqSdkTestBase extends TestCase
*/
protected $cashRegister;

/**
* Spending money constants.
*/
const SPENDING_MONEY_AMOUNT = '500';
const SPENDING_MONEY_RECIPIENT = 'sugardaddy@bunq.com';
const SPENDING_MONEY_DESCRIPTION = 'sdk php test, thanks daddy <3 - OG';

/**
*/
public static function setUpBeforeClass()
Expand All @@ -100,6 +109,9 @@ protected static function createApiContext()
protected function setUp()
{
$this->setSecondMonetaryAccountBank();
$this->requestSpendingMoney();
sleep(0.5); // ensure requests are auto accepted.
BunqContext::getUserContext()->refreshUserContext();
}

/**
Expand Down Expand Up @@ -144,13 +156,33 @@ protected function getAttachmentDescription(): string
private function setSecondMonetaryAccountBank()
{
$createdId = MonetaryAccountBank::create(
self::MOMENTARY_ACCOUNT_CURRENCY,
self::MONETARY_ACCOUNT_CURRENCY,
self::MONETARY_ACCOUNT_DESCRIPTION
);

$this->secondMonetaryAccountBank = MonetaryAccountBank::get($createdId->getValue())->getValue();
}

/**
*/
private function requestSpendingMoney()
{
RequestInquiry::create(
new Amount(self::SPENDING_MONEY_AMOUNT, self::MONETARY_ACCOUNT_CURRENCY),
new Pointer(self::POINTER_TYPE_EMAIL, self::SPENDING_MONEY_RECIPIENT),
self::SPENDING_MONEY_DESCRIPTION,
false
);

RequestInquiry::create(
new Amount(self::SPENDING_MONEY_AMOUNT, self::MONETARY_ACCOUNT_CURRENCY),
new Pointer(self::POINTER_TYPE_EMAIL, self::SPENDING_MONEY_RECIPIENT),
self::SPENDING_MONEY_DESCRIPTION,
false,
$this->getSecondMonetaryAccountId()
);
}

/**
* @return Pointer
*
Expand Down

0 comments on commit 7e1cddd

Please sign in to comment.