Completed
Push — master ( 136808...1b7afa )
by Dmitry
9s
created

CompletePurchaseRequestTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 92
Duplicated Lines 23.91 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 0 Features 3
Metric Value
wmc 4
c 3
b 0
f 3
lcom 1
cbo 3
dl 22
loc 92
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 22 22 1
A testGetData() 0 11 1
A testSendData() 0 6 1
B testTestMode() 0 30 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
2
3
/*
4
 * InterKassa driver for the Omnipay PHP payment processing library
5
 *
6
 * @link      https://github.com/hiqdev/omnipay-interkassa
7
 * @package   omnipay-interkassa
8
 * @license   MIT
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace Omnipay\InterKassa\Tests\Message;
13
14
use Omnipay\InterKassa\Message\CompletePurchaseRequest;
15
use Omnipay\Tests\TestCase;
16
use Symfony\Component\HttpFoundation\Request as HttpRequest;
17
18
class CompletePurchaseRequestTest extends TestCase
19
{
20
    /**
21
     * @var CompletePurchaseRequest
22
     */
23
    protected $request;
24
25
    protected $purse = '887ac1234c1eeee1488b156b';
26
    protected $signAlgorithm = 'sha256';
27
    protected $signKey = 'Zp2zfdSJzbS61L32';
28
    protected $testKey = 'W0b98idvHeKY2h3w';
29
    protected $description = 'Test Transaction long description';
30
    protected $transactionId = 'ID_123456';
31
    protected $amount = '1465.01';
32
    protected $currency = 'USD';
33
    protected $state = 'success';
34
    protected $time = '2015-12-22 11:07:12';
35
    protected $sign = 'ACm/nwG2yH1y3EVWIriFz4xP3icbqihbAr+06nAsgcU=';
36
37 View Code Duplication
    public function setUp()
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...
38
    {
39
        parent::setUp();
40
41
        $httpRequest = new HttpRequest([], [
42
            'ik_co_id' => $this->purse,
43
            'ik_trn_id' => $this->transactionId,
44
            'ik_desc' => $this->description,
45
            'ik_am' => $this->amount,
46
            'ik_cur' => $this->currency,
47
            'ik_inv_prc' => $this->time,
48
            'ik_sign' => $this->sign,
49
            'ik_inv_st' => $this->state,
50
        ]);
51
52
        $this->request = new CompletePurchaseRequest($this->getHttpClient(), $httpRequest);
53
        $this->request->initialize([
54
            'purse' => $this->purse,
55
            'signAlgorithm' => $this->signAlgorithm,
56
            'signKey' => $this->signKey,
57
        ]);
58
    }
59
60
    public function testGetData()
61
    {
62
        $data = $this->request->getData();
63
64
        $this->assertSame($this->purse, $data['ik_co_id']);
65
        $this->assertSame($this->transactionId, $data['ik_trn_id']);
66
        $this->assertSame($this->description, $data['ik_desc']);
67
        $this->assertSame($this->amount, $data['ik_am']);
68
        $this->assertSame($this->currency, $data['ik_cur']);
69
        $this->assertSame($this->time, $data['ik_inv_prc']);
70
    }
71
72
    public function testSendData()
73
    {
74
        $data = $this->request->getData();
75
        $response = $this->request->sendData($data);
76
        $this->assertSame('Omnipay\InterKassa\Message\CompletePurchaseResponse', get_class($response));
77
    }
78
79
    public function testTestMode()
80
    {
81
        $httpRequest = new HttpRequest([], [
82
            'ik_co_id' => $this->purse,
83
            'ik_trn_id' => $this->transactionId,
84
            'ik_desc' => $this->description,
85
            'ik_am' => $this->amount,
86
            'ik_cur' => $this->currency,
87
            'ik_inv_prc' => $this->time,
88
            'ik_sign' => $this->sign,
89
            'ik_inv_st' => $this->state,
90
        ]);
91
92
        $request = new CompletePurchaseRequest($this->getHttpClient(), $httpRequest);
93
        $request->initialize([
94
            'testMode' => true,
95
            'purse' => $this->purse,
96
            'signAlgorithm' => $this->signAlgorithm,
97
            'testKey' => $this->testKey,
98
        ]);
99
100
        $data = $request->getData();
101
102
        $this->assertSame($this->purse, $data['ik_co_id']);
103
        $this->assertSame($this->transactionId, $data['ik_trn_id']);
104
        $this->assertSame($this->description, $data['ik_desc']);
105
        $this->assertSame($this->amount, $data['ik_am']);
106
        $this->assertSame($this->currency, $data['ik_cur']);
107
        $this->assertSame($this->time, $data['ik_inv_prc']);
108
    }
109
}
110