Passed
Push — master ( 0001c9...a30983 )
by Evgenii
05:07 queued 12s
created

PhoneValidatorTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 51
c 2
b 0
f 0
dl 0
loc 130
rs 10
wmc 10
1
<?php
2
3
namespace floor12\phone\tests;
4
5
use floor12\phone\PhoneValidator;
6
use PHPUnit\Framework\TestCase;
7
8
class PhoneValidatorTest extends TestCase
9
{
10
    /**
11
     * Wrong value type
12
     */
13
    public function testWrongType()
14
    {
15
        $validator = new PhoneValidator();
16
        $this->assertFalse($validator->validate([]));
17
    }
18
19
    /**
20
     * To short value
21
     */
22
    public function testTooShortPhone()
23
    {
24
        $model = new User();
25
        $model->phone = 123;
26
        $this->assertFalse($model->validate());
27
        $this->assertEquals("The phone number must be 11 to 15 digits long.", $model->errors['phone'][0]);
28
29
        $validator = new PhoneValidator();
30
        $this->assertFalse($validator->validate($model->phone));
31
    }
32
33
    /**
34
     * Too logn value
35
     */
36
    public function testTooLongPhone()
37
    {
38
        $model = new User();
39
        $model->phone = 121231312312313123;
40
        $this->assertFalse($model->validate());
41
        $this->assertEquals("The phone number must be 11 to 15 digits long.", $model->errors['phone'][0]);
42
43
        $validator = new PhoneValidator();
44
        $this->assertFalse($validator->validate($model->phone));
45
    }
46
47
    /**
48
     *  Value with letters
49
     */
50
    public function testPhoneWithLetters()
51
    {
52
        $model = new User();
53
        $model->phone = '7926849852dd';
54
        $this->assertFalse($model->validate());
55
        $this->assertEquals("The phone number must contain only numbers.", $model->errors['phone'][0]);
56
57
        $validator = new PhoneValidator();
58
        $this->assertFalse($validator->validate($model->phone));
59
    }
60
61
62
    /**
63
     * Valid number with 11 digits
64
     */
65
    public function testValidPhone()
66
    {
67
        $model = new User();
68
        $model->phone = '79268465236';
69
        $this->assertTrue($model->validate());
70
71
        $validator = new PhoneValidator();
72
        $this->assertTrue($validator->validate($model->phone));
73
    }
74
75
    /**
76
     * Valid number with 11 digits
77
     */
78
    public function testValidPhone2()
79
    {
80
        $model = new User();
81
        $model->phone = '+7 (926) 846-52-36';
82
        $this->assertTrue($model->validate());
83
84
        $validator = new PhoneValidator();
85
        $this->assertTrue($validator->validate($model->phone));
86
    }
87
88
    /**
89
     * Valid number with 11 digits
90
     */
91
    public function testValidPhone3()
92
    {
93
        $model = new User();
94
        $model->phone = '7 926 846-52-36';
95
        $this->assertTrue($model->validate());
96
97
        $validator = new PhoneValidator();
98
        $this->assertTrue($validator->validate($model->phone));
99
    }
100
101
    /**
102
     * Valid number with 12 digits
103
     */
104
    public function testValidPhon4e()
105
    {
106
        $model = new User();
107
        $model->phone = '349268465236';
108
        $this->assertTrue($model->validate());
109
110
        $validator = new PhoneValidator();
111
        $this->assertTrue($validator->validate($model->phone));
112
    }
113
114
    /**
115
     * Valid number with 12 digits
116
     */
117
    public function testValidPhone5()
118
    {
119
        $model = new User();
120
        $model->phone = '+12 (926) 846-52-36';
121
        $this->assertTrue($model->validate());
122
123
        $validator = new PhoneValidator();
124
        $this->assertTrue($validator->validate($model->phone));
125
    }
126
127
    /**
128
     * Valid number with 12 digits
129
     */
130
    public function testValidPhone6()
131
    {
132
        $model = new User();
133
        $model->phone = '12 926 846-52-36';
134
        $this->assertTrue($model->validate());
135
136
        $validator = new PhoneValidator();
137
        $this->assertTrue($validator->validate($model->phone));
138
    }
139
140
}