Completed
Pull Request — master (#3)
by
unknown
01:56
created

CompletePurchaseResponseTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 89
Duplicated Lines 17.98 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 3
dl 16
loc 89
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A testNotVerifiedException() 0 7 1
A testInvalidTestModeException() 8 8 1
A testInvalidPaymentStatusException() 8 8 1
B testSuccess() 0 31 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
 * PayPal driver for Omnipay PHP payment library
5
 *
6
 * @link      https://github.com/hiqdev/omnipay-paypal
7
 * @package   omnipay-paypal
8
 * @license   MIT
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace Omnipay\PayPal\Message;
13
14
use Omnipay\Tests\TestCase;
15
16
class CompletePurchaseResponseTest extends TestCase
17
{
18
    private $request;
19
    private $response               = 'VERIFIED';
20
21
    private $purse                  = '[email protected]';
22
    private $secret                 = '22SAD#-78G8sdf$88';
23
    private $description            = 'Test Transaction long description';
24
    private $transactionId          = '1SD672345A890sd';
25
    private $transactionStatus      = 'Completed';
26
    private $transactionReference   = 'sdfa1SD672345A8';
27
    private $time                   = '2016-02-02T18:50:20+00:00';
28
    private $payer                  = '[email protected]';
29
    private $address                = 'Somewhere str, 123';
30
    private $fee                    = '1.01';
31
    private $amount                 = '1465.01';
32
    private $currency               = 'USD';
33
    private $testMode               = true;
34
35
    public function setUp()
36
    {
37
        parent::setUp();
38
39
        $this->request = new CompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
40
        $this->request->initialize([
41
            'purse'         => $this->purse,
42
            'secret'        => $this->secret,
43
            'testMode'      => $this->testMode,
44
        ]);
45
    }
46
47
    public function testNotVerifiedException()
48
    {
49
        $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Not verified');
50
        new CompletePurchaseResponse($this->request, [
51
            'description'           => $this->description,
52
        ]);
53
    }
54
55 View Code Duplication
    public function testInvalidTestModeException()
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...
56
    {
57
        $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Invalid test mode');
58
        new CompletePurchaseResponse($this->request, [
59
            'item_name'         => $this->description,
60
            '_result'           => $this->response,
61
        ]);
62
    }
63
64 View Code Duplication
    public function testInvalidPaymentStatusException()
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...
65
    {
66
        $this->setExpectedException('Omnipay\Common\Exception\InvalidResponseException', 'Invalid payment status');
67
        new CompletePurchaseResponse($this->request, [
68
            'item_name'         => $this->description,
69
            '_result'           => $this->response,
70
        ]);
71
    }
72
73
    public function testSuccess()
74
    {
75
        $response = new CompletePurchaseResponse($this->request, [
76
            'test_ipn'          => $this->testMode,
77
            'business'          => $this->purse,
78
            'payment_fee'       => $this->fee,
79
            'payment_gross'     => $this->amount,
80
            'item_name'         => $this->description,
81
            'mc_currency'       => $this->currency,
82
            'payer_email'       => $this->payer,
83
            'address_name'      => $this->address,
84
            'payment_date'      => $this->time,
85
            'item_number'       => $this->transactionId,
86
            'payment_status'    => $this->transactionStatus,
87
            'txn_id'            => $this->transactionReference,
88
            '_result'           => $this->response,
89
        ]);
90
91
        $this->assertTrue($response->isSuccessful());
92
        $this->assertTrue($response->getTestMode());
93
        $this->assertNull($response->getMessage());
94
        $this->assertNull($response->getCode());
95
        $this->assertSame($this->transactionId,         $response->getTransactionId());
96
        $this->assertSame($this->transactionStatus,     $response->getTransactionStatus());
97
        $this->assertSame($this->transactionReference,  $response->getTransactionReference());
98
        $this->assertSame($this->fee,                   $response->getFee());
99
        $this->assertSame($this->amount,                $response->getAmount());
100
        $this->assertSame($this->currency,              $response->getCurrency());
101
        $this->assertSame($this->time,                  $response->getTime());
102
        $this->assertSame($this->address . '/' . $this->payer, $response->getPayer());
103
    }
104
}
105