Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added initial travis config. (bunq/sdk_php#126) #127

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sudo: required

language: php

services:
- docker

before_install:
- docker build -t sdk .

script: docker run sdk
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ubuntu:16.04

RUN apt update && apt install -y php7.0 php7.0-curl php7.0-mbstring php7.0-xml composer wget tar bzip2 zip

RUN mkdir /sdk_php
COPY . /sdk_php
WORKDIR /sdk_php
RUN composer install

CMD vendor/bin/paratest -p 1
135 changes: 66 additions & 69 deletions src/Util/InstallationUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ public static function interactiveInstall()
try {
$context = static::createApiContextWithoutConstructor();

$environmentType = new BunqEnumApiEnvironmentType(static::readLine(
self::PROMPT_ENVIRONMENT,
self::ERROR_EMPTY_ENVIRONMENT
));
$environmentType = new BunqEnumApiEnvironmentType(
static::readLine(
self::PROMPT_ENVIRONMENT,
self::ERROR_EMPTY_ENVIRONMENT
)
);
static::setPrivateProperty($context, self::PROPERTY_ENVIRONMENT_TYPE, $environmentType);

$apiKey = static::readLine(
Expand Down Expand Up @@ -114,71 +116,6 @@ public static function interactiveInstall()
}
}

/**
* @param BunqEnumApiEnvironmentType $environmentType
* @param string $contextFileName
* @param string|null $apiKey
*/
public static function automaticInstall(
BunqEnumApiEnvironmentType $environmentType,
string $contextFileName,
string $apiKey = null
) {
try {
$context = static::createApiContextWithoutConstructor();

if (is_null($environmentType)) {
$environmentType = BunqEnumApiEnvironmentType::SANDBOX();
} else {
// Environment already passed
}

static::setPrivateProperty($context, self::PROPERTY_ENVIRONMENT_TYPE, $environmentType);

if ($environmentType->equals(BunqEnumApiEnvironmentType::SANDBOX()) && is_null($apiKey)) {
$methodCreateSandboxUser = static::createAccessibleReflectionMethod(
ApiContext::class,
self::METHOD_CREATE_SANDBOX_USER
);

$methodCreateSandboxUser->invoke($context);
} elseif (!is_null($apiKey)) {
static::setPrivateProperty($context, self::PROPERTY_API_KEY, $apiKey);
} else {
throw new BunqException(self::ERROR_CANNOT_CREATE_API_KEY_PRODUCTION);
}

$methodInitializeInstallationContext = static::createAccessibleReflectionMethod(
ApiContext::class,
self::METHOD_INITIALIZE_INSTALLATION_CONTEXT
);
$methodInitializeInstallationContext->invoke($context);

$methodRegisterDevice = static::createAccessibleReflectionMethod(
ApiContext::class,
self::METHOD_REGISTER_DEVICE
);
$methodRegisterDevice->invoke($context, gethostname(), []);

$methodInitializeSessionContext = static::createAccessibleReflectionMethod(
ApiContext::class,
self::METHOD_INITIALIZE_SESSION_CONTEXT
);
$methodInitializeSessionContext->invoke($context);

if ($contextFileName === null) {
$context->save();
} else {
$context->save($contextFileName);
}
} catch (BunqException $exception) {
echo sprintf(self::ERROR_BUNQ_EXCEPTION, $exception->getMessage());
var_dump($exception);
} catch (Exception $exception) {
echo sprintf(self::ERROR_EXCEPTION, $exception->getMessage());
}
}

/**
* @return ApiContext
*/
Expand Down Expand Up @@ -287,4 +224,64 @@ private static function assertIpIsValid(string $ip)
throw new BunqException(self::ERROR_INVALID_IP_ADDRESS, [$ip]);
}
}

/**
* @param BunqEnumApiEnvironmentType $environmentType
* @param string|null $contextFileName
* @param string|null $apiKey
* @param bool $saveToConfFile
*
* @return ApiContext
*/
public static function automaticInstall(
BunqEnumApiEnvironmentType $environmentType,
string $contextFileName = null,
string $apiKey = null,
bool $saveToConfFile = false
): ApiContext {
$context = static::createApiContextWithoutConstructor();

if (!is_null($environmentType)) {
$environmentType = BunqEnumApiEnvironmentType::SANDBOX();
}

static::setPrivateProperty($context, self::PROPERTY_ENVIRONMENT_TYPE, $environmentType);

if ($environmentType->equals(BunqEnumApiEnvironmentType::SANDBOX()) && is_null($apiKey)) {
$methodCreateSandboxUser = static::createAccessibleReflectionMethod(
ApiContext::class,
self::METHOD_CREATE_SANDBOX_USER
);

$methodCreateSandboxUser->invoke($context);
} elseif (!is_null($apiKey)) {
static::setPrivateProperty($context, self::PROPERTY_API_KEY, $apiKey);
} else {
throw new BunqException(self::ERROR_CANNOT_CREATE_API_KEY_PRODUCTION);
}

$methodInitializeInstallationContext = static::createAccessibleReflectionMethod(
ApiContext::class,
self::METHOD_INITIALIZE_INSTALLATION_CONTEXT
);
$methodInitializeInstallationContext->invoke($context);

$methodRegisterDevice = static::createAccessibleReflectionMethod(
ApiContext::class,
self::METHOD_REGISTER_DEVICE
);
$methodRegisterDevice->invoke($context, gethostname(), []);

$methodInitializeSessionContext = static::createAccessibleReflectionMethod(
ApiContext::class,
self::METHOD_INITIALIZE_SESSION_CONTEXT
);
$methodInitializeSessionContext->invoke($context);

if (!$contextFileName === null && $saveToConfFile) {
$context->save($contextFileName);
}

return $context;
}
}
122 changes: 60 additions & 62 deletions tests/BunqSdkTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ class BunqSdkTestBase extends TestCase
*/
const INDEX_FIRST = 0;

/**
* Spending money constants.
*/
const SPENDING_MONEY_AMOUNT = '500';
const SPENDING_MONEY_RECIPIENT = '[email protected]';
const SPENDING_MONEY_DESCRIPTION = 'sdk php test, thanks daddy <3';

/**
* @var MonetaryAccountBank
*/
Expand All @@ -77,30 +84,21 @@ 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()
{
static::createApiContext();
BunqContext::loadApiContext(
ApiContext::restore(self::FILE_PATH_CONTEXT_CONFIG)
static::createApiContext()
);
}

/**
*/
protected static function createApiContext()
protected static function createApiContext(): ApiContext
{
InstallationUtil::automaticInstall(
BunqEnumApiEnvironmentType::SANDBOX(),
self::FILE_PATH_CONTEXT_CONFIG
return InstallationUtil::automaticInstall(
BunqEnumApiEnvironmentType::SANDBOX()
);
}

Expand All @@ -114,43 +112,6 @@ protected function setUp()
BunqContext::getUserContext()->refreshUserContext();
}

/**
*/
private function setCashRegister()
{
$attachmentUuid = AttachmentPublic::create(
FileUtil::getFileContents(__DIR__ . self::FILE_PATH_AVATAR),
[
ApiClient::HEADER_CONTENT_TYPE => $this->getAttachmentContentType(),
ApiClient::HEADER_ATTACHMENT_DESCRIPTION => $this->getAttachmentDescription(),
]
);
$avatarUuid = Avatar::create($attachmentUuid->getValue());
$cashRegisterId = CashRegister::create(
self::CASH_REGISTER_NAME,
self::CASH_REGISTER_STATUS,
$avatarUuid->getValue()
);

$this->cashRegister = CashRegister::get($cashRegisterId->getValue());
}

/**
* @return string
*/
protected function getAttachmentContentType(): string
{
return self::ATTACHMENT_CONTENT_TYPE;
}

/**
* @return string
*/
protected function getAttachmentDescription(): string
{
return self::ATTACHMENT_DESCRIPTION;
}

/**
*/
private function setSecondMonetaryAccountBank()
Expand Down Expand Up @@ -183,6 +144,14 @@ private function requestSpendingMoney()
);
}

/**
* @return int
*/
protected function getSecondMonetaryAccountId(): int
{
return $this->secondMonetaryAccountBank->getId();
}

/**
* @return Pointer
*
Expand Down Expand Up @@ -236,14 +205,6 @@ protected function getPointerUserBravo(): Pointer
);
}

/**
* @return int
*/
protected function getSecondMonetaryAccountId(): int
{
return $this->secondMonetaryAccountBank->getId();
}

/**
* @return int
*/
Expand All @@ -257,13 +218,40 @@ protected function getCashRegisterId(): int
}

/**
* @return bool
*/
protected function isMonetaryAccountBalanceSufficient(): bool
private function setCashRegister()
{
$balance = floatval(BunqContext::getUserContext()->getPrimaryMonetaryAccount()->getBalance()->getValue());
$attachmentUuid = AttachmentPublic::create(
FileUtil::getFileContents(__DIR__ . self::FILE_PATH_AVATAR),
[
ApiClient::HEADER_CONTENT_TYPE => $this->getAttachmentContentType(),
ApiClient::HEADER_ATTACHMENT_DESCRIPTION => $this->getAttachmentDescription(),
]
);
$avatarUuid = Avatar::create($attachmentUuid->getValue());
$cashRegisterId = CashRegister::create(
self::CASH_REGISTER_NAME,
self::CASH_REGISTER_STATUS,
$avatarUuid->getValue()
);

return $balance > self::MONETARY_ACCOUNT_BALANCE_THRESHOLD;
$this->cashRegister = CashRegister::get($cashRegisterId->getValue());
}

/**
* @return string
*/
protected function getAttachmentContentType(): string
{
return self::ATTACHMENT_CONTENT_TYPE;
}

/**
* @return string
*/
protected function getAttachmentDescription(): string
{
return self::ATTACHMENT_DESCRIPTION;
}

/**
Expand All @@ -277,4 +265,14 @@ protected function skipTestIfNeededDueToInsufficientBalance(): bool

return true;
}

/**
* @return bool
*/
protected function isMonetaryAccountBalanceSufficient(): bool
{
$balance = floatval(BunqContext::getUserContext()->getPrimaryMonetaryAccount()->getBalance()->getValue());

return $balance > self::MONETARY_ACCOUNT_BALANCE_THRESHOLD;
}
}
2 changes: 1 addition & 1 deletion tests/Model/Generated/Object/NotificationUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class NotificationUrlTest extends BunqSdkTestBase
/**
* Model json paths constants.
*/
const BASE_PATH_JSON_MODEL = __DIR__ . '/../../../Resource/NotificationUrlJsons';
const BASE_PATH_JSON_MODEL = __DIR__ . '../../../Resource/NotificationUrlJsons';
const JSON_PATH_MUTATION_MODEL = self::BASE_PATH_JSON_MODEL . '/Mutation.json';
const JSON_PATH_BUNQ_ME_TAB_MODEL = self::BASE_PATH_JSON_MODEL . '/BunqMeTab.json';
const JSON_PATH_CHAT_MESSAGE_ANNOUNCEMENT_MODEL = self::BASE_PATH_JSON_MODEL . '/ChatMessageAnnouncement.json';
Expand Down