Completed
Pull Request — master (#16)
by Josef
05:49
created

InitPaymentRequestTest::testSend()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 33
nc 1
nop 0
dl 0
loc 44
rs 8.8571
c 2
b 0
f 1
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call\Oneclick;
4
5
use DateTimeImmutable;
6
use SlevomatCsobGateway\Api\ApiClient;
7
use SlevomatCsobGateway\Api\Response;
8
use SlevomatCsobGateway\Api\ResponseCode;
9
use SlevomatCsobGateway\Call\PaymentResponse;
10
use SlevomatCsobGateway\Call\PaymentStatus;
11
use SlevomatCsobGateway\Call\ResultCode;
12
use SlevomatCsobGateway\Currency;
13
use SlevomatCsobGateway\Price;
14
15
class InitPaymentRequestTest extends \PHPUnit_Framework_TestCase
16
{
17
18
	public function testSend()
19
	{
20
		$apiClient = $this->getMockBuilder(ApiClient::class)
21
			->disableOriginalConstructor()
22
			->getMock();
23
24
		$apiClient->expects(self::once())->method('post')
25
			->with('payment/oneclick/init', [
26
				'merchantId' => '012345',
27
				'origPayId' => 'ef08b6e9f22345c',
28
				'orderNo' => '5547',
29
				'totalAmount' => 1789600,
30
				'currency' => 'CZK',
31
				'description' => 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)',
32
			])
33
			->willReturn(
34
				new Response(new ResponseCode(ResponseCode::S200_OK), [
35
					'payId' => '123456789',
36
					'dttm' => '20140425131559',
37
					'resultCode' => 0,
38
					'resultMessage' => 'OK',
39
					'paymentStatus' => 1,
40
				])
41
			);
42
43
		$initPaymentRequest = new InitPaymentRequest(
44
			'012345',
45
			'ef08b6e9f22345c',
46
			'5547',
47
			new Price(1789600, new Currency(Currency::CZK)),
48
			'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)'
49
		);
50
51
		/** @var ApiClient $apiClient */
52
		$paymentResponse = $initPaymentRequest->send($apiClient);
53
54
		$this->assertInstanceOf(PaymentResponse::class, $paymentResponse);
55
		$this->assertSame('123456789', $paymentResponse->getPayId());
56
		$this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentResponse->getResponseDateTime());
57
		$this->assertEquals(new ResultCode(ResultCode::C0_OK), $paymentResponse->getResultCode());
58
		$this->assertSame('OK', $paymentResponse->getResultMessage());
59
		$this->assertEquals(new PaymentStatus(PaymentStatus::S1_CREATED), $paymentResponse->getPaymentStatus());
60
		$this->assertNull($paymentResponse->getAuthCode());
61
	}
62
63
}
64