Skip to content
23 changes: 15 additions & 8 deletions src/Symfony/AbstractConstraintValidatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,19 @@ protected function initRootForm(): Form
*/
protected function assertHandlesIncorrectConstraintType(mixed $value = null): void
{
$this->executionContext->expects(self::never())->method(self::anything());
$this->violationBuilder->expects(self::never())->method(self::anything());

$this->expectException(UnexpectedTypeException::class);
$this->validator->validate($value, $this->createMock(Constraint::class));
}

protected function expectNoViolations(): void
{
$this->executionContext->expects(static::never())->method('buildViolation');
$this->executionContext->expects(static::never())->method('addViolation');
$this->executionContext->expects(self::never())->method('buildViolation');
$this->executionContext->expects(self::never())->method('addViolation');

$this->violationBuilder->expects(self::never())->method(self::anything());
}

/**
Expand All @@ -96,7 +101,9 @@ protected function expectNoViolations(): void
*/
protected function expectViolation(string $message, array $parameters = []): void
{
$this->executionContext->expects(static::once())->method('addViolation')->with($message, $parameters);
$this->executionContext->expects(self::once())->method('addViolation')->with($message, $parameters);

$this->violationBuilder->expects(self::never())->method(self::anything());
}

/**
Expand All @@ -113,14 +120,14 @@ protected function expectViolationViaBuilder(
?string $atPath = null,
mixed $invalidValue = self::IGNORE_INVALID_VALUE
): void {
$this->executionContext->expects(static::once())->method('buildViolation')->with($message, $parameters)->willReturn($this->violationBuilder);
$this->executionContext->expects(self::once())->method('buildViolation')->with($message, $parameters)->willReturn($this->violationBuilder);
if ($atPath !== null) {
$this->violationBuilder->expects(static::once())->method('atPath')->with($atPath)->willReturnSelf();
$this->violationBuilder->expects(self::once())->method('atPath')->with($atPath)->willReturnSelf();
}
if ($invalidValue !== self::IGNORE_INVALID_VALUE) {
$this->violationBuilder->expects(static::once())->method('setInvalidValue')->with($invalidValue)->willReturnSelf();
$this->violationBuilder->expects(self::once())->method('setInvalidValue')->with($invalidValue)->willReturnSelf();
}
$this->violationBuilder->expects(static::once())->method('addViolation');
$this->violationBuilder->expects(self::once())->method('addViolation');
}

/**
Expand All @@ -145,7 +152,7 @@ protected function expectViolationViaBuilder(
*/
protected function expectBuildViolation(string $message, array $parameters = []): ConstraintViolationBuilderAssertion
{
$this->executionContext->expects(static::once())->method('buildViolation')->with($message, $parameters)->willReturn($this->violationBuilder);
$this->executionContext->expects(self::once())->method('buildViolation')->with($message, $parameters)->willReturn($this->violationBuilder);

return new ConstraintViolationBuilderAssertion($this->violationBuilder);
}
Expand Down