Passed
Pull Request — master (#38)
by Jan
04:37
created

StandardExtractRequestTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A testSend() 0 68 1
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call\Masterpass;
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
13
class StandardExtractRequestTest extends TestCase
14
{
15
16
	public function testSend(): void
17
	{
18
		$apiClient = $this->getMockBuilder(ApiClient::class)
19
			->disableOriginalConstructor()
20
			->getMock();
21
22
		$apiClient->expects(self::once())->method('post')
23
			->with('masterpass/standard/extract', [
24
				'merchantId' => '012345',
25
				'payId' => '123456789',
26
				'callbackParams' => [
27
					'mpstatus' => 'success',
28
					'oauthToken' => '6a79bf9e320a0460d08aee7ad154f7dab4e19503',
29
					'checkoutResourceUrl' => 'https://sandbox.api.mastercard.com/masterpass/v6/checkout/616764812',
30
					'oauthVerifier' => 'fc8f41bb76ed7d43ea6d714cb8fdefa606611a7d',
31
				],
32
			])
33
			->willReturn(
34
				new Response(ResponseCode::get(ResponseCode::S200_OK), [
35
					'payId' => '123456789',
36
					'dttm' => '20140425131559',
37
					'resultCode' => 0,
38
					'resultMessage' => 'OK',
39
					'paymentStatus' => 2,
40
					'checkoutParams' => ['card' => [
41
						'maskedCln' => '****4145',
42
						'expiration' => '11/19',
43
						'billingAddress' =>
44
								[
45
									'city' => 'Praha 1',
46
									'country' => 'CZ',
47
									'line1' => 'Jindřišská 16',
48
									'postalCode' => '11150',
49
								],
50
					],
51
						'shippingAddress' =>
52
							[
53
								'recipientName' => 'Jan Novák',
54
								'recipientPhoneNumber' => '+420602123456',
55
								'city' => 'Praha 1',
56
								'country' => 'CZ',
57
								'line1' => 'Dlouhá 23',
58
								'postalCode' => '11150',
59
							],
60
					],
61
				])
62
			);
63
64
		/** @var ApiClient $apiClient */
65
		$paymentRequest = new StandardExtractRequest(
66
			'012345',
67
			'123456789',
68
			[
69
				'mpstatus' => 'success',
70
				'oauthToken' => '6a79bf9e320a0460d08aee7ad154f7dab4e19503',
71
				'checkoutResourceUrl' => 'https://sandbox.api.mastercard.com/masterpass/v6/checkout/616764812',
72
				'oauthVerifier' => 'fc8f41bb76ed7d43ea6d714cb8fdefa606611a7d',
73
			]
74
		);
75
76
		$extractResponse = $paymentRequest->send($apiClient);
77
78
		self::assertSame('123456789', $extractResponse->getPayId());
79
		self::assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $extractResponse->getResponseDateTime());
80
		self::assertEquals(ResultCode::get(ResultCode::C0_OK), $extractResponse->getResultCode());
81
		self::assertSame('OK', $extractResponse->getResultMessage());
82
		self::assertEquals(PaymentStatus::get(PaymentStatus::S2_IN_PROGRESS), $extractResponse->getPaymentStatus());
83
		self::assertNotNull($extractResponse->getCheckoutParams());
84
	}
85
86
}
87