Completed
Push — master ( 955097...f4414e )
by Jan
08:34
created

InitApplePayRequestTest::testSend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 43
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

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