Does anyone have a good way to unit test an entity\'s validation constraints in Symfony2?
Ideally I want to have access to the Dependency Injection Container within
With Symfony 2.8, it seems that you can now use the AbstractConstraintValidatorTest class this way :
validator->validate(null, new MyEntity());
$this->assertNoViolation();
}
public function testNotValid()
{
$this->assertViolationRaised(new MyEntity(), MyConstraint::SOME_ERROR_NAME);
}
}
You have got a good sample with the IpValidatorTest class