Completed
Push — master ( c88800...3459a9 )
by Vuong
01:54
created

NganLuongTest::testAuthenticate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
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 Yii Viet
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
9
namespace yiiviet\tests\unit\payment;
10
11
use Yii;
12
13
/**
14
 * Class NganLuongTest
15
 *
16
 * @author Vuong Minh <[email protected]>
17
 * @since 1.0
18
 */
19
class NganLuongTest extends TestCase
20
{
21
22
    const TOKEN = '58914-68d8693f31a5c6299813c4d26bb643c2';
23
24
    /**
25
     * @var \yiiviet\payment\nganluong\PaymentGateway
26
     */
27
    public $gateway;
28
29
30
    public static function gatewayId(): string
31
    {
32
        return 'NL';
33
    }
34
35
    /**
36
     * @expectedException \yii\base\InvalidConfigException
37
     * @expectedExceptionMessage cannot be blank
38
     */
39
    public function testPurchase()
40
    {
41
        // Valid
42
        $responseData = $this->gateway->purchase([
43
            'bank_code' => 'VCB',
44
            'buyer_fullname' => 'vxm',
45
            'buyer_email' => '[email protected]',
46
            'buyer_mobile' => '0909113911',
47
            'total_amount' => 10000000,
48
            'order_code' => microtime()
49
        ]);
50
51
        $this->assertTrue($responseData->getIsOk());
52
        $this->assertTrue(isset($responseData['checkout_url']));
53
54
        // Throws
55
        $this->gateway->purchase([]);
56
57
    }
58
59
    /**
60
     * @expectedException \yii\base\InvalidConfigException
61
     * @expectedExceptionMessage cannot be blank
62
     */
63
    public function testQueryDR()
64
    {
65
        // Valid
66
        $responseData = $this->gateway->queryDR([
67
            'token' => self::TOKEN
68
        ]);
69
70
        $this->assertEquals('81', $responseData->error_code);
0 ignored issues
show
Documentation introduced by
The property error_code does not exist on object<yiiviet\payment\nganluong\ResponseData>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
71
        $this->assertFalse($responseData->getIsOk());
72
73
        // Throws
74
        $this->gateway->queryDR([]);
75
    }
76
77
    /**
78
     * @expectedException \yii\base\InvalidConfigException
79
     * @expectedExceptionMessage cannot be blank
80
     */
81
    public function testAuthenticate()
82
    {
83
        // Valid
84
        $this->gateway->setVersion('3.2');
85
        $responseData = $this->gateway->authenticate([
86
            'token' => self::TOKEN,
87
            'otp' => '123321',
88
            'auth_url' => 'http://localhost'
89
        ]);
90
        $this->assertFalse($responseData->getIsOk());
91
92
        // Throws
93
        $this->gateway->authenticate([
94
            'token' => self::TOKEN,
95
            'otp' => '123321'
96
        ]);
97
    }
98
99
    public function testVerifyRequestPurchaseSuccess()
100
    {
101
        $_GET['token'] = self::TOKEN;
102
103
        $result = $this->gateway->verifyRequestPurchaseSuccess();
104
        $this->assertInstanceOf('\yiiviet\payment\VerifiedData', $result);
105
106
        $_GET = [];
107
        $result = $this->gateway->verifyRequestPurchaseSuccess();
108
        $this->assertFalse($result);
109
    }
110
111
    /**
112
     * @expectedException \yii\base\InvalidConfigException
113
     * @expectedExceptionMessage cannot be blank
114
     */
115
    public function testPurchase32()
116
    {
117
        // Valid
118
        $this->gateway->setVersion('3.2');
119
        $responseData = $this->gateway->purchase([
120
            'bank_code' => 'VCB',
121
            'buyer_fullname' => 'vxm',
122
            'buyer_email' => '[email protected]',
123
            'buyer_mobile' => '0909113911',
124
            'total_amount' => 10000000,
125
            'order_code' => microtime(),
126
            'card_number' => '123123123',
127
            'card_fullname' => 'vxm',
128
            'card_month' => '01',
129
            'card_year' => '2012'
130
        ]);
131
132
        $this->assertFalse($responseData->getIsOk());
133
134
        // Throws
135
        $this->gateway->purchase([
136
            'bank_code' => 'VCB',
137
            'buyer_fullname' => 'vxm',
138
            'buyer_email' => '[email protected]',
139
            'buyer_mobile' => '0909113911',
140
            'total_amount' => 10000000,
141
            'order_code' => microtime()
142
        ]);
143
    }
144
}
145