Completed
Push — master ( 54bcb1...083d0b )
by Jan
03:06
created

ReceivePaymentRequestTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 70
Duplicated Lines 91.43 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 64
loc 70
rs 10
wmc 2
lcom 1
cbo 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testSend() 32 32 1
B testSendWithStringValues() 32 32 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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