File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Rakit \Validation \Rules ;
4
+
5
+ use Rakit \Validation \Rule ;
6
+
7
+ class Integer extends Rule
8
+ {
9
+
10
+ protected $ message = "The :attribute must be integer " ;
11
+
12
+ public function check ($ value )
13
+ {
14
+ return filter_var ($ value , FILTER_VALIDATE_INT ) !== false ;
15
+ }
16
+
17
+ }
Original file line number Diff line number Diff line change @@ -90,6 +90,7 @@ protected function registerBaseValidators()
90
90
'max ' => new Rules \Max ,
91
91
'between ' => new Rules \Between ,
92
92
'url ' => new Rules \Url ,
93
+ 'integer ' => new Rules \Integer ,
93
94
'ip ' => new Rules \Ip ,
94
95
'ipv4 ' => new Rules \Ipv4 ,
95
96
'ipv6 ' => new Rules \Ipv6 ,
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Rakit \Validation \Rules \Integer ;
4
+
5
+ class IntegerTest extends PHPUnit_Framework_TestCase
6
+ {
7
+
8
+ public function setUp ()
9
+ {
10
+ $ this ->rule = new Integer ;
11
+ }
12
+
13
+ public function testValids ()
14
+ {
15
+ $ this ->assertTrue ($ this ->rule ->check (0 ));
16
+ $ this ->assertTrue ($ this ->rule ->check ('0 ' ));
17
+ $ this ->assertTrue ($ this ->rule ->check ('123 ' ));
18
+ $ this ->assertTrue ($ this ->rule ->check ('-123 ' ));
19
+ $ this ->assertTrue ($ this ->rule ->check (123 ));
20
+ $ this ->assertTrue ($ this ->rule ->check (-123 ));
21
+
22
+ }
23
+
24
+ public function testInvalids ()
25
+ {
26
+ $ this ->assertFalse ($ this ->rule ->check ('foo123 ' ));
27
+ $ this ->assertFalse ($ this ->rule ->check ('123foo ' ));
28
+ $ this ->assertFalse ($ this ->rule ->check ([123 ]));
29
+ $ this ->assertFalse ($ this ->rule ->check ('123.456 ' ));
30
+ $ this ->assertFalse ($ this ->rule ->check ('-123.456 ' ));
31
+ }
32
+
33
+ }
You can’t perform that action at this time.
0 commit comments