I'm trying to unit tests some potential behaviors on a contact form in Symfony 6, and specifically test the messages returned by the constraints on the form fields.
To do so I try to get these messages within the profiler, but I can't find any method to retrieve the error messages returned, all I found is how to get the number of errors :
public function testFailureEmailSending()
{
// Given
$this->client->enableProfiler();
// When
$this->client->request('POST', '/contact', [
'contact' => [
'name' => '',
'email' => '',
'phone' => '',
'message' => 'Less than 30 characters !',
]]);
if ($profile = $this->client->getProfile()) {
$validator = $profile->getCollector('validator');
$violationsCount = $validator->getViolationsCount();
// how to retrieve error messages ?
}
// Then
$this->assertEquals(4, $violationsCount); // works
}