Completed
Push — master ( 552a80...bb7932 )
by Vuong
01:49
created

BaoKimTest::testVerifyIPN()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
/**
3
 * @link https://github.com/yiiviet/yii2-payment
4
 * @copyright Copyright (c) 2017 Yii2VN
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace yiiviet\tests\unit\payment;
9
10
use Yii;
11
12
/**
13
 * Class BaoKimTest
14
 *
15
 * @author Vuong Minh <[email protected]>
16
 * @since 1.0
17
 */
18
class BaoKimTest extends TestCase
19
{
20
    /**
21
     * @var \yiiviet\payment\baokim\PaymentGateway
22
     */
23
    public $gateway;
24
25
    public static function gatewayId(): string
26
    {
27
        return 'BK';
28
    }
29
30
    /**
31
     * @expectedException \yii\base\InvalidConfigException
32
     * @expectedExceptionMessage cannot be blank
33
     */
34 View Code Duplication
    public function testPurchase()
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...
35
    {
36
        // valid
37
        $responseData = $this->gateway->purchase([
38
            'order_id' => 2,
39
            'total_amount' => 500000,
40
            'url_success' => '/'
41
        ]);
42
43
        $this->assertTrue($responseData->getIsOk());
44
        $this->assertTrue(isset($responseData['redirect_url']));
45
46
        // throws
47
        $this->gateway->purchase([
48
            'order_id' => 1,
49
            'url_success' => '/'
50
        ]);
51
52
    }
53
54
    /**
55
     * @expectedException \yii\base\InvalidConfigException
56
     * @expectedExceptionMessage cannot be blank
57
     */
58
    public function testPurchasePro()
59
    {
60
        // Valid
61
        $responseData = $this->gateway->purchasePro([
62
            'bank_payment_method_id' => '128',
63
            'payer_name' => 'vxm',
64
            'payer_email' => '[email protected]',
65
            'payer_phone_no' => '0909113911',
66
            'order_id' => microtime(),
67
            'total_amount' => 500000,
68
            'url_success' => '/',
69
        ]);
70
        $this->assertTrue($responseData->next_action === 'redirect');
0 ignored issues
show
Bug introduced by
Accessing next_action on the interface vxm\gatewayclients\DataInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
71
72
        // Throws
73
        $this->gateway->purchasePro([
74
            'bank_payment_method_id' => '128',
75
            'payer_name' => 'vxm',
76
            'payer_email' => '[email protected]',
77
            'payer_phone_no' => '0909113911',
78
            'order_id' => time(),
79
            'url_success' => '/',
80
        ]);
81
82
    }
83
84
    /**
85
     * @expectedException \yii\base\InvalidConfigException
86
     * @expectedExceptionMessage cannot be blank
87
     */
88 View Code Duplication
    public function testQueryDR()
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...
89
    {
90
        // Valid
91
        $responseData = $this->gateway->queryDR(['transaction_id' => 1]);
92
        $this->assertTrue($responseData->getIsOk());
93
94
        // Throws
95
        $this->gateway->queryDR([]);
96
    }
97
98
    public function testGetMerchantData()
99
    {
100
        $merchantData = $this->gateway->getMerchantData();
101
        var_dump(array_keys($merchantData->get())); die;
0 ignored issues
show
Security Debugging Code introduced by
var_dump(array_keys($merchantData->get())); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
102
        $this->assertTrue($merchantData->getIsOk());
0 ignored issues
show
Unused Code introduced by
$this->assertTrue($merchantData->getIsOk()); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
103
    }
104
105 View Code Duplication
    public function testVerifyRequestIPN()
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...
106
    {
107
        $_POST = [
108
            'business' => '[email protected]',
109
            'order_id' => 2,
110
            'total_amount' => 500000,
111
            'checksum' => 'c96f01e3fdb4ba665304e70c04d58ba8917f31fe',
112
            'merchant_id' => 647,
113
            'url_success' => '/'
114
        ];
115
        $responseData = $this->gateway->verifyRequestIPN();
116
        $this->assertFalse($responseData);
117
    }
118
119 View Code Duplication
    public function testVerifyRequestPurchaseSuccess()
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...
120
    {
121
        $_GET = [
122
            'business' => '[email protected]',
123
            'order_id' => 2,
124
            'total_amount' => 500000,
125
            'checksum' => 'c96f01e3fdb4ba665304e70c04d58ba8917f31fe',
126
            'merchant_id' => 647,
127
            'url_success' => '/'
128
        ];
129
        $responseData = $this->gateway->verifyRequestPurchaseSuccess();
130
        $this->assertFalse($responseData);
131
    }
132
}
133