BankValidatorTest::testInValidBankId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
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
use Yii;
11
12
use yii\base\DynamicModel;
13
use yiiviet\payment\baokim\BankProvider;
14
15
/**
16
 * Lớp BankValidatorTest
17
 *
18
 * @author Vuong Minh <[email protected]>
19
 * @since 1.0.3
20
 */
21
class BankValidatorTest extends TestCase
22
{
23
    /**
24
     * @var \yiiviet\payment\baokim\PaymentGateway
25
     */
26
    public $gateway;
27
28
    public static function gatewayId(): string
29
    {
30
        return 'BK';
31
    }
32
33
    /**
34
     * @return object|BankProvider
35
     * @throws \yii\base\InvalidConfigException
36
     */
37
    protected function getBankProvider()
38
    {
39
        return Yii::createObject(BankProvider::class, [$this->gateway]);
40
    }
41
42
    /**
43
     * @throws \ReflectionException
44
     * @throws \yii\base\InvalidConfigException
45
     */
46 View Code Duplication
    public function testValidBankId()
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...
47
    {
48
        $banks = $this->getBankProvider()->banks();
49
        $this->assertTrue($banks[91] === "Vietinbank - Ngân hàng Công thương Việt Nam");
50
        $model = new DynamicModel([
51
            'bankId' => 91
52
        ]);
53
        $model->addRule('bankId', 'bankvn', [
54
            'gateway' => $this->gateway
55
        ]);
56
        $this->assertTrue($model->validate());
57
    }
58
59
    /**
60
     * @throws \ReflectionException
61
     * @throws \yii\base\InvalidConfigException
62
     * @depends testValidBankId
63
     */
64 View Code Duplication
    public function testInValidBankId()
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...
65
    {
66
        $banks = $this->getBankProvider()->banks();
67
        $this->assertFalse(isset($banks[10000]));
68
        $model = new DynamicModel([
69
            'bankId' => 10000
70
        ]);
71
        $model->addRule('bankId', 'bankvn', [
72
            'gateway' => $this->gateway
73
        ]);
74
        $this->assertFalse($model->validate());
75
    }
76
77
    /**
78
     * @throws \ReflectionException
79
     * @throws \yii\base\InvalidConfigException
80
     * @expectedException \yii\base\InvalidConfigException
81
     */
82
    public function testException()
83
    {
84
        $model = new DynamicModel([
85
            'bankId' => 91
86
        ]);
87
        $model->addRule('bankId', 'bankvn');
88
        $this->assertTrue($model->validate());
89
    }
90
}
91