Skip to content

Commit

Permalink
fix!: remove isLive
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Dec 18, 2021
1 parent e4c950a commit 855ae2c
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 99 deletions.
52 changes: 52 additions & 0 deletions phpstan-baseline.neon
@@ -0,0 +1,52 @@
parameters:
ignoreErrors:
-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:DUPLICATE_TRANSACTION is unused\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:ERROR is unused\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:INVALID_ACCOUNT is unused\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:SUCCESS is unused\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:SYSTEM_EXCEPTION is unused\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:UNAUTHENTICATED is unused\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\ErrorCodeEnum\\:\\:WRONG_REQUEST is unused\\.$#"
count: 1
path: src/Enums/ErrorCodeEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\PostedStatusEnum\\:\\:NO is unused\\.$#"
count: 1
path: src/Enums/PostedStatusEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\PostedStatusEnum\\:\\:YES is unused\\.$#"
count: 1
path: src/Enums/PostedStatusEnum.php

-
message: "#^Constant BrokeYourBike\\\\ZenithBank\\\\Enums\\\\StatusCodeEnum\\:\\:PROCESSED is unused\\.$#"
count: 1
path: src/Enums/StatusCodeEnum.php

3 changes: 3 additions & 0 deletions phpstan.neon
@@ -1,3 +1,6 @@
includes:
- phpstan-baseline.neon

parameters:
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
Expand Down
12 changes: 9 additions & 3 deletions src/Client.php
Expand Up @@ -44,20 +44,26 @@ public function __construct(ConfigInterface $config, ClientInterface $httpClient

public function authTokenCacheKey(): string
{
$liveKey = $this->config->isLive() ? 'live' : 'sandbox';
return __CLASS__ . ':authToken:' . $liveKey;
return get_class($this) . ':authToken:';
}

public function getAuthToken(): ?string
{
if ($this->cache->has($this->authTokenCacheKey())) {
return (string) $this->cache->get($this->authTokenCacheKey());
$cachedToken = $this->cache->get($this->authTokenCacheKey());

if (is_string($cachedToken)) {
return $cachedToken;
}
}

$response = $this->fetchAuthTokenRaw();
$responseJson = \json_decode((string) $response->getBody(), true);

if (
is_array($responseJson) &&
isset($responseJson['tokenDetail']) &&
is_array($responseJson['tokenDetail']) &&
isset($responseJson['tokenDetail']['token']) &&
is_string($responseJson['tokenDetail']['token']) &&
isset($responseJson['tokenDetail']['expiration']) &&
Expand Down
1 change: 0 additions & 1 deletion src/Interfaces/ConfigInterface.php
Expand Up @@ -13,7 +13,6 @@
*/
interface ConfigInterface
{
public function isLive(): bool;
public function getUrl(): string;
public function getUsername(): string;
public function getPassword(): string;
Expand Down
24 changes: 0 additions & 24 deletions tests/ClientTest.php
Expand Up @@ -56,30 +56,6 @@ public function it_implements_has_source_model_interface(): void
$this->assertInstanceOf(HasSourceModelInterface::class, $api);
}

/** @test */
public function it_will_return_different_cache_key_for_test_and_sandbox()
{
/** @var \GuzzleHttp\ClientInterface */
$mockedHttpClient = $this->getMockBuilder(\GuzzleHttp\ClientInterface::class)->getMock();

/** @var \Psr\SimpleCache\CacheInterface */
$mockedCache = $this->getMockBuilder(\Psr\SimpleCache\CacheInterface::class)->getMock();

$liveConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
$liveConfig->method('isLive')->willReturn(true);

/** @var ConfigInterface $liveConfig */
$liveApi = new Client($liveConfig, $mockedHttpClient, $mockedCache);

$sandboxConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
$sandboxConfig->method('isLive')->willReturn(false);

/** @var ConfigInterface $sandboxConfig */
$sandboxApi = new Client($sandboxConfig, $mockedHttpClient, $mockedCache);

$this->assertNotEquals($liveApi->authTokenCacheKey(), $sandboxApi->authTokenCacheKey());
}

/** @test */
public function it_uses_http_client_trait(): void
{
Expand Down
8 changes: 2 additions & 6 deletions tests/FetchAccountRawTest.php
Expand Up @@ -22,14 +22,10 @@ class FetchAccountRawTest extends TestCase
private string $bankCode = '12345';
private string $accountNumber = '654987';

/**
* @test
* @dataProvider isLiveProvider
*/
public function it_can_prepare_request(bool $isLive): void
/** @test */
public function it_can_prepare_request(): void
{
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
$mockedConfig->method('isLive')->willReturn($isLive);
$mockedConfig->method('getUrl')->willReturn('https://api.example/');

/** @var \Mockery\MockInterface $mockedClient */
Expand Down
8 changes: 2 additions & 6 deletions tests/FetchAuthTokenRawTest.php
Expand Up @@ -21,14 +21,10 @@ class FetchAuthTokenRawTest extends TestCase
private string $username = 'unique-username';
private string $password = 'secure-password';

/**
* @test
* @dataProvider isLiveProvider
*/
public function it_can_prepare_request(bool $isLive): void
/** @test */
public function it_can_prepare_request(): void
{
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
$mockedConfig->method('isLive')->willReturn($isLive);
$mockedConfig->method('getUrl')->willReturn('https://api.example/');
$mockedConfig->method('getUsername')->willReturn($this->username);
$mockedConfig->method('getPassword')->willReturn($this->password);
Expand Down
8 changes: 2 additions & 6 deletions tests/FetchBalanceRawTest.php
Expand Up @@ -21,14 +21,10 @@ class FetchBalanceRawTest extends TestCase
private string $authToken = 'secure-token';
private string $accountNumber = '654987';

/**
* @test
* @dataProvider isLiveProvider
*/
public function it_can_prepare_request(bool $isLive): void
/** @test */
public function it_can_prepare_request(): void
{
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
$mockedConfig->method('isLive')->willReturn($isLive);
$mockedConfig->method('getUrl')->willReturn('https://api.example/');

/** @var \Mockery\MockInterface $mockedClient */
Expand Down
8 changes: 2 additions & 6 deletions tests/FetchDomesticAccountRawTest.php
Expand Up @@ -21,14 +21,10 @@ class FetchDomesticAccountRawTest extends TestCase
private string $authToken = 'secure-token';
private string $accountNumber = '654987';

/**
* @test
* @dataProvider isLiveProvider
*/
public function it_can_prepare_request(bool $isLive): void
/** @test */
public function it_can_prepare_request(): void
{
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
$mockedConfig->method('isLive')->willReturn($isLive);
$mockedConfig->method('getUrl')->willReturn('https://api.example/');

/** @var \Mockery\MockInterface $mockedClient */
Expand Down
8 changes: 2 additions & 6 deletions tests/FetchDomesticTransactionRawTest.php
Expand Up @@ -21,14 +21,10 @@ class FetchDomesticTransactionRawTest extends TestCase
private string $authToken = 'secure-token';
private string $transactionReference = 'TRX-1234';

/**
* @test
* @dataProvider isLiveProvider
*/
public function it_can_prepare_request(bool $isLive): void
/** @test */
public function it_can_prepare_request(): void
{
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
$mockedConfig->method('isLive')->willReturn($isLive);
$mockedConfig->method('getUrl')->willReturn('https://api.example/');

/** @var \Mockery\MockInterface $mockedClient */
Expand Down
8 changes: 2 additions & 6 deletions tests/FetchTransactionRawTest.php
Expand Up @@ -21,14 +21,10 @@ class FetchTransactionRawTest extends TestCase
private string $authToken = 'secure-token';
private string $transactionReference = 'TRX-1234';

/**
* @test
* @dataProvider isLiveProvider
*/
public function it_can_prepare_request(bool $isLive): void
/** @test */
public function it_can_prepare_request(): void
{
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
$mockedConfig->method('isLive')->willReturn($isLive);
$mockedConfig->method('getUrl')->willReturn('https://api.example/');

/** @var \Mockery\MockInterface $mockedClient */
Expand Down
12 changes: 3 additions & 9 deletions tests/GetAuthTokenTest.php
Expand Up @@ -21,11 +21,8 @@ class GetAuthTokenTest extends TestCase
{
private string $tokenValue = 'super-secure-token';

/**
* @test
* @dataProvider isLiveProvider
*/
public function it_can_cache_and_return_auth_token(bool $isLive)
/** @test */
public function it_can_cache_and_return_auth_token()
{
$currentTestDate = Carbon::create(2020, 1, 1, 23, 30, 59);
Carbon::setTestNow($currentTestDate);
Expand Down Expand Up @@ -148,10 +145,7 @@ public function it_can_return_cached_value()
$this->assertSame($this->tokenValue, $requestResult);
}

/**
* @test
* @dataProvider isLiveProvider
*/
/** @test */
public function it_will_return_null_if_response_invalid()
{
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
Expand Down
16 changes: 4 additions & 12 deletions tests/SendDomesticTransactionTest.php
Expand Up @@ -21,11 +21,8 @@ class SendDomesticTransactionTest extends TestCase
{
private string $authToken = 'secure-token';

/**
* @test
* @dataProvider isLiveProvider
*/
public function it_can_prepare_request(bool $isLive): void
/** @test */
public function it_can_prepare_request(): void
{
$transaction = $this->getMockBuilder(TransactionInterface::class)->getMock();
$transaction->method('getReference')->willReturn('REF-1234');
Expand All @@ -40,7 +37,6 @@ public function it_can_prepare_request(bool $isLive): void
$this->assertInstanceOf(TransactionInterface::class, $transaction);

$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
$mockedConfig->method('isLive')->willReturn($isLive);
$mockedConfig->method('getUrl')->willReturn('https://api.example/');

/** @var \Mockery\MockInterface $mockedClient */
Expand Down Expand Up @@ -83,17 +79,13 @@ public function it_can_prepare_request(bool $isLive): void
$this->assertInstanceOf(ResponseInterface::class, $requestResult);
}

/**
* @test
* @dataProvider isLiveProvider
*/
public function it_will_pass_source_model_as_option(bool $isLive): void
/** @test */
public function it_will_pass_source_model_as_option(): void
{
/** @var SourceTransactionFixture $transaction */
$transaction = $this->getMockBuilder(SourceTransactionFixture::class)->getMock();

$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
$mockedConfig->method('isLive')->willReturn($isLive);
$mockedConfig->method('getUrl')->willReturn('https://api.example/');

/** @var \Mockery\MockInterface $mockedClient */
Expand Down
8 changes: 0 additions & 8 deletions tests/TestCase.php
Expand Up @@ -18,12 +18,4 @@ protected function tearDown(): void
parent::tearDown();
\Mockery::close();
}

public function isLiveProvider(): array
{
return [
[true],
[false],
];
}
}
8 changes: 2 additions & 6 deletions tests/TransactionLookupRawTest.php
Expand Up @@ -31,14 +31,10 @@ protected function setUp(): void
$this->transactionDate = Carbon::create(2020, 1, 5, 23, 30, 59);
}

/**
* @test
* @dataProvider isLiveProvider
*/
public function it_can_prepare_request(bool $isLive): void
/** @test */
public function it_can_prepare_request(): void
{
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
$mockedConfig->method('isLive')->willReturn($isLive);
$mockedConfig->method('getUrl')->willReturn('https://api.example/');

/** @var \Mockery\MockInterface $mockedClient */
Expand Down

0 comments on commit 855ae2c

Please sign in to comment.