Skip to content

Commit

Permalink
fix(src/rules/minlength.php): a numeric string, e.g. '10', should be …
Browse files Browse the repository at this point in the history
…accepted as rule value
  • Loading branch information
SandroMiguel committed Oct 21, 2024
1 parent 9210dc3 commit f931c61
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Rules/MinLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function validate(): bool
'Rule "min_length": the rule value is mandatory'
);
}
if (!is_int($this->ruleValues[0])) {
if (!\is_numeric($this->ruleValues[0])) {
throw ValidatorException::noIntegerValue($this->ruleValues[0]);
}

Expand Down
12 changes: 5 additions & 7 deletions tests/MinLengthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,12 @@ public function testValidateNull(): void
}

/**
* An Empty String ('') value should pass validation (ignored field).
*
* @return void
* A numeric string, e.g. '10', should be accepted as rule value.
*/
// public function testValidateEmptyString(): void
// {
// $this->assertTrue($this->validate('', [5]));
// }
public function testValidateNumericString(): void
{
$this->assertFalse($this->validate('text with 23 characters', ['30']));
}

/**
* The String ('text with 23 characters') value should violate the rule with min length of 30 characters.
Expand Down

0 comments on commit f931c61

Please sign in to comment.