-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransactionLookupRawTest.php
73 lines (62 loc) · 2.5 KB
/
TransactionLookupRawTest.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
65
66
67
68
69
70
71
72
73
<?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 Carbon\Carbon;
use BrokeYourBike\ZenithBank\Interfaces\ConfigInterface;
use BrokeYourBike\ZenithBank\Client;
/**
* @author Ivan Stasiuk <brokeyourbike@gmail.com>
*/
class TransactionLookupRawTest extends TestCase
{
private string $authToken = 'secure-token';
private string $accountNumber = '123456';
private \DateTime $transactionDate;
/**
* This method is called before each test.
*/
protected function setUp(): void
{
$this->transactionDate = Carbon::create(2020, 1, 5, 23, 30, 59);
}
/** @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/transactionLookup',
[
\GuzzleHttp\RequestOptions::HTTP_ERRORS => false,
\GuzzleHttp\RequestOptions::HEADERS => [
'Accept' => 'application/json',
'Authorization' => "Bearer {$this->authToken}",
],
\GuzzleHttp\RequestOptions::JSON => [
'accountNumber' => $this->accountNumber,
'transactionDate' => '2020-01-05',
],
],
])->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->transactionLookupRaw($this->accountNumber, $this->transactionDate);
$this->assertInstanceOf(ResponseInterface::class, $requestResult);
}
}