Completed
Push — develop ( 131cab...e5d75d )
by Mathieu
01:55
created

ValidatorTest::testValidateTrue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
class ValidatorTest extends \PHPUnit\Framework\TestCase
3
{
4
    public function testValidateTrue()
5
    {
6
        $test = true;
7
8
        $validator = new \Suricate\Validator($test);
9
        $validator->true("Not true");
10
        $this->assertSame(0, count($validator->getErrors()));
11
        $this->assertTrue($validator->pass());
12
        $this->assertFalse($validator->fails());
13
14
    }
15
16
    public function testValidateFalse()
17
    {
18
        $test = true;
19
20
        $validator = new \Suricate\Validator($test);
21
        $validator->false("Not false");
22
        $this->assertSame(1, count($validator->getErrors()));
23
        $this->assertFalse($validator->pass());
24
        $this->assertTrue($validator->fails());
25
        $this->assertSame("Not false", $validator->getErrors()[0]);
26
    }
27
28
    public function testValidateEqualTo()
29
    {
30
        $test = true;
31
32
        $validator = new \Suricate\Validator($test);
33
        $validator->equalTo(true, "Not equal to 1");
34
        $this->assertTrue($validator->pass());
35
    }
36
37
    public function testValidateIdenticalTo()
38
    {
39
        $test = true;
40
41
        $validator = new \Suricate\Validator($test);
42
        $validator->identicalTo("1", "Not identical to 1");
43
        $this->assertTrue($validator->fails());
44
45
        $validator = new \Suricate\Validator($test);
46
        $validator->identicalTo(1, "Not identical to 1");
47
        $this->assertTrue($validator->fails());
48
    }
49
50
    public function testValidateLessThan()
51
    {
52
        $test = 10;
53
54
        $validator = new \Suricate\Validator($test);
55
        $validator->lessThan(1, "Not less than 1");
56
        $this->assertTrue($validator->fails());
57
    }
58
59
    public function testValidateLessThanOrEqual()
60
    {
61
        $test = 10;
62
63
        $validator = new \Suricate\Validator($test);
64
        $validator->lessThanOrEqual(10, "Not <= than 10");
65
        $this->assertTrue($validator->pass());
66
    }
67
68
    public function testValidateGreaterThan()
69
    {
70
        $test = 10;
71
72
        $validator = new \Suricate\Validator($test);
73
        $validator->greaterThan(11, "Not greater than 11");
74
        $this->assertTrue($validator->fails());
75
    }
76
77
    public function testValidateGreaterThanOrEqual()
78
    {
79
        $test = 10;
80
81
        $validator = new \Suricate\Validator($test);
82
        $validator->greaterThanOrEqual(10, "Not >= than 10");
83
        $this->assertTrue($validator->pass());
84
    }
85
86
    public function testBlank()
87
    {
88
        $test = '';
89
90
        $validator = new \Suricate\Validator($test);
91
        $validator->blank("Not blank");
92
        $this->assertTrue($validator->pass());
93
    }
94
95
    public function testNull()
96
    {
97
        $test = null;
98
99
        $validator = new \Suricate\Validator($test);
100
        $validator->null("Not null");
101
        $this->assertTrue($validator->pass());
102
103
        $test = 0;
104
105
        $validator = new \Suricate\Validator($test);
106
        $validator->null("Not null");
107
        $this->assertFalse($validator->pass());
108
    }
109
110
    public function testType()
111
    {
112
        $test = [1, 2, 3];
113
        $validator = new \Suricate\Validator($test);
114
        $validator->type('array', "Not an array");
115
        $this->assertTrue($validator->pass());
116
117
        $test = true;
118
        $validator = new \Suricate\Validator($test);
119
        $validator->type('bool', "Not a bool");
120
        $this->assertTrue($validator->pass());
121
122
        $test = 1;
123
        $validator = new \Suricate\Validator($test);
124
        $validator->type('bool', "Not a bool");
125
        $this->assertTrue($validator->fails());
126
127
        $test = 1.0;
128
        $validator = new \Suricate\Validator($test);
129
        $validator->type('int', "Not an int");
130
        $this->assertTrue($validator->fails());
131
132
        $test = 1;
133
        $validator = new \Suricate\Validator($test);
134
        $validator->type('float', "Not a float");
135
        $this->assertTrue($validator->fails());
136
137
        $test = 1;
138
        $validator = new \Suricate\Validator($test);
139
        $validator->type('numeric', "Not a numeric");
140
        $this->assertTrue($validator->pass());
141
142
        $test = 1.2;
143
        $validator = new \Suricate\Validator($test);
144
        $validator->type('numeric', "Not a numeric");
145
        $this->assertTrue($validator->pass());
146
147
        $test = new stdClass();
148
        $validator = new \Suricate\Validator($test);
149
        $validator->type('object', "Not an object ");
150
        $this->assertTrue($validator->pass());
151
152
        $test = "tt";
153
        $validator = new \Suricate\Validator($test);
154
        $validator->type('string', "Not a string ");
155
        $this->assertTrue($validator->pass());
156
    }
157
158
    public function testEmail()
159
    {
160
        $test = '[email protected]';
161
        $validator = new \Suricate\Validator($test);
162
        $validator->email("Not an email");
0 ignored issues
show
Bug introduced by
The method email() does not exist on Suricate\Validator. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

162
        $validator->/** @scrutinizer ignore-call */ 
163
                    email("Not an email");
Loading history...
163
        $this->assertTrue($validator->pass());
164
165
        $test = 'mathieu@lesniak';
166
        $validator = new \Suricate\Validator($test);
167
        $validator->email("Not an email");
168
        $this->assertFalse($validator->pass());
169
170
        $test = '[email protected]';
171
        $validator = new \Suricate\Validator($test);
172
        $validator->email("Not an email");
173
        $this->assertTrue($validator->pass());
174
    }
175
176
    public function testUrl()
177
    {
178
        $test = 'https://www.google.com/search?index=1';
179
        $validator = new \Suricate\Validator($test);
180
        $validator->url("Not an URL");
0 ignored issues
show
Bug introduced by
The method url() does not exist on Suricate\Validator. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

180
        $validator->/** @scrutinizer ignore-call */ 
181
                    url("Not an URL");
Loading history...
181
        $this->assertTrue($validator->pass());
182
183
        $test = 'www.google.com/search?index=1';
184
        $validator = new \Suricate\Validator($test);
185
        $validator->url("Not an URL");
186
        $this->assertTrue($validator->fails());
187
188
        $test = 'gopher://www.google.com/search?index=1';
189
        $validator = new \Suricate\Validator($test);
190
        $validator->url("Not an URL");
191
        $this->assertTrue($validator->pass());
192
    }
193
194
    public function testIP()
195
    {
196
        $test = '8.8.8.8';
197
        $validator = new \Suricate\Validator($test);
198
        $validator->ip("Not an IP");
0 ignored issues
show
Bug introduced by
The method ip() does not exist on Suricate\Validator. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

198
        $validator->/** @scrutinizer ignore-call */ 
199
                    ip("Not an IP");
Loading history...
199
        $this->assertTrue($validator->pass());
200
201
        $test = '2001:0db8:0000:85a3:0000:0000:ac1f:8001';
202
        $validator = new \Suricate\Validator($test);
203
        $validator->ip("Not an IP");
204
        $this->assertTrue($validator->pass());
205
    }
206
207
    public function testAlnum()
208
    {
209
        $test = '!aa';
210
        $validator = new \Suricate\Validator($test);
211
        $validator->alnum('Not alphanumeric');
0 ignored issues
show
Bug introduced by
The method alnum() does not exist on Suricate\Validator. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

211
        $validator->/** @scrutinizer ignore-call */ 
212
                    alnum('Not alphanumeric');
Loading history...
212
        $this->assertTrue($validator->fails());
213
214
        $test = 'aa123z';
215
        $validator = new \Suricate\Validator($test);
216
        $validator->alnum('Not alphanumeric');
217
        $this->assertTrue($validator->pass());
218
    }
219
}