CompletePurchaseResponseTest::testSuccess()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 9.44
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * OKPAY driver for Omnipay PHP payment library.
4
 *
5
 * @link      https://github.com/hiqdev/omnipay-okpay
6
 * @package   omnipay-okpay
7
 * @license   MIT
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace Omnipay\OKPAY\Message;
12
13
use Omnipay\Tests\TestCase;
14
15
class CompletePurchaseResponseTest extends TestCase
16
{
17
    private $request;
18
19
    private $purse                  = '[email protected]';
20
    private $description            = 'sDf#$Sdf#$%';
21
    private $transactionReference   = '1234567890';
22
    private $transactionId          = '843145';
23
    private $amount                 = '8.69';
24
    private $currency               = 'USD';
25
    private $testMode               = true;
26
    private $status                 = 'completed';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
27
    private $fee                    = '0.00';
28
    private $payer_first_name       = 'FirstName';
29
    private $payer_last_name        = 'LastName';
30
    private $payer_email            = '[email protected]';
31
    private $datetime               = '2017-09-20 16:07:50';
32
33
    public function setUp()
34
    {
35
        parent::setUp();
36
37
        $this->request = new CompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
38
        $this->request->initialize([
39
            'purse'     => $this->purse,
40
            'secret'    => $this->secret,
0 ignored issues
show
Bug introduced by
The property secret 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...
41
            'testMode'  => $this->testMode,
42
        ]);
43
    }
44
45
    public function testSuccess()
46
    {
47
        $response = new CompletePurchaseResponse($this->request, [
48
            'ok_item_1_name'            => $this->description,
49
            'ok_receiver'               => $this->purse,
50
            'ok_txn_gross'              => $this->amount,
51
            'ok_txn_datetime'           => $this->datetime,
52
            'ok_invoice'                => $this->transactionId,
53
            'ok_txn_id'                 => $this->transactionReference,
54
            'ok_txn_status'             => $this->status,
55
            'ok_txn_currency'           => $this->currency,
56
            'ok_txn_fee'                => $this->fee,
57
            'ok_payer_first_name'       => $this->payer_first_name,
58
            'ok_payer_last_name'        => $this->payer_last_name,
59
            'ok_payer_email'            => $this->payer_email,
60
        ]);
61
62
        $this->assertTrue($response->isSuccessful());
63
        $this->assertNull($response->getMessage());
64
        $this->assertNull($response->getCode());
65
        $this->assertSame($this->amount,                $response->getAmount());
66
        $this->assertSame($this->description,           $response->getDescription());
67
        $this->assertSame($this->purse,                 $response->getPurse());
68
        $this->assertSame($this->currency,              $response->getCurrency());
69
        $this->assertSame($this->transactionId,         $response->getTransactionId());
70
        $this->assertSame($this->transactionReference,  $response->getTransactionReference());
71
        $this->assertSame($this->fee,                   $response->getFee());
72
        $this->assertEquals(new \DateTime($this->datetime), $response->getTime());
73
        $this->assertSame($this->payer_first_name . ' ' . $this->payer_last_name . ' / ' . $this->payer_email, $response->getPayer());
74
    }
75
}
76