Skip to content

Commit 736ca04

Browse files
authoredOct 30, 2024··
fix(validator): allow to pass both a ConstraintViolationList and a previous exception (#6762)
1 parent 216d9cc commit 736ca04

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
 

‎src/Validator/Exception/ValidationException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __construct(string|ConstraintViolationListInterface $message = '
7575

7676
if ($message instanceof ConstraintViolationListInterface) {
7777
$this->constraintViolationList = $message;
78-
parent::__construct($code ?? $this->__toString(), $previous ?? 0, $errorTitle instanceof \Throwable ? $errorTitle : null);
78+
parent::__construct($this->__toString(), $code ?? 0, $previous);
7979

8080
return;
8181
}

‎src/Validator/Tests/Exception/ValidationExceptionTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,19 @@ public function testToString(): void
3939
TXT
4040
), $e->__toString());
4141
}
42+
43+
public function testWithPrevious(): void
44+
{
45+
$previous = new \Exception();
46+
$e = new ValidationException(new ConstraintViolationList([
47+
new ConstraintViolation('message 1', '', [], '', '', 'invalid'),
48+
]), null, $previous);
49+
$this->assertInstanceOf(\RuntimeException::class, $e);
50+
51+
$this->assertSame(str_replace(\PHP_EOL, "\n", <<<TXT
52+
message 1
53+
TXT
54+
), $e->__toString());
55+
$this->assertSame($previous, $e->getPrevious());
56+
}
4257
}

0 commit comments

Comments
 (0)
Please sign in to comment.