From 96b2d1e3f11aa8e1cd7b9358a7226852ecf6dd69 Mon Sep 17 00:00:00 2001 From: Xavier Lacot Date: Mon, 28 Oct 2024 18:32:19 +0100 Subject: [PATCH] fixed the ValidationException construct when both a ConstraintViolationList and a previous are passed --- src/Validator/Exception/ValidationException.php | 2 +- .../Tests/Exception/ValidationExceptionTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Validator/Exception/ValidationException.php b/src/Validator/Exception/ValidationException.php index 98117463ff1..720f1f26ca1 100644 --- a/src/Validator/Exception/ValidationException.php +++ b/src/Validator/Exception/ValidationException.php @@ -75,7 +75,7 @@ public function __construct(string|ConstraintViolationListInterface $message = ' if ($message instanceof ConstraintViolationListInterface) { $this->constraintViolationList = $message; - parent::__construct($code ?? $this->__toString(), $previous ?? 0, $errorTitle instanceof \Throwable ? $errorTitle : null); + parent::__construct($this->__toString(), $code ?? 0, $previous); return; } diff --git a/src/Validator/Tests/Exception/ValidationExceptionTest.php b/src/Validator/Tests/Exception/ValidationExceptionTest.php index 35afcd05cfa..09c77a198f2 100644 --- a/src/Validator/Tests/Exception/ValidationExceptionTest.php +++ b/src/Validator/Tests/Exception/ValidationExceptionTest.php @@ -39,4 +39,19 @@ public function testToString(): void TXT ), $e->__toString()); } + + public function testWithPrevious(): void + { + $previous = new \Exception(); + $e = new ValidationException(new ConstraintViolationList([ + new ConstraintViolation('message 1', '', [], '', '', 'invalid'), + ]), null, $previous); + $this->assertInstanceOf(\RuntimeException::class, $e); + + $this->assertSame(str_replace(\PHP_EOL, "\n", <<__toString()); + $this->assertSame($previous, $e->getPrevious()); + } }