forked from mysiar-org/omnipay-przelewy24v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlikChargeByAliasRequestTest.php
100 lines (83 loc) · 3.58 KB
/
BlikChargeByAliasRequestTest.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
declare(strict_types=1);
namespace Message;
use Omnipay\Przelewy24\Message\BlikChargeByAliasRequest;
use Omnipay\Przelewy24\Message\BlikChargeByAliasResponse;
use Omnipay\Przelewy24\Message\BlikChargeByCodeRequest;
use Omnipay\Tests\TestCase;
use Symfony\Component\HttpFoundation\Response;
class BlikChargeByAliasRequestTest extends TestCase
{
/**
* @var BlikChargeByCodeRequest
*/
private $request;
public function setUp(): void
{
$this->request = new BlikChargeByAliasRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize([
'token' => 'test1',
'type' => 'alias',
'aliasLabel' => 'test3',
'aliasValue' => 'test4',
'alternativeKey' => 'test5',
]);
}
public function testGetData(): void
{
$data = $this->request->getData();
$this->assertSame('test1', $data['token']);
$this->assertSame('alias', $data['type']);
$this->assertSame('test3', $data['aliasLabel']);
$this->assertSame('test4', $data['aliasValue']);
$this->assertSame('test5', $data['alternativeKey']);
}
public function testSendSuccess(): void
{
$this->setMockHttpResponse('BlikChargeByCodeSuccess.txt');
/** @var BlikChargeByAliasResponse $response */
$response = $this->request->send();
$this->assertInstanceOf(BlikChargeByAliasResponse::class, $response);
$this->assertTrue($response->isSuccessful());
$this->assertSame("test123", $response->getOrderId());
$this->assertSame("success", $response->getChargeMessage());
}
public function testSendFailure(): void
{
$this->setMockHttpResponse('BlikChargeByCodeFailure.txt');
$response = $this->request->send();
$this->assertInstanceOf(BlikChargeByAliasResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$this->assertSame(Response::HTTP_BAD_REQUEST, $response->getCode());
$this->assertSame('Invalid input data', $response->getMessage());
}
public function testSendAuthFailure(): void
{
$this->setMockHttpResponse('BlikChargeByCodeAuthFailure.txt');
$response = $this->request->send();
$this->assertInstanceOf(BlikChargeByAliasResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getCode());
$this->assertSame('Incorrect authentication', $response->getMessage());
}
public function testUndefinedError(): void
{
$this->setMockHttpResponse('BlikChargeByCodeUndefinedError.txt');
$response = $this->request->send();
$this->assertInstanceOf(BlikChargeByAliasResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$this->assertSame(Response::HTTP_INTERNAL_SERVER_ERROR, $response->getCode());
$this->assertSame("Undefined error", $response->getMessage());
}
public function testAlternativeKeys(): void
{
$this->setMockHttpResponse('BlikChargeByAliasAlternativeKeysFailure.txt');
$response = $this->request->send();
$this->assertInstanceOf(BlikChargeByAliasResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$this->assertSame(Response::HTTP_CONFLICT, $response->getCode());
$this->assertIsArray($response->getMessage());
$this->assertArrayHasKey('alternativeKeys', $response->getMessage());
$this->assertCount(2, $response->getMessage()['alternativeKeys']);
}
}