Skip to content

Commit aacb5a0

Browse files
committed
Adjusted NullableRule
Will return true only if value is null Validation message is updated to specify that the attribute has to be nullable
1 parent eb94ced commit aacb5a0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Validation/Rules/NullableRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class NullableRule implements ValidationRule
1212

1313
public function evaluate(mixed $value): bool
1414
{
15-
return true;
15+
return is_null($value);
1616
}
1717

1818
/**
@@ -25,6 +25,6 @@ public static function make(?array $parameters = null): self
2525

2626
public function validationMessage(): string
2727
{
28-
return '';
28+
return 'The :attribute must be nullable.';
2929
}
3030
}

tests/Unit/Validation/Rules/NullableRuleTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class NullableRuleTest extends ValidationRuleTestCase
1919
public function validate_validation_message(): void
2020
{
2121
self::assertEquals(
22-
'',
22+
'The :attribute must be nullable.',
2323
NullableRule::make()->validationMessage()
2424
);
2525
}
@@ -43,12 +43,12 @@ public static function data_provider(): array
4343
'valueToBeEvaluated' => null,
4444
'expectedResult' => true,
4545
],
46-
'Will return true if the value exists' => [
46+
'Will return false if the value is different then null' => [
4747
'validationRuleClassString' => NullableRule::class,
4848
'makeParams' => null,
4949
'expectedMakeException' => null,
5050
'valueToBeEvaluated' => 'Something',
51-
'expectedResult' => true,
51+
'expectedResult' => false,
5252
]
5353
];
5454
}

0 commit comments

Comments
 (0)