VnPaymentTest::testRefund()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
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 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 VnPaymentTest
12
 *
13
 * @author Vuong Minh <[email protected]>
14
 * @since 1.0
15
 */
16
class VnPaymentTest extends TestCase
17
{
18
19
    /**
20
     * @var \yiiviet\payment\vnpayment\PaymentGateway
21
     */
22
    public $gateway;
23
24
    public static function gatewayId(): string
25
    {
26
        return 'VNP';
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->purchase([
37
            'TxnRef' => time(),
38
            'OrderType' => 100000,
39
            'OrderInfo' => time(),
40
            'IpAddr' => '127.0.0.1',
41
            'Amount' => 1000000,
42
            'ReturnUrl' => 'http://localhost'
43
        ]);
44
45
        $this->assertTrue($responseData->getIsOk());
46
        $this->assertTrue(isset($responseData['redirect_url']));
47
48
        // Throws
49
        $this->purchase([
50
            'OrderType' => 100000,
51
            'IpAddr' => '127.0.0.1',
52
            'ReturnUrl' => 'http://localhost'
53
        ]);
54
    }
55
56
    /**
57
     * @expectedException \yii\base\InvalidConfigException
58
     * @expectedExceptionMessage cannot be blank
59
     */
60
    public function testQueryDR()
61
    {
62
        // Valid
63
        $responseData = $this->queryDR([
64
            'TxnRef' => 123,
65
            'IpAddr' => '127.0.0.1',
66
            'OrderInfo' => time(),
67
            'TransDate' => date('Ymdhis'),
68
            'TransactionNo' => 123,
69
        ]);
70
71
        $this->assertFalse($responseData->getIsOk());
72
73
        // Throws
74
        $this->queryDR([
75
            'IpAddr' => '127.0.0.1',
76
            'OrderInfo' => time(),
77
            'TransDate' => date('Ymdhis'),
78
            'TransactionNo' => 123,
79
        ]);
80
    }
81
82
    /**
83
     * @expectedException \yii\base\InvalidConfigException
84
     * @expectedExceptionMessage cannot be blank
85
     */
86
    public function testRefund()
87
    {
88
        // Valid
89
        $responseData = $this->refund([
90
            'TxnRef' => 123,
91
            'Amount' => 100000,
92
            'IpAddr' => '127.0.0.1',
93
            'OrderInfo' => time(),
94
            'TransDate' => date('Ymdhis'),
95
            'TransactionNo' => 123,
96
        ]);
97
98
        $this->assertFalse($responseData->getIsOk());
99
        $this->assertEquals(99, $responseData->getResponseCode());
100
101
        // Throws
102
        $this->refund([
103
            'IpAddr' => '127.0.0.1',
104
            'OrderInfo' => time(),
105
            'TransDate' => date('Ymdhis'),
106
            'TransactionNo' => 123,
107
        ]);
108
    }
109
}
110