Completed
Push — master ( 0f907a...866d23 )
by Andrii
02:30
created

CompletePurchaseRequestTest::testSendData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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 View Code Duplication
    public function testGetData()
0 ignored issues
show
Duplication introduced by Andrii Vasyliev
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...
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