Completed
Push — master ( eccc2c...9c0ef3 )
by Vuong
01:43
created

OnePayTest::testPurchaseInternational()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
dl 24
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 16
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
/**
11
 * Class OnePayTest
12
 *
13
 * @author Vuong Minh <[email protected]>
14
 * @since 1.0
15
 */
16
class OnePayTest extends TestCase
17
{
18
19
    /**
20
     * @var \yiiviet\payment\onepay\PaymentGateway
21
     */
22
    public $gateway;
23
24
    public static function gatewayId(): string
25
    {
26
        return 'OP';
27
    }
28
29
    /**
30
     * @expectedException \yii\base\InvalidConfigException
31
     * @expectedExceptionMessage cannot be blank
32
     */
33 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...
34
    {
35
        // Valid
36
        $responseData = $this->gateway->purchase([
37
            'ReturnURL' => 'http://localhost/',
38
            'OrderInfo' => time(),
39
            'Amount' => 500000,
40
            'TicketNo' => '127.0.0.1',
41
            'AgainLink' => 'http://localhost/',
42
            'Title' => 'Hello World',
43
            'MerchTxnRef' => time()
44
        ]);
45
46
        $this->assertTrue($responseData->getIsOk());
47
        $this->assertTrue(isset($responseData['location']));
48
49
        // Throws
50
        $this->gateway->purchase([
51
            'ReturnURL' => 'http://localhost/',
52
            'TicketNo' => '127.0.0.1',
53
            'AgainLink' => 'http://localhost/'
54
        ]);
55
    }
56
57
    /**
58
     * @expectedException \yii\base\InvalidConfigException
59
     * @expectedExceptionMessage cannot be blank
60
     */
61 View Code Duplication
    public function testPurchaseInternational()
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...
62
    {
63
        // Valid
64
        $this->gateway->international = true;
65
        $responseData = $this->gateway->purchase([
66
            'ReturnURL' => 'http://localhost/',
67
            'OrderInfo' => time(),
68
            'Amount' => 500000,
69
            'TicketNo' => '127.0.0.1',
70
            'AgainLink' => 'http://localhost/',
71
            'Title' => 'Hello World',
72
            'MerchTxnRef' => time()
73
        ]);
74
75
        $this->assertTrue($responseData->getIsOk());
76
        $this->assertTrue(isset($responseData['location']));
77
78
        // Throws
79
        $this->gateway->purchase([
80
            'ReturnURL' => 'http://localhost/',
81
            'TicketNo' => '127.0.0.1',
82
            'AgainLink' => 'http://localhost/'
83
        ]);
84
    }
85
86
    /**
87
     * @expectedException \yii\base\InvalidConfigException
88
     * @expectedExceptionMessage cannot be blank
89
     */
90 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...
91
    {
92
        // Valid
93
        $responseData = $this->gateway->queryDR([
94
            'MerchTxnRef' => 1
95
        ]);
96
97
        $this->assertTrue($responseData->getIsOk());
98
99
        // Throws
100
        $this->gateway->queryDR([]);
101
    }
102
103
    /**
104
     * @expectedException \yii\base\InvalidConfigException
105
     * @expectedExceptionMessage cannot be blank
106
     */
107 View Code Duplication
    public function testQueryDRInternational()
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...
108
    {
109
        // Valid
110
        $this->gateway->international = true;
111
        $responseData = $this->gateway->queryDR([
112
            'MerchTxnRef' => 1
113
        ]);
114
115
        $this->assertTrue($responseData->getIsOk());
116
117
        // Throws
118
        $this->gateway->queryDR([]);
119
    }
120
121
    public function testVerifyRequestPurchaseSuccess()
122
    {
123
        $result = $this->gateway->verifyRequestPurchaseSuccess();
124
125
        $this->assertFalse($result);
126
    }
127
128
    public function testVerifyRequestPurchaseInternationalSuccess()
129
    {
130
        $this->gateway->international = true;
131
        $result = $this->gateway->verifyRequestPurchaseSuccess();
132
133
        $this->assertFalse($result);
134
    }
135
136
    public function testVerifyRequestIPN()
137
    {
138
        $result = $this->gateway->verifyRequestIPN();
139
140
        $this->assertFalse($result);
141
    }
142
143
    public function testVerifyRequestIPNInternational()
144
    {
145
        $this->gateway->international = true;
146
        $result = $this->gateway->verifyRequestIPN();
147
148
        $this->assertFalse($result);
149
    }
150
}
151