-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FetchAccountRawTest.php
64 lines (54 loc) · 2.29 KB
/
FetchAccountRawTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?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 */
public function it_can_prepare_request(): void
{
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
$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);
}
}