PaymentButtonRequestTest::testSend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 55
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 55
rs 9.232
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call\Button;
4
5
use DateTimeImmutable;
6
use PHPUnit\Framework\MockObject\MockObject;
7
use PHPUnit\Framework\TestCase;
8
use SlevomatCsobGateway\Api\ApiClient;
9
use SlevomatCsobGateway\Api\HttpMethod;
10
use SlevomatCsobGateway\Api\Response;
11
use SlevomatCsobGateway\Api\ResponseCode;
12
use SlevomatCsobGateway\Call\PaymentStatus;
13
use SlevomatCsobGateway\Call\ResultCode;
14
use SlevomatCsobGateway\Currency;
15
use SlevomatCsobGateway\Language;
16
use SlevomatCsobGateway\Price;
17
18
class PaymentButtonRequestTest extends TestCase
19
{
20
21
	public function testSend(): void
22
	{
23
		/** @var ApiClient|MockObject $apiClient */
24
		$apiClient = $this->getMockBuilder(ApiClient::class)
25
			->disableOriginalConstructor()
26
			->getMock();
27
28
		$apiClient->expects(self::once())->method('post')
29
			->with('button/init', [
30
				'merchantId' => '012345',
31
				'orderNo' => '123456789',
32
				'clientIp' => '127.0.0.1',
33
				'totalAmount' => 12000,
34
				'currency' => 'CZK',
35
				'returnUrl' => 'https://www.example.com/return',
36
				'returnMethod' => 'GET',
37
				'brand' => 'csob',
38
				'language' => 'EN',
39
			])
40
			->willReturn(
41
				new Response(ResponseCode::get(ResponseCode::S200_OK), [
42
					'payId' => '123456789',
43
					'dttm' => '20140425131559',
44
					'resultCode' => 0,
45
					'resultMessage' => 'OK',
46
					'paymentStatus' => 1,
47
					'redirect' => [
48
						'method' => 'GET',
49
						'url' => 'https://platebnibrana.csob.cz/pay/vasobchod.cz/2c72d818-9788-45a1-878a-9db2a706edc5/pt-detect/csob',
50
					],
51
				])
52
			);
53
54
		$paymentRequest = new PaymentButtonRequest(
55
			'012345',
56
			'123456789',
57
			'127.0.0.1',
58
			new Price(12000, Currency::get(Currency::CZK)),
59
			'https://www.example.com/return',
60
			HttpMethod::get(HttpMethod::GET),
61
			PaymentButtonBrand::get(PaymentButtonBrand::CSOB),
62
			null,
63
			Language::get(Language::EN)
64
		);
65
66
		$paymentButtonResponse = $paymentRequest->send($apiClient);
67
68
		self::assertSame('123456789', $paymentButtonResponse->getPayId());
69
		self::assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentButtonResponse->getResponseDateTime());
70
		self::assertEquals(ResultCode::get(ResultCode::C0_OK), $paymentButtonResponse->getResultCode());
71
		self::assertSame('OK', $paymentButtonResponse->getResultMessage());
72
		self::assertEquals(PaymentStatus::get(PaymentStatus::S1_CREATED), $paymentButtonResponse->getPaymentStatus());
73
		self::assertSame('https://platebnibrana.csob.cz/pay/vasobchod.cz/2c72d818-9788-45a1-878a-9db2a706edc5/pt-detect/csob', $paymentButtonResponse->getRedirectUrl());
74
		self::assertSame(HttpMethod::get(HttpMethod::GET), $paymentButtonResponse->getRedirectMethod());
75
		self::assertNull($paymentButtonResponse->getRedirectParams());
76
	}
77
78
}
79