InitOneClickPaymentRequestTest::testSend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 44
rs 9.392
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call\OneClick;
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 InitOneClickPaymentRequestTest 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('oneclick/init', [
28
				'merchantId' => '012345',
29
				'origPayId' => 'ef08b6e9f22345c',
30
				'orderNo' => '5547',
31
				'clientIp' => '127.0.0.1',
32
				'totalAmount' => 1789600,
33
				'currency' => 'CZK',
34
				'description' => 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)',
35
			])
36
			->willReturn(
37
				new Response(ResponseCode::get(ResponseCode::S200_OK), [
38
					'payId' => '123456789',
39
					'dttm' => '20140425131559',
40
					'resultCode' => 0,
41
					'resultMessage' => 'OK',
42
					'paymentStatus' => 1,
43
				])
44
			);
45
46
		$initPaymentRequest = new InitOneClickPaymentRequest(
47
			'012345',
48
			'ef08b6e9f22345c',
49
			'5547',
50
			'127.0.0.1',
51
			new Price(1789600, Currency::get(Currency::CZK)),
52
			'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)'
53
		);
54
55
		$paymentResponse = $initPaymentRequest->send($apiClient);
56
57
		self::assertSame('123456789', $paymentResponse->getPayId());
58
		self::assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentResponse->getResponseDateTime());
59
		self::assertEquals(ResultCode::get(ResultCode::C0_OK), $paymentResponse->getResultCode());
60
		self::assertSame('OK', $paymentResponse->getResultMessage());
61
		self::assertEquals(PaymentStatus::get(PaymentStatus::S1_CREATED), $paymentResponse->getPaymentStatus());
62
		self::assertNull($paymentResponse->getAuthCode());
63
	}
64
65
}
66