Skip to content

Commit

Permalink
Merge pull request #6492 from kenjis/fix-validation-greater_than_equa…
Browse files Browse the repository at this point in the history
…l_to

fix: Strict Validation Rules greater_than/less_than
  • Loading branch information
kenjis authored Sep 4, 2022
2 parents 836a5aa + f768d16 commit 3be80cb
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 499 deletions.
40 changes: 36 additions & 4 deletions system/Validation/StrictRules/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,36 @@ public function exact_length($str, string $val): bool
/**
* Greater than
*
* @param mixed $str
* @param mixed $str expects int|string
*/
public function greater_than($str, string $min): bool
{
if (is_int($str)) {
$str = (string) $str;
}

if (! is_string($str)) {
return false;
}

return $this->nonStrictRules->greater_than($str, $min);
}

/**
* Equal to or Greater than
*
* @param mixed $str
* @param mixed $str expects int|string
*/
public function greater_than_equal_to($str, string $min): bool
{
if (is_int($str)) {
$str = (string) $str;
}

if (! is_string($str)) {
return false;
}

return $this->nonStrictRules->greater_than_equal_to($str, $min);
}

Expand Down Expand Up @@ -141,20 +157,36 @@ public function is_unique($str, string $field, array $data): bool
/**
* Less than
*
* @param mixed $str
* @param mixed $str expects int|string
*/
public function less_than($str, string $max): bool
{
if (is_int($str)) {
$str = (string) $str;
}

if (! is_string($str)) {
return false;
}

return $this->nonStrictRules->less_than($str, $max);
}

/**
* Equal to or Less than
*
* @param mixed $str
* @param mixed $str expects int|string
*/
public function less_than_equal_to($str, string $max): bool
{
if (is_int($str)) {
$str = (string) $str;
}

if (! is_string($str)) {
return false;
}

return $this->nonStrictRules->less_than_equal_to($str, $max);
}

Expand Down
8 changes: 5 additions & 3 deletions tests/system/Validation/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

/**
* @internal
*
* @no-final
*/
final class RulesTest extends CIUnitTestCase
class RulesTest extends CIUnitTestCase
{
private Validation $validation;
private array $config = [
protected Validation $validation;
protected array $config = [
'ruleSets' => [
Rules::class,
FormatRules::class,
Expand Down
Loading

0 comments on commit 3be80cb

Please sign in to comment.