StartApplePayRequestTest::testSend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
dl 0
loc 38
rs 9.488
c 1
b 0
f 0
cc 1
nc 1
nop 0
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
14
class StartApplePayRequestTest extends TestCase
15
{
16
17
	public function testSend(): void
18
	{
19
		/** @var ApiClient|MockObject $apiClient */
20
		$apiClient = $this->getMockBuilder(ApiClient::class)
21
			->disableOriginalConstructor()
22
			->getMock();
23
24
		$apiClient->expects(self::once())->method('post')
25
			->with('applepay/start', [
26
				'merchantId' => '012345',
27
				'payId' => 'ef08b6e9f22345c',
28
				'payload' => 'eyJmb28iOiJiYXIifQ==',
29
			])
30
			->willReturn(
31
				new Response(ResponseCode::get(ResponseCode::S200_OK), [
32
					'payId' => 'ef08b6e9f22345c',
33
					'dttm' => '20190425131559',
34
					'resultCode' => 0,
35
					'resultMessage' => 'OK',
36
					'paymentStatus' => 2,
37
				])
38
			);
39
40
		$initPaymentRequest = new StartApplePayRequest(
41
			'012345',
42
			'ef08b6e9f22345c',
43
			['foo' => 'bar'],
44
			null
45
		);
46
47
		$paymentResponse = $initPaymentRequest->send($apiClient);
48
49
		self::assertSame('ef08b6e9f22345c', $paymentResponse->getPayId());
50
		self::assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20190425131559'), $paymentResponse->getResponseDateTime());
51
		self::assertEquals(ResultCode::get(ResultCode::C0_OK), $paymentResponse->getResultCode());
52
		self::assertSame('OK', $paymentResponse->getResultMessage());
53
		self::assertEquals(PaymentStatus::get(PaymentStatus::S2_IN_PROGRESS), $paymentResponse->getPaymentStatus());
54
		self::assertNull($paymentResponse->getAuthCode());
55
	}
56
57
}
58