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

PaymentButtonRequestTest::testSend()   A

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