-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FetchAuthTokenRawTest.php
61 lines (52 loc) · 2.18 KB
/
FetchAuthTokenRawTest.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
<?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 FetchAuthTokenRawTest extends TestCase
{
private string $username = 'unique-username';
private string $password = 'secure-password';
/** @test */
public function it_can_prepare_request(): void
{
$mockedConfig = $this->getMockBuilder(ConfigInterface::class)->getMock();
$mockedConfig->method('getUrl')->willReturn('https://api.example/');
$mockedConfig->method('getUsername')->willReturn($this->username);
$mockedConfig->method('getPassword')->willReturn($this->password);
/** @var \Mockery\MockInterface $mockedClient */
$mockedClient = \Mockery::mock(\GuzzleHttp\Client::class);
$mockedClient->shouldReceive('request')->withArgs([
'POST',
'https://api.example/api/authentication/getToken',
[
\GuzzleHttp\RequestOptions::HTTP_ERRORS => false,
\GuzzleHttp\RequestOptions::HEADERS => [
'Accept' => 'application/json',
],
\GuzzleHttp\RequestOptions::JSON => [
'userIdentifyer' => $this->username,
'userProtector' => $this->password,
],
],
])->once();
$mockedCache = $this->getMockBuilder(CacheInterface::class)->getMock();
/**
* @var ConfigInterface $mockedConfig
* @var \GuzzleHttp\Client $mockedClient
* @var CacheInterface $mockedCache
* */
$api = new Client($mockedConfig, $mockedClient, $mockedCache);
$requestResult = $api->fetchAuthTokenRaw();
$this->assertInstanceOf(ResponseInterface::class, $requestResult);
}
}