From b5eb6e17ecfaa29b47f9d4aa980c2761a685f2de Mon Sep 17 00:00:00 2001 From: Thibault JUNIN Date: Sun, 1 Jan 2023 16:06:56 +0100 Subject: [PATCH] fix custom validation error message Signed-off-by: Thibault JUNIN --- src/ValidationError.php | 2 +- tests/SimpleTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ValidationError.php b/src/ValidationError.php index 55b677b..b969f63 100644 --- a/src/ValidationError.php +++ b/src/ValidationError.php @@ -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); } diff --git a/tests/SimpleTest.php b/tests/SimpleTest.php index fc2addd..cc63c2f 100644 --- a/tests/SimpleTest.php +++ b/tests/SimpleTest.php @@ -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())); } } \ No newline at end of file