CompletePurchaseRequestTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 20.34 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 12
loc 59
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 23 1
A testGetData() 12 12 1
A testSendData() 0 6 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
 * eCoin driver for Omnipay PHP payment library
5
 *
6
 * @link      https://github.com/hiqdev/omnipay-ecoin
7
 * @package   omnipay-ecoin
8
 * @license   MIT
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace Omnipay\eCoin\Message;
13
14
use Omnipay\Tests\TestCase;
15
use Symfony\Component\HttpFoundation\Request as HttpRequest;
16
17
class CompletePurchaseRequestTest extends TestCase
18
{
19
    private $request;
20
21
    private $purse                  = 'ec12345';
22
    private $secret                 = '*&^^&$%&(23';
23
    private $hash                   = '33bfff79d7eeffdca9a9ac7b34a78dfc';
24
    private $description            = 'Test Transaction long description';
25
    private $transactionId          = '12345ASD67890sd';
26
    private $transactionReference   = '12345678';
27
    private $timestamp              = '1454331086';
28
    private $payer                  = 'ec54321';
29
    private $amount                 = '1465.01';
30
    private $testMode               = false;
31
32
    public function setUp()
33
    {
34
        parent::setUp();
35
36
        $httpRequest = new HttpRequest([], [
37
            'ECM_HASH'                  => $this->hash,
38
            'ECM_PURCH_DESC'            => $this->description,
39
            'ECM_PAYER_ID'              => $this->payer,
40
            'ECM_PAYEE_ID'              => $this->purse,
41
            'ECM_PAYMENT_AMOUNT'        => $this->amount,
42
            'ECM_ITEM_COST'             => $this->amount,
43
            'ECM_TRANS_DATE'            => $this->timestamp,
44
            'ECM_INV_NO'                => $this->transactionId,
45
            'ECM_TRANS_ID'              => $this->transactionReference,
46
        ]);
47
48
        $this->request = new CompletePurchaseRequest($this->getHttpClient(), $httpRequest);
49
        $this->request->initialize([
50
            'purse'     => $this->purse,
51
            'secret'    => $this->secret,
52
            'testMode'  => $this->testMode,
53
        ]);
54
    }
55
56 View Code Duplication
    public function testGetData()
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...
57
    {
58
        $data = $this->request->getData();
59
60
        $this->assertSame($this->description,   $data['ECM_PURCH_DESC']);
61
        $this->assertSame($this->transactionId, $data['ECM_INV_NO']);
62
        $this->assertSame($this->hash,          $data['ECM_HASH']);
63
        $this->assertSame($this->amount,        $data['ECM_PAYMENT_AMOUNT']);
64
        $this->assertSame($this->timestamp,     $data['ECM_TRANS_DATE']);
65
        $this->assertSame($this->payer,         $data['ECM_PAYER_ID']);
66
        $this->assertSame($this->purse,         $data['ECM_PAYEE_ID']);
67
    }
68
69
    public function testSendData()
70
    {
71
        $data = $this->request->getData();
72
        $response = $this->request->sendData($data);
73
        $this->assertInstanceOf('Omnipay\eCoin\Message\CompletePurchaseResponse', $response);
74
    }
75
}
76