Skip to content

Commit

Permalink
Merge pull request #123 from bunq/optimise_test_framework_auto_topup_…
Browse files Browse the repository at this point in the history
…#120

Optimise test framework auto topup #120
  • Loading branch information
OGKevin authored Apr 5, 2018
2 parents de3ba20 + 8f959d2 commit a188cf4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 27 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 = '[email protected]';
const SPENDING_MONEY_DESCRIPTION = 'sdk php test, thanks daddy <3';

/**
*/
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
39 changes: 16 additions & 23 deletions tests/Model/Generated/Endpoint/PaymentTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<?php
namespace bunq\test\Model\Generated\Endpoint;

use bunq\Model\Generated\Endpoint\BunqResponseInt;
use bunq\Model\Generated\Endpoint\ChatMessageText;
use bunq\Model\Generated\Endpoint\Payment;
use bunq\Model\Generated\Endpoint\PaymentChat;
use bunq\Model\Generated\Object\Amount;
use bunq\Model\Generated\Object\Pointer;
use bunq\test\BunqSdkTestBase;
use bunq\test\Config;
use phpDocumentor\Reflection\Types\This;

/**
* Tests:
Expand Down Expand Up @@ -38,56 +36,51 @@ class PaymentTest extends BunqSdkTestBase
*/
const PAYMENT_CHAT_TEXT_MESSAGE = 'send from PHP test';

/**
* @var int
*/
private $paymentId;

/**
* Test sending money to other sandbox user.
*
* This test has no assertion as of its testing to see if the code runs without errors.
*/
public function testSendMoneyToOtherUser()
{
$this->skipTestIfNeededDueToInsufficientBalance();

Payment::create(
$response = Payment::create(
new Amount(self::PAYMENT_AMOUNT_IN_EUR, self::PAYMENT_CURRENCY),
$this->getPointerUserBravo(),
self::PAYMENT_DESCRIPTION
);

static::assertNotNull($response);
}

/**
* Test sending money to other monetaryAccount.
*
* This test has no assertion as of its testing to see if the code runs without errors.
*/
public function testSendMoneyToOtherMonetaryAccount()
public function testSendMoneyToOtherMonetaryAccount(): BunqResponseInt
{
$this->skipTestIfNeededDueToInsufficientBalance();

$this->paymentId = Payment::create(
$paymentId = Payment::create(
new Amount(self::PAYMENT_AMOUNT_IN_EUR, self::PAYMENT_CURRENCY),
$this->getSecondMonetaryAccountAlias(),
self::PAYMENT_DESCRIPTION
)->getValue();
);

static::assertNotNull($paymentId);

return $paymentId;
}

/**
* Test sending a payment chat to a payment.
*
* This test has no assertion as of its testing to see if the code runs without errors.
*
* @depends testSendMoneyToOtherMonetaryAccount
*/
public function testSendMessageToPayment()
public function testSendMessageToPayment(BunqResponseInt $paymentId)
{
$chatId = PaymentChat::create(
$this->paymentId
)->getValue();
$chatId = PaymentChat::create($paymentId->getValue())->getValue();

$response = ChatMessageText::create($chatId, self::PAYMENT_CHAT_TEXT_MESSAGE);

ChatMessageText::create($chatId, self::PAYMENT_CHAT_TEXT_MESSAGE);
static::assertNotNull($response);
}
}
11 changes: 9 additions & 2 deletions tests/Model/Generated/Endpoint/RequestInquiryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public function testSendingAndAcceptingRequest()

$this->sendRequest();
$responses = RequestResponse::listing($this->getSecondMonetaryAccountId())->getValue();

static::assertNotNull($responses);

$requestResponseId = $responses[self::INDEX_FIRST]->getId();
$this->acceptRequest($requestResponseId);
}
Expand All @@ -53,24 +56,28 @@ public function testSendingAndAcceptingRequest()
*/
private function sendRequest()
{
RequestInquiry::create(
$response = RequestInquiry::create(
new Amount(self::REQUEST_AMOUNT_IN_EUR, self::REQUEST_CURRENCY),
$this->getSecondMonetaryAccountAlias(),
self::REQUEST_DESCRIPTION,
false
);

static::assertNotNull($response);
}

/**
* @param int $requestResponseId
*/
private function acceptRequest(int $requestResponseId)
{
RequestResponse::update(
$response = RequestResponse::update(
$requestResponseId,
$this->getSecondMonetaryAccountId(),
null,
self::REQUEST_STATUS_ACCEPTED
);

static::assertNotNull($response);
}
}

0 comments on commit a188cf4

Please sign in to comment.