InitApplePayRequestTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 33
dl 0
loc 46
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testSend() 0 43 1
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call\ApplePay;
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
use SlevomatCsobGateway\Call\PaymentStatus;
12
use SlevomatCsobGateway\Call\ResultCode;
13
use SlevomatCsobGateway\Currency;
14
use SlevomatCsobGateway\Price;
15
16
class InitApplePayRequestTest extends TestCase
17
{
18
19
	public function testSend(): void
20
	{
21
		/** @var ApiClient|MockObject $apiClient */
22
		$apiClient = $this->getMockBuilder(ApiClient::class)
23
			->disableOriginalConstructor()
24
			->getMock();
25
26
		$apiClient->expects(self::once())->method('post')
27
			->with('applepay/init', [
28
				'merchantId' => '012345',
29
				'orderNo' => '12345',
30
				'clientIp' => '127.0.0.1',
31
				'totalAmount' => 1789600,
32
				'currency' => 'CZK',
33
				'closePayment' => true,
34
			])
35
			->willReturn(
36
				new Response(ResponseCode::get(ResponseCode::S200_OK), [
37
					'payId' => '123456789',
38
					'dttm' => '20190425131559',
39
					'resultCode' => 0,
40
					'resultMessage' => 'OK',
41
					'paymentStatus' => 1,
42
				])
43
			);
44
45
		$initPaymentRequest = new InitApplePayRequest(
46
			'012345',
47
			'12345',
48
			'127.0.0.1',
49
			new Price(1789600, Currency::get(Currency::CZK)),
50
			true,
51
			null
52
		);
53
54
		$paymentResponse = $initPaymentRequest->send($apiClient);
55
56
		self::assertSame('123456789', $paymentResponse->getPayId());
57
		self::assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20190425131559'), $paymentResponse->getResponseDateTime());
58
		self::assertEquals(ResultCode::get(ResultCode::C0_OK), $paymentResponse->getResultCode());
59
		self::assertSame('OK', $paymentResponse->getResultMessage());
60
		self::assertEquals(PaymentStatus::get(PaymentStatus::S1_CREATED), $paymentResponse->getPaymentStatus());
61
		self::assertNull($paymentResponse->getAuthCode());
62
	}
63
64
}
65