Skip to content

Commit

Permalink
fix(validator): allow to pass both a ConstraintViolationList and a pr…
Browse files Browse the repository at this point in the history
…evious exception (#6762)
  • Loading branch information
xavierlacot authored Oct 30, 2024
1 parent 216d9cc commit 736ca04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Validator/Exception/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 15 additions & 0 deletions src/Validator/Tests/Exception/ValidationExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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", <<<TXT
message 1
TXT
), $e->__toString());
$this->assertSame($previous, $e->getPrevious());
}
}

0 comments on commit 736ca04

Please sign in to comment.