-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from DenislavParvanov/master
add integer rule
- Loading branch information
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Rakit\Validation\Rules; | ||
|
||
use Rakit\Validation\Rule; | ||
|
||
class Integer extends Rule | ||
{ | ||
|
||
protected $message = "The :attribute must be integer"; | ||
|
||
public function check($value) | ||
{ | ||
return filter_var($value, FILTER_VALIDATE_INT) !== false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use Rakit\Validation\Rules\Integer; | ||
|
||
class IntegerTest extends PHPUnit_Framework_TestCase | ||
{ | ||
|
||
public function setUp() | ||
{ | ||
$this->rule = new Integer; | ||
} | ||
|
||
public function testValids() | ||
{ | ||
$this->assertTrue($this->rule->check(0)); | ||
$this->assertTrue($this->rule->check('0')); | ||
$this->assertTrue($this->rule->check('123')); | ||
$this->assertTrue($this->rule->check('-123')); | ||
$this->assertTrue($this->rule->check(123)); | ||
$this->assertTrue($this->rule->check(-123)); | ||
|
||
} | ||
|
||
public function testInvalids() | ||
{ | ||
$this->assertFalse($this->rule->check('foo123')); | ||
$this->assertFalse($this->rule->check('123foo')); | ||
$this->assertFalse($this->rule->check([123])); | ||
$this->assertFalse($this->rule->check('123.456')); | ||
$this->assertFalse($this->rule->check('-123.456')); | ||
} | ||
|
||
} |