Skip to content

Commit

Permalink
Merge pull request #43 from or-benjamin/patch-1
Browse files Browse the repository at this point in the history
Add the ability to change the validation message
  • Loading branch information
loevgaard authored Jun 4, 2024
2 parents 1dddd47 + bda51fb commit 71be332
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Validator/CronExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,21 @@
class CronExpression extends Constraint
{
public string $message = '{{ value }} is not a valid cron expression.';

/**
* @param string|null $message
* @param string[]|null $groups
* @param mixed $payload
* @param array $options
*/
public function __construct(
string $message = null,
?array $groups = null,
mixed $payload = null,
array $options = []
) {
parent::__construct($options, $groups, $payload);

$this->message = $message ?? $this->message;
}
}
2 changes: 1 addition & 1 deletion tests/Validator/CronExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testExpectsStringCompatibleValue(): void
*/
public function testInvalidValues($value, string $valueAsString): void
{
$constraint = new Constraint(['message' => 'myMessage']);
$constraint = new Constraint('myMessage');

$this->validator->validate($value, $constraint);

Expand Down

0 comments on commit 71be332

Please sign in to comment.