Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Prev Previous commit
[HttpKernel] Enhance ValidationExceptionTest with additional test cas…
…es for value and violations
  • Loading branch information
momito69 committed Oct 8, 2025
commit 1a30ed430cd1e36509561f42fc231285dd407522
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,41 @@

use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\ValidationException;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\Exception\ValidationFailedException;

class ValidationExceptionTest extends HttpExceptionTest
{
protected function createException(string $message = '', ?\Throwable $previous = null, int $code = 0, array $headers = []): HttpException
{
return new ValidationException('invalid value', $this->createMock(ConstraintViolationListInterface::class), 422, $message, $previous, $headers, $code);
return new ValidationException('invalid value', new ConstraintViolationList(), 422, $message, $previous, $headers, $code);
}

public function testGetValue()
{
$value = ['test' => 'data'];
$exception = new ValidationException($value, new ConstraintViolationList());

$this->assertSame($value, $exception->getValue());
}

public function testGetViolations()
{
$value = 'test';
$violations = new ConstraintViolationList();
$exception = new ValidationException($value, $violations);

$this->assertSame($violations, $exception->getViolations());
}

public function testDefaultPreviousIsValidationFailedException()
{
$value = 'test';
$violations = new ConstraintViolationList();
$exception = new ValidationException($value, $violations);

$this->assertInstanceOf(ValidationFailedException::class, $exception->getPrevious());
$this->assertSame($value, $exception->getPrevious()->getValue());
$this->assertSame($violations, $exception->getPrevious()->getViolations());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.