DomainValidatorTest::testInvalidDomain()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * @link https://github.com/yiiviet/yii2-validator
4
 * @copyright Copyright (c) 2018 Yii Viet
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace yiiviet\tests\unit\validator;
9
10
use yii\base\DynamicModel;
11
12
/**
13
 * Lớp DomainValidatorTest
14
 *
15
 * @author Vuong Minh <[email protected]>
16
 * @since 1.0
17
 */
18 View Code Duplication
class DomainValidatorTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
19
{
20
21
    /**
22
     * @dataProvider validDomainProvider
23
     */
24
    public function testValidDomain($domain)
25
    {
26
        $model = DynamicModel::validateData([
27
            'domain' => $domain
28
        ], [
29
            ['domain', 'domainvn']
30
        ]);
31
32
        $this->assertFalse($model->hasErrors());
33
    }
34
35
    /**
36
     * @dataProvider invalidDomainProvider
37
     */
38
    public function testInvalidDomain($domain)
39
    {
40
        $model = DynamicModel::validateData([
41
            'domain' => $domain
42
        ], [
43
            ['domain', 'domainvn']
44
        ]);
45
46
        $this->assertTrue($model->hasErrors());
47
    }
48
49
    public function validDomainProvider()
50
    {
51
        return [
52
            ['yiiframework.vn'],
53
            ['chinhphu.vn'],
54
            ['edu.vn'],
55
            ['fpt.edu.vn'],
56
            ['zing.vn'],
57
            ['mp3.zing.vn'],
58
            ['gov.vn'],
59
            ['google.com.vn'],
60
            ['vnexpress.vn'],
61
            ['momo.vn']
62
        ];
63
    }
64
65
66
    public function invalidDomainProvider()
67
    {
68
        return [
69
            ['yiiframework.com'],
70
            ['github.com'],
71
            ['google.com'],
72
            ['stackoverflow.com'],
73
            ['blog.jetbrains.com']
74
        ];
75
    }
76
77
78
}
79