With Symfony 4.2, I have entity with assert :
...
/**
* @var string
*
* @Assert\NotBlank()
* @Assert\Email()
*/
private $email;
...
I have a form for this entity :
$builder
...
->add('email', null, [
'label' => 'label.email',
'help' => 'email.help_privacy',
])
...
I want to test this form. I read the doc : How to Unit Test your Forms
But when I want to test this form, But I don't know how to test asserts. Here the email is not completed while I have a Notblank() assert.
public function testSubmitValidData(): void
{
$formData = [
'name' => 'Sheriff Woody',
'message' => 'Hello Sheriff Woody',
];
$objectToCompare = new Contact();
$form = $this->factory->create(ContactType::class, $objectToCompare);
$object = new Contact();
$object->setName('Sheriff Woody');
$object->setMessage('Hello Sheriff Woody');
$form->submit($formData);
$this->assertTrue($form->isSynchronized());
$this->assertEquals(
$object,
$objectToCompare
);
$view = $form->createView();
$children = $view->children;
foreach (array_keys($formData) as $key) {
$this->assertArrayHasKey(
$key,
$children
);
}
}
But I do not know how to test the asserts of my entity. Can you help me ?