Skip to content

Commit

Permalink
Permitindo valores nnumericos com onull.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcisio-softbox committed Jun 16, 2017
1 parent 5a3e7be commit 968fdad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ValidationRules/NumericValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public function getIdentifier() {
* @return array
*/
public function validate($value) {
if (($value === null && !$this->allowNull) || !is_numeric($value)) {
return array("Campo não é numérico.");
if (($this->allowNull && $value === null) || is_numeric($value)) {
return array();
}

return array();
return array("Campo não é numérico.");
}

/**
Expand Down
14 changes: 14 additions & 0 deletions test/ValidationRules/NumericValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,18 @@ public function testInvalidValues() {
$this->assertNotEmpty($validation->validate(array()));
$this->assertNotEmpty($validation->validate(AttributeNotExists::instance()));
}

public function testNullableParam() {
$validation = new NumericValidation();
$validation->setParams(["nullable"]);

$this->assertEmpty($validation->validate(null));
$this->assertEmpty($validation->validate(1));
$this->assertEmpty($validation->validate(0));

$validation->setParams([]);
$this->assertNotEmpty($validation->validate(null));
$this->assertEmpty($validation->validate(1));
$this->assertEmpty($validation->validate(0));
}
}

0 comments on commit 968fdad

Please sign in to comment.