diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..f5c67f9 --- /dev/null +++ b/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 + diff --git a/phpstan.neon b/phpstan.neon index 7c42ee3..9ca1701 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,3 +1,6 @@ +includes: + - phpstan-baseline.neon + parameters: checkMissingIterableValueType: false checkGenericClassInNonGenericObjectType: false diff --git a/src/Client.php b/src/Client.php index 4dd2c76..5c8a176 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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']) && diff --git a/src/Interfaces/ConfigInterface.php b/src/Interfaces/ConfigInterface.php index 2515fd5..ad19171 100644 --- a/src/Interfaces/ConfigInterface.php +++ b/src/Interfaces/ConfigInterface.php @@ -13,7 +13,6 @@ */ interface ConfigInterface { - public function isLive(): bool; public function getUrl(): string; public function getUsername(): string; public function getPassword(): string; diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 8a796f4..8ef3fc5 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -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 { diff --git a/tests/FetchAccountRawTest.php b/tests/FetchAccountRawTest.php index d65dbf1..0ac39ce 100644 --- a/tests/FetchAccountRawTest.php +++ b/tests/FetchAccountRawTest.php @@ -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 */ diff --git a/tests/FetchAuthTokenRawTest.php b/tests/FetchAuthTokenRawTest.php index 9a9cb05..c4380fc 100644 --- a/tests/FetchAuthTokenRawTest.php +++ b/tests/FetchAuthTokenRawTest.php @@ -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); diff --git a/tests/FetchBalanceRawTest.php b/tests/FetchBalanceRawTest.php index bf2d6de..3aff7e4 100644 --- a/tests/FetchBalanceRawTest.php +++ b/tests/FetchBalanceRawTest.php @@ -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 */ diff --git a/tests/FetchDomesticAccountRawTest.php b/tests/FetchDomesticAccountRawTest.php index 775257a..ba48378 100644 --- a/tests/FetchDomesticAccountRawTest.php +++ b/tests/FetchDomesticAccountRawTest.php @@ -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 */ diff --git a/tests/FetchDomesticTransactionRawTest.php b/tests/FetchDomesticTransactionRawTest.php index 4227c5a..374ea51 100644 --- a/tests/FetchDomesticTransactionRawTest.php +++ b/tests/FetchDomesticTransactionRawTest.php @@ -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 */ diff --git a/tests/FetchTransactionRawTest.php b/tests/FetchTransactionRawTest.php index 0a49550..2067cca 100644 --- a/tests/FetchTransactionRawTest.php +++ b/tests/FetchTransactionRawTest.php @@ -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 */ diff --git a/tests/GetAuthTokenTest.php b/tests/GetAuthTokenTest.php index e5c7b24..3d9c256 100644 --- a/tests/GetAuthTokenTest.php +++ b/tests/GetAuthTokenTest.php @@ -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); @@ -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(); diff --git a/tests/SendDomesticTransactionTest.php b/tests/SendDomesticTransactionTest.php index 3300ba0..4871a3f 100644 --- a/tests/SendDomesticTransactionTest.php +++ b/tests/SendDomesticTransactionTest.php @@ -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'); @@ -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 */ @@ -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 */ diff --git a/tests/TestCase.php b/tests/TestCase.php index 477e6ff..5fe0723 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -18,12 +18,4 @@ protected function tearDown(): void parent::tearDown(); \Mockery::close(); } - - public function isLiveProvider(): array - { - return [ - [true], - [false], - ]; - } } diff --git a/tests/TransactionLookupRawTest.php b/tests/TransactionLookupRawTest.php index 6beb3d0..d05b4d1 100644 --- a/tests/TransactionLookupRawTest.php +++ b/tests/TransactionLookupRawTest.php @@ -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 */