CompletePurchaseRequestTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 30 1
A testGetData() 0 11 1
A testSendData() 0 6 1
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 Guzzle\Http\Message\Response;
15
use Omnipay\Tests\TestCase;
16
use Symfony\Component\HttpFoundation\Request as HttpRequest;
17
18
class CompletePurchaseRequestTest extends TestCase
19
{
20
    private $request;
21
22
    private $purse                  = '[email protected]';
23
    private $secret                 = '*&^^&$sdf&(23';
24
    private $hash                   = '33bfff79d7eeffdca9a9ac7b34a78dfc';
0 ignored issues
show
Unused Code introduced by Andrii Vasyliev
The property $hash is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
25
    private $description            = 'Test Transaction long description';
26
    private $transactionId          = '12345ASD67890sd';
27
    private $transactionReference   = '12345678';
28
    private $timestamp              = '2016-02-02 16:56:56 UTC';
0 ignored issues
show
Unused Code introduced by Andrii Vasyliev
The property $timestamp is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
29
    private $payer                  = '[email protected]';
30
    private $amount                 = '1465.01';
31
    private $testMode               = false;
32
    private $response               = 'VERIFIED';
33
34
    public function setUp()
35
    {
36
        parent::setUp();
37
38
        $httpResponse = new Response(200, null, $this->response);
39
40
        $tmpRequest = $this->getMock('Guzzle\Http\Message\Request', ['send'], ['POST', '']);
41
        $tmpRequest->expects($this->any())->method('send')->will($this->returnValue($httpResponse));
42
43
        $httpClient = $this->getMock('Guzzle\Http\Client', ['setConfig', 'post']);
44
        $httpClient->expects($this->any())->method('post')->will($this->returnValue($tmpRequest));
45
46
        $httpRequest = new HttpRequest([], [
47
            'business'          => $this->purse,
48
            'payment_gross'     => $this->amount,
49
            'item_name'         => $this->description,
50
            'mc_currency'       => $this->currency,
0 ignored issues
show
Bug introduced by Andrii Vasyliev
The property currency does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
51
            'payer_email'       => $this->payer,
52
            'payment_date'      => $this->time,
0 ignored issues
show
Bug introduced by Andrii Vasyliev
The property time does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
53
            'item_number'       => $this->transactionId,
54
            'txn_id'            => $this->transactionReference,
55
        ]);
56
57
        $this->request = new CompletePurchaseRequest($httpClient, $httpRequest);
58
        $this->request->initialize([
59
            'purse'     => $this->purse,
60
            'secret'    => $this->secret,
61
            'testMode'  => $this->testMode,
62
        ]);
63
    }
64
65
    public function testGetData()
66
    {
67
        $data = $this->request->getData();
68
69
        $this->assertSame($this->purse,         $data['business']);
70
        $this->assertSame($this->description,   $data['item_name']);
71
        $this->assertSame($this->transactionId, $data['item_number']);
72
        $this->assertSame($this->amount,        $data['payment_gross']);
73
        $this->assertSame($this->time,          $data['payment_date']);
74
        $this->assertSame($this->payer,         $data['payer_email']);
75
    }
76
77
    public function testSendData()
78
    {
79
        $data = $this->request->getData();
80
        $response = $this->request->sendData($data);
81
        $this->assertInstanceOf('Omnipay\PayPal\Message\CompletePurchaseResponse', $response);
82
    }
83
}
84