-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d844ec7
commit d6e4f55
Showing
11 changed files
with
677 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\ZenithBank\Interfaces; | ||
|
||
/** | ||
* @author Ivan Stasiuk <brokeyourbike@gmail.com> | ||
*/ | ||
interface TransactionInterface | ||
{ | ||
public function getReference(): string; | ||
public function getSenderName(): string; | ||
public function getRecipientName(): string; | ||
public function getRecipientAccount(): string; | ||
public function getDebitAccount(): string; | ||
public function getAmount(): float; | ||
public function shouldResend(): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\ZenithBank\Tests; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use BrokeYourBike\ZenithBank\Interfaces\ConfigInterface; | ||
use BrokeYourBike\ZenithBank\Client; | ||
|
||
/** | ||
* @author Ivan Stasiuk <brokeyourbike@gmail.com> | ||
*/ | ||
class FetchAccountRawTest extends TestCase | ||
{ | ||
private string $authToken = 'secure-token'; | ||
private string $bankCode = '12345'; | ||
private string $accountNumber = '654987'; | ||
|
||
/** | ||
* @test | ||
* @dataProvider isLiveProvider | ||
*/ | ||
public function it_can_prepare_request(bool $isLive): void | ||
{ | ||
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock(); | ||
$mockedConfig->method('isLive')->willReturn($isLive); | ||
$mockedConfig->method('getUrl')->willReturn('https://api.example/'); | ||
|
||
/** @var \Mockery\MockInterface $mockedClient */ | ||
$mockedClient = \Mockery::mock(\GuzzleHttp\Client::class); | ||
$mockedClient->shouldReceive('request')->withArgs([ | ||
'POST', | ||
'https://api.example/api/enquiry/accountEnquiry', | ||
[ | ||
\GuzzleHttp\RequestOptions::HTTP_ERRORS => false, | ||
\GuzzleHttp\RequestOptions::HEADERS => [ | ||
'Accept' => 'application/json', | ||
'Authorization' => "Bearer {$this->authToken}", | ||
], | ||
\GuzzleHttp\RequestOptions::JSON => [ | ||
'destinationBankCode' => $this->bankCode, | ||
'accountNumber' => $this->accountNumber, | ||
], | ||
], | ||
])->once(); | ||
|
||
$mockedCache = $this->getMockBuilder(CacheInterface::class)->getMock(); | ||
$mockedCache->method('has')->willReturn(true); | ||
$mockedCache->method('get')->willReturn($this->authToken); | ||
|
||
/** | ||
* @var ConfigInterface $mockedConfig | ||
* @var \GuzzleHttp\Client $mockedClient | ||
* @var CacheInterface $mockedCache | ||
* */ | ||
$api = new Client($mockedConfig, $mockedClient, $mockedCache); | ||
|
||
$requestResult = $api->fetchAccountRaw($this->bankCode, $this->accountNumber); | ||
|
||
$this->assertInstanceOf(ResponseInterface::class, $requestResult); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\ZenithBank\Tests; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use BrokeYourBike\ZenithBank\Interfaces\ConfigInterface; | ||
use BrokeYourBike\ZenithBank\Client; | ||
|
||
/** | ||
* @author Ivan Stasiuk <brokeyourbike@gmail.com> | ||
*/ | ||
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 | ||
{ | ||
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock(); | ||
$mockedConfig->method('isLive')->willReturn($isLive); | ||
$mockedConfig->method('getUrl')->willReturn('https://api.example/'); | ||
|
||
/** @var \Mockery\MockInterface $mockedClient */ | ||
$mockedClient = \Mockery::mock(\GuzzleHttp\Client::class); | ||
$mockedClient->shouldReceive('request')->withArgs([ | ||
'POST', | ||
'https://api.example/api/enquiry/balance', | ||
[ | ||
\GuzzleHttp\RequestOptions::HTTP_ERRORS => false, | ||
\GuzzleHttp\RequestOptions::HEADERS => [ | ||
'Accept' => 'application/json', | ||
'Authorization' => "Bearer {$this->authToken}", | ||
], | ||
\GuzzleHttp\RequestOptions::JSON => [ | ||
'accountNumber' => $this->accountNumber, | ||
], | ||
], | ||
])->once(); | ||
|
||
$mockedCache = $this->getMockBuilder(CacheInterface::class)->getMock(); | ||
$mockedCache->method('has')->willReturn(true); | ||
$mockedCache->method('get')->willReturn($this->authToken); | ||
|
||
/** | ||
* @var ConfigInterface $mockedConfig | ||
* @var \GuzzleHttp\Client $mockedClient | ||
* @var CacheInterface $mockedCache | ||
* */ | ||
$api = new Client($mockedConfig, $mockedClient, $mockedCache); | ||
|
||
$requestResult = $api->fetchBalanceRaw($this->accountNumber); | ||
|
||
$this->assertInstanceOf(ResponseInterface::class, $requestResult); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
// Copyright (C) 2021 Ivan Stasiuk <brokeyourbike@gmail.com>. | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace BrokeYourBike\ZenithBank\Tests; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use BrokeYourBike\ZenithBank\Interfaces\ConfigInterface; | ||
use BrokeYourBike\ZenithBank\Client; | ||
|
||
/** | ||
* @author Ivan Stasiuk <brokeyourbike@gmail.com> | ||
*/ | ||
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 | ||
{ | ||
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock(); | ||
$mockedConfig->method('isLive')->willReturn($isLive); | ||
$mockedConfig->method('getUrl')->willReturn('https://api.example/'); | ||
|
||
/** @var \Mockery\MockInterface $mockedClient */ | ||
$mockedClient = \Mockery::mock(\GuzzleHttp\Client::class); | ||
$mockedClient->shouldReceive('request')->withArgs([ | ||
'POST', | ||
'https://api.example/api/enquiry/domAccountEnquiry', | ||
[ | ||
\GuzzleHttp\RequestOptions::HTTP_ERRORS => false, | ||
\GuzzleHttp\RequestOptions::HEADERS => [ | ||
'Accept' => 'application/json', | ||
'Authorization' => "Bearer {$this->authToken}", | ||
], | ||
\GuzzleHttp\RequestOptions::JSON => [ | ||
'accountNumber' => $this->accountNumber, | ||
], | ||
], | ||
])->once(); | ||
|
||
$mockedCache = $this->getMockBuilder(CacheInterface::class)->getMock(); | ||
$mockedCache->method('has')->willReturn(true); | ||
$mockedCache->method('get')->willReturn($this->authToken); | ||
|
||
/** | ||
* @var ConfigInterface $mockedConfig | ||
* @var \GuzzleHttp\Client $mockedClient | ||
* @var CacheInterface $mockedCache | ||
* */ | ||
$api = new Client($mockedConfig, $mockedClient, $mockedCache); | ||
|
||
$requestResult = $api->fetchDomesticAccountRaw($this->accountNumber); | ||
|
||
$this->assertInstanceOf(ResponseInterface::class, $requestResult); | ||
} | ||
} |
Oops, something went wrong.