mirror of
https://github.com/bitinflow/accounts.git
synced 2026-03-13 13:35:52 +00:00
Refactoring
This commit is contained in:
26
tests/Payments/ApiOauthTest.php
Normal file
26
tests/Payments/ApiOauthTest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Bitinflow\Payments\Tests;
|
||||
|
||||
use Bitinflow\Accounts\Contracts\AppTokenRepository;
|
||||
use Bitinflow\Payments\Tests\TestCases\ApiTestCase;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
class ApiOauthTest extends ApiTestCase
|
||||
{
|
||||
|
||||
public function testGetOauthToken(): void
|
||||
{
|
||||
$token = app(AppTokenRepository::class)->getAccessToken();
|
||||
|
||||
$this->getPaymentsClient()->withToken($this->getToken());
|
||||
$this->registerResult($result = $this->getPaymentsClient()->createSubscription([
|
||||
|
||||
]));
|
||||
$result->dump();
|
||||
}
|
||||
}
|
||||
80
tests/Payments/TestCases/ApiTestCase.php
Normal file
80
tests/Payments/TestCases/ApiTestCase.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Bitinflow\Payments\Tests\TestCases;
|
||||
|
||||
use Bitinflow\Accounts\BitinflowAccounts;
|
||||
use Bitinflow\Accounts\Result;
|
||||
use Bitinflow\Payments\BitinflowPayments;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
abstract class ApiTestCase extends TestCase
|
||||
{
|
||||
protected static $rateLimitRemaining = null;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if ($this->getAccountsBaseUrl()) {
|
||||
BitinflowAccounts::setBaseUrl($this->getAccountsBaseUrl());
|
||||
}
|
||||
if ($this->getPaymentsBaseUrl()) {
|
||||
BitinflowPayments::setBaseUrl($this->getPaymentsBaseUrl());
|
||||
}
|
||||
|
||||
if (!$this->getClientId()) {
|
||||
$this->markTestSkipped('No Client-ID given');
|
||||
}
|
||||
if (self::$rateLimitRemaining !== null && self::$rateLimitRemaining < 3) {
|
||||
$this->markTestSkipped('Rate Limit exceeded (' . self::$rateLimitRemaining . ')');
|
||||
}
|
||||
$this->getAccountsClient()->setClientId($this->getClientId());
|
||||
$this->getPaymentsClient()->setClientId($this->getClientId());
|
||||
}
|
||||
|
||||
protected function registerResult(Result $result): Result
|
||||
{
|
||||
self::$rateLimitRemaining = $result->rateLimit('remaining');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getAccountsBaseUrl()
|
||||
{
|
||||
return getenv('ACCOUNTS_BASE_URL');
|
||||
}
|
||||
|
||||
protected function getPaymentsBaseUrl()
|
||||
{
|
||||
return getenv('PAYMENTS_BASE_URL');
|
||||
}
|
||||
|
||||
protected function getClientId()
|
||||
{
|
||||
return getenv('CLIENT_ID');
|
||||
}
|
||||
|
||||
protected function getClientSecret()
|
||||
{
|
||||
return getenv('CLIENT_KEY');
|
||||
}
|
||||
|
||||
protected function getToken()
|
||||
{
|
||||
return getenv('CLIENT_ACCESS_TOKEN');
|
||||
}
|
||||
|
||||
public function getPaymentsClient(): BitinflowPayments
|
||||
{
|
||||
return app(BitinflowPayments::class);
|
||||
}
|
||||
|
||||
public function getAccountsClient(): BitinflowAccounts
|
||||
{
|
||||
return app(BitinflowAccounts::class);
|
||||
}
|
||||
}
|
||||
30
tests/Payments/TestCases/TestCase.php
Normal file
30
tests/Payments/TestCases/TestCase.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Bitinflow\Payments\Tests\TestCases;
|
||||
|
||||
use Bitinflow\Accounts\BitinflowAccounts;
|
||||
use Bitinflow\Accounts\Providers\BitinflowAccountsServiceProvider;
|
||||
use Orchestra\Testbench\TestCase as BaseTestCase;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return [
|
||||
BitinflowAccountsServiceProvider::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getPackageAliases($app)
|
||||
{
|
||||
return [
|
||||
'BitinflowAccounts' => BitinflowAccounts::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user