1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace SlevomatCsobGateway\Call; |
4
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
6
|
|
|
use SlevomatCsobGateway\Api\ApiClient; |
7
|
|
|
use SlevomatCsobGateway\Api\Response; |
8
|
|
|
use SlevomatCsobGateway\Api\ResponseCode; |
9
|
|
|
|
10
|
|
|
class ReceivePaymentRequestTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
View Code Duplication |
public function testSend() |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
$postData = [ |
16
|
|
|
'payId' => '123456789', |
17
|
|
|
'dttm' => '20140425131559', |
18
|
|
|
'resultCode' => 0, |
19
|
|
|
'resultMessage' => 'OK', |
20
|
|
|
'paymentStatus' => 5, |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
$apiClient = $this->getMockBuilder(ApiClient::class) |
24
|
|
|
->disableOriginalConstructor() |
25
|
|
|
->getMock(); |
26
|
|
|
|
27
|
|
|
$apiClient->expects(self::once())->method('createResponseByData') |
28
|
|
|
->willReturnCallback(function (array $postData) { |
29
|
|
|
return new Response(new ResponseCode(ResponseCode::S200_OK), $postData); |
30
|
|
|
}); |
31
|
|
|
|
32
|
|
|
/** @var ApiClient $apiClient */ |
33
|
|
|
$receivePaymentRequest = new ReceivePaymentRequest(); |
34
|
|
|
|
35
|
|
|
$paymentResponse = $receivePaymentRequest->send($apiClient, $postData); |
36
|
|
|
|
37
|
|
|
$this->assertInstanceOf(PaymentResponse::class, $paymentResponse); |
38
|
|
|
$this->assertSame('123456789', $paymentResponse->getPayId()); |
39
|
|
|
$this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentResponse->getResponseDateTime()); |
40
|
|
|
$this->assertEquals(new ResultCode(ResultCode::C0_OK), $paymentResponse->getResultCode()); |
41
|
|
|
$this->assertSame('OK', $paymentResponse->getResultMessage()); |
42
|
|
|
$this->assertEquals(new PaymentStatus(PaymentStatus::S5_REVOKED), $paymentResponse->getPaymentStatus()); |
43
|
|
|
$this->assertNull($paymentResponse->getAuthCode()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
View Code Duplication |
public function testSendWithStringValues() |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$postData = [ |
49
|
|
|
'payId' => '123456789', |
50
|
|
|
'dttm' => '20140425131559', |
51
|
|
|
'resultCode' => '0', |
52
|
|
|
'resultMessage' => 'OK', |
53
|
|
|
'paymentStatus' => '5', |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
$apiClient = $this->getMockBuilder(ApiClient::class) |
57
|
|
|
->disableOriginalConstructor() |
58
|
|
|
->getMock(); |
59
|
|
|
|
60
|
|
|
$apiClient->expects(self::once())->method('createResponseByData') |
61
|
|
|
->willReturnCallback(function (array $postData) { |
62
|
|
|
return new Response(new ResponseCode(ResponseCode::S200_OK), $postData); |
63
|
|
|
}); |
64
|
|
|
|
65
|
|
|
/** @var ApiClient $apiClient */ |
66
|
|
|
$receivePaymentRequest = new ReceivePaymentRequest(); |
67
|
|
|
|
68
|
|
|
$paymentResponse = $receivePaymentRequest->send($apiClient, $postData); |
69
|
|
|
|
70
|
|
|
$this->assertInstanceOf(PaymentResponse::class, $paymentResponse); |
71
|
|
|
$this->assertSame('123456789', $paymentResponse->getPayId()); |
72
|
|
|
$this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentResponse->getResponseDateTime()); |
73
|
|
|
$this->assertEquals(new ResultCode(ResultCode::C0_OK), $paymentResponse->getResultCode()); |
74
|
|
|
$this->assertSame('OK', $paymentResponse->getResultMessage()); |
75
|
|
|
$this->assertEquals(new PaymentStatus(PaymentStatus::S5_REVOKED), $paymentResponse->getPaymentStatus()); |
76
|
|
|
$this->assertNull($paymentResponse->getAuthCode()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.