Skip to content

Commit 61fe2ed

Browse files
committed
Test required
1 parent b3a1fd3 commit 61fe2ed

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

tests/Types/UserFormType.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class UserFormType extends AbstractType
1111
public function buildForm(FormBuilderInterface $builder, array $options)
1212
{
1313
$builder
14-
->add('name', TextType::class)
14+
->add('name', TextType::class, [
15+
'required' => true,
16+
])
1517
->add('email', EmailType::class, [
1618
'rules' => 'email',
1719
])

tests/ValidationTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,26 @@ public function testValidForm()
3232
$this->assertTrue($form->isValid());
3333
}
3434

35-
public function testInvalidForm()
35+
public function testMissingNameForm()
36+
{
37+
/** @var UserFormType $form */
38+
$form = FormFactory::create(UserFormType::class, [])
39+
->add('save', SubmitType::class, ['label' => 'Save user']);
40+
41+
$request = $this->createPostRequest([
42+
'user_form' => [
43+
'email' => '[email protected]',
44+
'save' => true,
45+
]
46+
]);
47+
48+
$form->handleRequest($request);
49+
50+
$this->assertTrue($form->isSubmitted());
51+
$this->assertFalse($form->isValid());
52+
}
53+
54+
public function testInvalidEmailForm()
3655
{
3756
/** @var UserFormType $form */
3857
$form = FormFactory::create(UserFormType::class, [])

0 commit comments

Comments
 (0)