From f931c618c98354e75199d10bf0ff3455f6529313 Mon Sep 17 00:00:00 2001 From: SandroMiguel Date: Mon, 21 Oct 2024 18:06:08 +0100 Subject: [PATCH] fix(src/rules/minlength.php): a numeric string, e.g. '10', should be accepted as rule value --- src/Rules/MinLength.php | 2 +- tests/MinLengthTest.php | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Rules/MinLength.php b/src/Rules/MinLength.php index 3ed0b40..6ecc5b5 100755 --- a/src/Rules/MinLength.php +++ b/src/Rules/MinLength.php @@ -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]); } diff --git a/tests/MinLengthTest.php b/tests/MinLengthTest.php index db3811f..bdea502 100755 --- a/tests/MinLengthTest.php +++ b/tests/MinLengthTest.php @@ -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.