StandardFinishRequestTest::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
cc 1
eloc 27
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 38
rs 9.488
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call\Masterpass;
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 StandardFinishRequestTest 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('masterpass/standard/finish', [
26
				'merchantId' => '012345',
27
				'payId' => '123456789',
28
				'oauthToken' => '123456789123456789',
29
				'totalAmount' => 15000,
30
			])
31
			->willReturn(
32
				new Response(ResponseCode::get(ResponseCode::S200_OK), [
33
					'payId' => '123456789',
34
					'dttm' => '20140425131559',
35
					'resultCode' => 0,
36
					'resultMessage' => 'OK',
37
					'paymentStatus' => 2,
38
				])
39
			);
40
41
		$paymentRequest = new StandardFinishRequest(
42
			'012345',
43
			'123456789',
44
			'123456789123456789',
45
			15000
46
		);
47
48
		$checkoutResponse = $paymentRequest->send($apiClient);
49
50
		self::assertSame('123456789', $checkoutResponse->getPayId());
51
		self::assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $checkoutResponse->getResponseDateTime());
52
		self::assertEquals(ResultCode::get(ResultCode::C0_OK), $checkoutResponse->getResultCode());
53
		self::assertSame('OK', $checkoutResponse->getResultMessage());
54
		self::assertEquals(PaymentStatus::get(PaymentStatus::S2_IN_PROGRESS), $checkoutResponse->getPaymentStatus());
55
	}
56
57
}
58