BankValidatorTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 34.29 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 24
loc 70
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A gatewayId() 0 4 1
A getBankProvider() 0 4 1
A testValidBankId() 12 12 1
A testInValidBankId() 12 12 1
A testException() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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