suricate-php /
framework
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | /** |
||||||
| 4 | * @SuppressWarnings("TooManyPublicMethods") |
||||||
| 5 | **/ |
||||||
| 6 | class ValidatorTest extends \PHPUnit\Framework\TestCase |
||||||
| 7 | { |
||||||
| 8 | public function testValidateTrue() |
||||||
| 9 | { |
||||||
| 10 | $test = true; |
||||||
| 11 | |||||||
| 12 | $validator = new \Suricate\Validator($test); |
||||||
| 13 | $validator->true("Not true"); |
||||||
| 14 | $this->assertSame(0, count($validator->getErrors())); |
||||||
| 15 | $this->assertTrue($validator->pass()); |
||||||
| 16 | $this->assertFalse($validator->fails()); |
||||||
| 17 | } |
||||||
| 18 | |||||||
| 19 | public function testValidateFalse() |
||||||
| 20 | { |
||||||
| 21 | $test = true; |
||||||
| 22 | |||||||
| 23 | $validator = new \Suricate\Validator($test); |
||||||
| 24 | $validator->false("Not false"); |
||||||
| 25 | $this->assertSame(1, count($validator->getErrors())); |
||||||
| 26 | $this->assertFalse($validator->pass()); |
||||||
| 27 | $this->assertTrue($validator->fails()); |
||||||
| 28 | $this->assertSame("Not false", $validator->getErrors()[0]); |
||||||
| 29 | } |
||||||
| 30 | |||||||
| 31 | public function testValidateEqualTo() |
||||||
| 32 | { |
||||||
| 33 | $test = true; |
||||||
| 34 | |||||||
| 35 | $validator = new \Suricate\Validator($test); |
||||||
| 36 | $validator->equalTo(true, "Not equal to 1"); |
||||||
| 37 | $this->assertTrue($validator->pass()); |
||||||
| 38 | } |
||||||
| 39 | |||||||
| 40 | public function testValidateIdenticalTo() |
||||||
| 41 | { |
||||||
| 42 | $test = true; |
||||||
| 43 | |||||||
| 44 | $validator = new \Suricate\Validator($test); |
||||||
| 45 | $validator->identicalTo("1", "Not identical to 1"); |
||||||
| 46 | $this->assertTrue($validator->fails()); |
||||||
| 47 | |||||||
| 48 | $validator = new \Suricate\Validator($test); |
||||||
| 49 | $validator->identicalTo(1, "Not identical to 1"); |
||||||
| 50 | $this->assertTrue($validator->fails()); |
||||||
| 51 | } |
||||||
| 52 | |||||||
| 53 | public function testValidateLessThan() |
||||||
| 54 | { |
||||||
| 55 | $test = 10; |
||||||
| 56 | |||||||
| 57 | $validator = new \Suricate\Validator($test); |
||||||
| 58 | $validator->lessThan(1, "Not less than 1"); |
||||||
| 59 | $this->assertTrue($validator->fails()); |
||||||
| 60 | } |
||||||
| 61 | |||||||
| 62 | public function testValidateLessThanOrEqual() |
||||||
| 63 | { |
||||||
| 64 | $test = 10; |
||||||
| 65 | |||||||
| 66 | $validator = new \Suricate\Validator($test); |
||||||
| 67 | $validator->lessThanOrEqual(10, "Not <= than 10"); |
||||||
| 68 | $this->assertTrue($validator->pass()); |
||||||
| 69 | } |
||||||
| 70 | |||||||
| 71 | public function testValidateGreaterThan() |
||||||
| 72 | { |
||||||
| 73 | $test = 10; |
||||||
| 74 | |||||||
| 75 | $validator = new \Suricate\Validator($test); |
||||||
| 76 | $validator->greaterThan(11, "Not greater than 11"); |
||||||
| 77 | $this->assertTrue($validator->fails()); |
||||||
| 78 | } |
||||||
| 79 | |||||||
| 80 | public function testValidateGreaterThanOrEqual() |
||||||
| 81 | { |
||||||
| 82 | $test = 10; |
||||||
| 83 | |||||||
| 84 | $validator = new \Suricate\Validator($test); |
||||||
| 85 | $validator->greaterThanOrEqual(10, "Not >= than 10"); |
||||||
| 86 | $this->assertTrue($validator->pass()); |
||||||
| 87 | } |
||||||
| 88 | |||||||
| 89 | public function testBlank() |
||||||
| 90 | { |
||||||
| 91 | $test = ''; |
||||||
| 92 | |||||||
| 93 | $validator = new \Suricate\Validator($test); |
||||||
| 94 | $validator->blank("Not blank"); |
||||||
| 95 | $this->assertTrue($validator->pass()); |
||||||
| 96 | } |
||||||
| 97 | |||||||
| 98 | public function testNull() |
||||||
| 99 | { |
||||||
| 100 | $test = null; |
||||||
| 101 | |||||||
| 102 | $validator = new \Suricate\Validator($test); |
||||||
| 103 | $validator->null("Not null"); |
||||||
| 104 | $this->assertTrue($validator->pass()); |
||||||
| 105 | |||||||
| 106 | $test = 0; |
||||||
| 107 | |||||||
| 108 | $validator = new \Suricate\Validator($test); |
||||||
| 109 | $validator->null("Not null"); |
||||||
| 110 | $this->assertFalse($validator->pass()); |
||||||
| 111 | } |
||||||
| 112 | |||||||
| 113 | public function testType() |
||||||
| 114 | { |
||||||
| 115 | $test = [1, 2, 3]; |
||||||
| 116 | $validator = new \Suricate\Validator($test); |
||||||
| 117 | $validator->type('array', "Not an array"); |
||||||
| 118 | $this->assertTrue($validator->pass()); |
||||||
| 119 | |||||||
| 120 | $test = true; |
||||||
| 121 | $validator = new \Suricate\Validator($test); |
||||||
| 122 | $validator->type('bool', "Not a bool"); |
||||||
| 123 | $this->assertTrue($validator->pass()); |
||||||
| 124 | |||||||
| 125 | $test = 1; |
||||||
| 126 | $validator = new \Suricate\Validator($test); |
||||||
| 127 | $validator->type('bool', "Not a bool"); |
||||||
| 128 | $this->assertTrue($validator->fails()); |
||||||
| 129 | |||||||
| 130 | $test = 1.0; |
||||||
| 131 | $validator = new \Suricate\Validator($test); |
||||||
| 132 | $validator->type('int', "Not an int"); |
||||||
| 133 | $this->assertTrue($validator->fails()); |
||||||
| 134 | |||||||
| 135 | $test = 1; |
||||||
| 136 | $validator = new \Suricate\Validator($test); |
||||||
| 137 | $validator->type('float', "Not a float"); |
||||||
| 138 | $this->assertTrue($validator->fails()); |
||||||
| 139 | |||||||
| 140 | $test = 1; |
||||||
| 141 | $validator = new \Suricate\Validator($test); |
||||||
| 142 | $validator->type('numeric', "Not a numeric"); |
||||||
| 143 | $this->assertTrue($validator->pass()); |
||||||
| 144 | |||||||
| 145 | $test = 1.2; |
||||||
| 146 | $validator = new \Suricate\Validator($test); |
||||||
| 147 | $validator->type('numeric', "Not a numeric"); |
||||||
| 148 | $this->assertTrue($validator->pass()); |
||||||
| 149 | |||||||
| 150 | $test = new stdClass(); |
||||||
| 151 | $validator = new \Suricate\Validator($test); |
||||||
| 152 | $validator->type('object', "Not an object "); |
||||||
| 153 | $this->assertTrue($validator->pass()); |
||||||
| 154 | |||||||
| 155 | $test = "tt"; |
||||||
| 156 | $validator = new \Suricate\Validator($test); |
||||||
| 157 | $validator->type('string', "Not a string "); |
||||||
| 158 | $this->assertTrue($validator->pass()); |
||||||
| 159 | } |
||||||
| 160 | |||||||
| 161 | public function testEmail() |
||||||
| 162 | { |
||||||
| 163 | $test = '[email protected]'; |
||||||
| 164 | $validator = new \Suricate\Validator($test); |
||||||
| 165 | $validator->email("Not an email"); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 166 | $this->assertTrue($validator->pass()); |
||||||
| 167 | |||||||
| 168 | $test = 'mathieu@lesniak'; |
||||||
| 169 | $validator = new \Suricate\Validator($test); |
||||||
| 170 | $validator->email("Not an email"); |
||||||
| 171 | $this->assertFalse($validator->pass()); |
||||||
| 172 | |||||||
| 173 | $test = '[email protected]'; |
||||||
| 174 | $validator = new \Suricate\Validator($test); |
||||||
| 175 | $validator->email("Not an email"); |
||||||
| 176 | $this->assertTrue($validator->pass()); |
||||||
| 177 | } |
||||||
| 178 | |||||||
| 179 | public function testUrl() |
||||||
| 180 | { |
||||||
| 181 | $test = 'https://www.google.com/search?index=1'; |
||||||
| 182 | $validator = new \Suricate\Validator($test); |
||||||
| 183 | $validator->url("Not an URL"); |
||||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||||
| 184 | $this->assertTrue($validator->pass()); |
||||||
| 185 | |||||||
| 186 | $test = 'www.google.com/search?index=1'; |
||||||
| 187 | $validator = new \Suricate\Validator($test); |
||||||
| 188 | $validator->url("Not an URL"); |
||||||
| 189 | $this->assertTrue($validator->fails()); |
||||||
| 190 | |||||||
| 191 | $test = 'gopher://www.google.com/search?index=1'; |
||||||
| 192 | $validator = new \Suricate\Validator($test); |
||||||
| 193 | $validator->url("Not an URL"); |
||||||
| 194 | $this->assertTrue($validator->pass()); |
||||||
| 195 | } |
||||||
| 196 | |||||||
| 197 | public function testIP() |
||||||
| 198 | { |
||||||
| 199 | $test = '8.8.8.8'; |
||||||
| 200 | $validator = new \Suricate\Validator($test); |
||||||
| 201 | $validator->ip("Not an IP"); |
||||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||||
| 202 | $this->assertTrue($validator->pass()); |
||||||
| 203 | |||||||
| 204 | $test = '2001:0db8:0000:85a3:0000:0000:ac1f:8001'; |
||||||
| 205 | $validator = new \Suricate\Validator($test); |
||||||
| 206 | $validator->ip("Not an IP"); |
||||||
| 207 | $this->assertTrue($validator->pass()); |
||||||
| 208 | } |
||||||
| 209 | |||||||
| 210 | public function testAlnum() |
||||||
| 211 | { |
||||||
| 212 | $test = '!aa'; |
||||||
| 213 | $validator = new \Suricate\Validator($test); |
||||||
| 214 | $validator->alnum('Not alphanumeric'); |
||||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||||
| 215 | $this->assertTrue($validator->fails()); |
||||||
| 216 | |||||||
| 217 | $test = 'aa123z'; |
||||||
| 218 | $validator = new \Suricate\Validator($test); |
||||||
| 219 | $validator->alnum('Not alphanumeric'); |
||||||
| 220 | $this->assertTrue($validator->pass()); |
||||||
| 221 | } |
||||||
| 222 | } |
||||||
| 223 |