我正在try 在symfony 6中对联系人表单上的一些潜在行为进行单元测试,并专门测试由表单域上的约束返回的消息.
为此,我try 在分析器中获取这些消息,但我找不到任何方法来检索返回的错误消息,我只找到如何获取错误数:
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
}