Completed
Pull Request — master (#16)
by Josef
02:58
created

InitPaymentRequestTest::testSend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 50
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 37
nc 1
nop 0
dl 0
loc 50
rs 9.3333
c 1
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\Cart;
13
use SlevomatCsobGateway\Currency;
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
		/** @var ApiClient $apiClient */
44
		$cart = new Cart(
45
			new Currency(Currency::CZK)
46
		);
47
		$cart->addItem('Nákup na vasobchodcz', 1, 1789600, 'Lenovo ThinkPad Edge E540');
48
		$cart->addItem('Poštovné', 1, 0, 'Doprava PPL');
49
50
		$initPaymentRequest = new InitPaymentRequest(
51
			'012345',
52
			'ef08b6e9f22345c',
53
			'5547',
54
			$cart,
55
			'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)'
56
		);
57
58
		$paymentResponse = $initPaymentRequest->send($apiClient);
59
60
		$this->assertInstanceOf(PaymentResponse::class, $paymentResponse);
61
		$this->assertSame('123456789', $paymentResponse->getPayId());
62
		$this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentResponse->getResponseDateTime());
63
		$this->assertEquals(new ResultCode(ResultCode::C0_OK), $paymentResponse->getResultCode());
64
		$this->assertSame('OK', $paymentResponse->getResultMessage());
65
		$this->assertEquals(new PaymentStatus(PaymentStatus::S1_CREATED), $paymentResponse->getPaymentStatus());
66
		$this->assertNull($paymentResponse->getAuthCode());
67
	}
68
69
}
70