Skip to content

Commit

Permalink
fix custom validation error message
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault JUNIN <[email protected]>
  • Loading branch information
thibaultjunin committed Jan 1, 2023
1 parent 476ab36 commit b5eb6e1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ValidationError.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(string $key, string $rule, array $attributes)
public function __toString()
{
if ($this->rule == ValidationRules::CUSTOM) {
return sprintf($this->messages[$this->rule], ...$this->attributes);
return sprintf($this->messages[$this->rule], $this->attributes[0]);
}
return sprintf($this->messages[$this->rule], $this->key, ...$this->attributes);
}
Expand Down
1 change: 1 addition & 0 deletions tests/SimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public function testCustomValidation()
$customValidator->addError("random");
});
$this->assertCount(1, $validator->getErrors(), json_encode($validator->getErrors()));
$this->assertEquals("random", $validator->getErrors()[0], json_encode($validator->getErrors()));
}

}

0 comments on commit b5eb6e1

Please sign in to comment.