ReceivePaymentRequestTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 41
c 3
b 0
f 0
dl 0
loc 65
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSendWithStringValues() 0 30 1
A testSend() 0 30 1
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call;
4
5
use DateTimeImmutable;
6
use PHPUnit\Framework\MockObject\MockObject;
7
use PHPUnit\Framework\TestCase;
8
use SlevomatCsobGateway\Api\ApiClient;
9
use SlevomatCsobGateway\Api\Response;
10
use SlevomatCsobGateway\Api\ResponseCode;
11
12
class ReceivePaymentRequestTest extends TestCase
13
{
14
15
	public function testSend(): void
16
	{
17
		$postData = [
18
			'payId' => '123456789',
19
			'dttm' => '20140425131559',
20
			'resultCode' => 0,
21
			'resultMessage' => 'OK',
22
			'paymentStatus' => 5,
23
		];
24
25
		/** @var ApiClient|MockObject $apiClient */
26
		$apiClient = $this->getMockBuilder(ApiClient::class)
27
			->disableOriginalConstructor()
28
			->getMock();
29
30
		$apiClient->expects(self::once())->method('createResponseByData')
31
			->willReturnCallback(static function (array $postData): Response {
32
				return new Response(ResponseCode::get(ResponseCode::S200_OK), $postData);
33
			});
34
35
		$receivePaymentRequest = new ReceivePaymentRequest();
36
37
		$paymentResponse = $receivePaymentRequest->send($apiClient, $postData);
38
39
		self::assertSame('123456789', $paymentResponse->getPayId());
40
		self::assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentResponse->getResponseDateTime());
41
		self::assertEquals(ResultCode::get(ResultCode::C0_OK), $paymentResponse->getResultCode());
42
		self::assertSame('OK', $paymentResponse->getResultMessage());
43
		self::assertEquals(PaymentStatus::get(PaymentStatus::S5_REVOKED), $paymentResponse->getPaymentStatus());
44
		self::assertNull($paymentResponse->getAuthCode());
45
	}
46
47
	public function testSendWithStringValues(): void
48
	{
49
		$postData = [
50
			'payId' => '123456789',
51
			'dttm' => '20140425131559',
52
			'resultCode' => '0',
53
			'resultMessage' => 'OK',
54
			'paymentStatus' => '5',
55
		];
56
57
		/** @var ApiClient|MockObject $apiClient */
58
		$apiClient = $this->getMockBuilder(ApiClient::class)
59
			->disableOriginalConstructor()
60
			->getMock();
61
62
		$apiClient->expects(self::once())->method('createResponseByData')
63
			->willReturnCallback(static function (array $postData): Response {
64
				return new Response(ResponseCode::get(ResponseCode::S200_OK), $postData);
65
			});
66
67
		$receivePaymentRequest = new ReceivePaymentRequest();
68
69
		$paymentResponse = $receivePaymentRequest->send($apiClient, $postData);
70
71
		self::assertSame('123456789', $paymentResponse->getPayId());
72
		self::assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentResponse->getResponseDateTime());
73
		self::assertEquals(ResultCode::get(ResultCode::C0_OK), $paymentResponse->getResultCode());
74
		self::assertSame('OK', $paymentResponse->getResultMessage());
75
		self::assertEquals(PaymentStatus::get(PaymentStatus::S5_REVOKED), $paymentResponse->getPaymentStatus());
76
		self::assertNull($paymentResponse->getAuthCode());
77
	}
78
79
}
80