Skip to content

Commit

Permalink
Fix numeric rule tests failing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BlakvGhost committed Nov 18, 2023
1 parent 4ad6812 commit 75675cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Rules/NumericRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function passes(string $field, $value, array $data): bool
$this->field = $field;

// Check if the value is numeric.
return is_numeric($value);
return ($value !== null) & is_numeric($value);
}

/**
Expand Down
11 changes: 4 additions & 7 deletions tests/Feature/RuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
$validator = new Validator(['password' => 'NoDigit'], ['password' => 'password']);
expect($validator->isValid())->toBeFalse();

expect($validator->getErrors()['field'][0])->toBe(
expect($validator->getErrors()['password'][0])->toBe(
LangManager::getTranslation('validation.password_rule', [
'attribute' => 'password',
])
Expand All @@ -195,15 +195,12 @@
expect($validator->isValid())->toBeTrue();

$validator = new Validator(['numericField' => '456'], ['numericField' => 'numeric']);
expect($validator->isValid())->toBeFalse();
expect($validator->isValid())->toBeTrue();

$validator = new Validator(['numericField' => 'NotNumeric'], ['numericField' => 'numeric']);
expect($validator->isValid())->toBeFalse();

$validator = new Validator(['numericField' => null], ['numericField' => 'numeric']);
expect($validator->isValid())->toBeFalse();

expect($validator->getErrors()['field'][0])->toBe(
expect($validator->getErrors()['numericField'][0])->toBe(
LangManager::getTranslation('validation.numeric_rule', [
'attribute' => 'numericField',
])
Expand All @@ -218,7 +215,7 @@
$validator = new Validator(['nullableField' => 'NotNull'], ['nullableField' => 'nullable']);
expect($validator->isValid())->toBeFalse();

expect($validator->getErrors()['field'][0])->toBe(
expect($validator->getErrors()['nullableField'][0])->toBe(
LangManager::getTranslation('validation.nullable_rule', [
'attribute' => 'nullableField',
])
Expand Down

0 comments on commit 75675cf

Please sign in to comment.