1
|
|
|
<?php |
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
|
|
View Code Duplication |
class RefundPaymentRequestTest extends \PHPUnit_Framework_TestCase |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
public function testSend() |
14
|
|
|
{ |
15
|
|
|
$apiClient = $this->getMockBuilder(ApiClient::class) |
16
|
|
|
->disableOriginalConstructor() |
17
|
|
|
->getMock(); |
18
|
|
|
|
19
|
|
|
$apiClient->expects(self::once())->method('put') |
20
|
|
|
->with('payment/refund', [ |
21
|
|
|
'merchantId' => '012345', |
22
|
|
|
'payId' => '123456789', |
23
|
|
|
]) |
24
|
|
|
->willReturn( |
25
|
|
|
new Response(new ResponseCode(ResponseCode::S200_OK), [ |
26
|
|
|
'payId' => '123456789', |
27
|
|
|
'dttm' => '20140425131559', |
28
|
|
|
'resultCode' => 0, |
29
|
|
|
'resultMessage' => 'OK', |
30
|
|
|
'paymentStatus' => 8, |
31
|
|
|
]) |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
/** @var ApiClient $apiClient */ |
35
|
|
|
$refundPaymentRequest = new RefundPaymentRequest( |
36
|
|
|
'012345', |
37
|
|
|
'123456789' |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
$paymentResponse = $refundPaymentRequest->send($apiClient); |
41
|
|
|
|
42
|
|
|
$this->assertInstanceOf(PaymentResponse::class, $paymentResponse); |
43
|
|
|
$this->assertSame('123456789', $paymentResponse->getPayId()); |
44
|
|
|
$this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentResponse->getResponseDateTime()); |
45
|
|
|
$this->assertEquals(new ResultCode(ResultCode::C0_OK), $paymentResponse->getResultCode()); |
46
|
|
|
$this->assertSame('OK', $paymentResponse->getResultMessage()); |
47
|
|
|
$this->assertEquals(new PaymentStatus(PaymentStatus::S8_CHARGED), $paymentResponse->getPaymentStatus()); |
48
|
|
|
$this->assertNull($paymentResponse->getAuthCode()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
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.