-
Notifications
You must be signed in to change notification settings - Fork 3
/
PurchaseOfflineRequestTest.php
86 lines (71 loc) · 3.14 KB
/
PurchaseOfflineRequestTest.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
<?php
declare(strict_types=1);
namespace Message;
use Omnipay\Przelewy24\Message\PurchaseOfflineRequest;
use Omnipay\Przelewy24\Message\PurchaseOfflineResponse;
use Omnipay\Tests\TestCase;
use Symfony\Component\HttpFoundation\Response;
class PurchaseOfflineRequestTest extends TestCase
{
/**
* @var PurchaseOfflineRequest
*/
private $request;
public function setUp(): void
{
$this->request = new PurchaseOfflineRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize([
'token' => '29fa01f8-6bb8-4187-9fb0-ec6e1a62a731',
]);
}
public function testGetData(): void
{
$data = $this->request->getData();
$this->assertSame('29fa01f8-6bb8-4187-9fb0-ec6e1a62a731', $data['token']);
}
public function testSendSuccess(): void
{
$this->setMockHttpResponse('PurchaseOfflineSuccess.txt');
/** @var PurchaseOfflineResponse $response */
$response = $this->request->send();
$this->assertInstanceOf(PurchaseOfflineResponse::class, $response);
$this->assertTrue($response->isSuccessful());
$this->assertSame(Response::HTTP_OK, $response->getCode());
$data = $response->getInfo();
$this->assertCount(7, $data);
$this->assertSame(1234567890, $data['transactionId']);
$this->assertSame('cb53d93f-3933-48dd-9756-13e6c03a74c0', $data['sessionId']);
$this->assertSame(1234, $data['amount']);
$this->assertSame('statement-full', $data['statement']);
$this->assertSame('PL21109024021694854264921521', $data['iban']);
$this->assertSame('Franek Dolas', $data['ibanOwner']);
$this->assertSame('Strzebrzeszyn 123', $data['ibanOwnerAddress']);
}
public function testSendAuthFailure(): void
{
$this->setMockHttpResponse('PurchaseOfflineAuthFailure.txt');
$response = $this->request->send();
$this->assertInstanceOf(PurchaseOfflineResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getCode());
$this->assertSame('Incorrect authentication', $response->getMessage());
}
public function testSendInvalidDataFailure(): void
{
$this->setMockHttpResponse('PurchaseOfflineInvalidDataFailure.txt');
$response = $this->request->send();
$this->assertInstanceOf(PurchaseOfflineResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$this->assertSame(Response::HTTP_BAD_REQUEST, $response->getCode());
$this->assertSame('Invalid input data', $response->getMessage());
}
public function testSendUnableToCreateFailure(): void
{
$this->setMockHttpResponse('PurchaseOfflineUnableToCreateFailure.txt');
$response = $this->request->send();
$this->assertInstanceOf(PurchaseOfflineResponse::class, $response);
$this->assertFalse($response->isSuccessful());
$this->assertSame(Response::HTTP_CONFLICT, $response->getCode());
$this->assertSame('Unable to create offline transaction', $response->getMessage());
}
}