Completed
Push — master ( 4f7c7c...fdaf8f )
by Vuong
02:10
created

MoMoTest::testVerifyRequestIPN()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @link https://github.com/yiiviet/yii2-payment
4
 * @copyright Copyright (c) 2017 Yii Viet
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace yiiviet\tests\unit\payment;
9
10
/**
11
 * Lớp MoMoTest
12
 *
13
 * @author Vuong Minh <[email protected]>
14
 * @since 1.0.3
15
 */
16
class MoMoTest extends TestCase
17
{
18
19
    /**
20
     * @var \yiiviet\payment\momo\PaymentGateway
21
     */
22
    public $gateway;
23
24
    public static function gatewayId(): string
25
    {
26
        return 'MM';
27
    }
28
29
    public function testPurchase()
30
    {
31
        $orderId = microtime();
32
        $requestId = microtime();
33
        $responseData = $this->purchase([
34
            'amount' => 500000,
35
            'returnUrl' => 'http://localhost',
36
            'notifyUrl' => 'http://localhost',
37
            'orderId' => $orderId,
38
            'requestId' => $requestId
39
        ]);
40
41
        $this->assertTrue($responseData->getIsOk());
42
        $this->assertTrue($responseData->payUrl !== '');
43
44
        return [$orderId, $requestId];
45
    }
46
47
    /**
48
     * @expectedException \yii\base\InvalidConfigException
49
     * @expectedExceptionMessage cannot be blank
50
     * @depends testPurchase
51
     */
52
    public function testInvalidPurchase()
53
    {
54
        $this->purchase([]);
55
    }
56
57
    /**
58
     * @depends testPurchase
59
     */
60
    public function testQueryDR()
61
    {
62
        list($orderId, $requestId) = $this->testPurchase();
63
        $responseData = $this->queryDR([
64
            'orderId' => $orderId,
65
            'requestId' => $requestId
66
        ]);
67
68
        $this->assertTrue($responseData->getIsOk());
69
    }
70
71
    /**
72
     * @expectedException \yii\base\InvalidConfigException
73
     * @expectedExceptionMessage cannot be blank
74
     * @depends testQueryDR
75
     */
76
    public function testInvalidQueryDR()
77
    {
78
        $this->queryDR([]);
79
    }
80
81
    /**
82
     * @depends testPurchase
83
     * @depends testQueryDR
84
     */
85 View Code Duplication
    public function testRefund()
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...
86
    {
87
        list($orderId, $requestId) = $this->testPurchase();
88
        $responseData = $this->refund([
89
            'orderId' => $orderId,
90
            'transId' => $orderId,
91
            'amount' => 10000,
92
            'requestId' => $requestId
93
        ]);
94
95
        $this->assertFalse($responseData->getIsOk());
96
    }
97
98
    /**
99
     * @expectedException \yii\base\InvalidConfigException
100
     * @expectedExceptionMessage cannot be blank
101
     * @depends testRefund
102
     */
103
    public function testInvalidRefund()
104
    {
105
        $this->refund([]);
106
    }
107
108
    /**
109
     * @depends testRefund
110
     */
111 View Code Duplication
    public function testQueryRefund()
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...
112
    {
113
        list($orderId, $requestId) = $this->testPurchase();
114
        $responseData = $this->queryRefund([
115
            'orderId' => $orderId,
116
            'transId' => $orderId,
117
            'amount' => 10000,
118
            'requestId' => $requestId
119
        ]);
120
121
        $this->assertFalse($responseData->getIsOk());
122
    }
123
124
125
    /**
126
     * @expectedException \yii\base\InvalidConfigException
127
     * @expectedExceptionMessage cannot be blank
128
     * @depends testQueryRefund
129
     */
130
    public function testInvalidQueryRefund()
131
    {
132
        $this->queryRefund([]);
133
    }
134
135
    /**
136
     * @depends testPurchase
137
     * @depends testQueryDR
138
     */
139
    public function testVerifyRequestPurchaseSuccess()
140
    {
141
        $result = $this->verifyRequestPurchaseSuccess();
142
        $this->assertFalse($result);
143
    }
144
145
    /**
146
     * @depends testPurchase
147
     * @depends testQueryDR
148
     */
149
    public function testVerifyRequestIPN()
150
    {
151
        $result = $this->verifyRequestIPN();
152
153
        $this->assertFalse($result);
154
    }
155
}
156