Skip to content

Commit 440168e

Browse files
committed
Add test for resubmitting the invalid data
1 parent b7e1baa commit 440168e

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

features/interactive.feature

+15
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,18 @@ Feature: It is possible to interactively fill in a form from the CLI
146146
[fieldName] => empty
147147
)
148148
"""
149+
150+
Scenario: Provide no value with no default value, value should be asked again
151+
When I run the command "form:name_without_default_value" and I provide as input "[enter]Jelmer[enter]"
152+
And the output should contain
153+
"""
154+
Your name: Invalid data provided: name:
155+
"""
156+
And the output should contain
157+
"""
158+
ERROR: This value should not be blank
159+
"""
160+
And the output should contain
161+
"""
162+
[name] => Jelmer
163+
"""
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Matthias\SymfonyConsoleForm\Tests\Form;
4+
5+
use Symfony\Component\Form\AbstractType;
6+
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
7+
use Symfony\Component\Form\Extension\Core\Type\TextType;
8+
use Symfony\Component\Form\FormBuilderInterface;
9+
use Symfony\Component\Validator\Constraints\NotBlank;
10+
11+
class NameWithoutDefaultValueType extends AbstractType
12+
{
13+
public function buildForm(FormBuilderInterface $builder, array $options)
14+
{
15+
$builder->add(
16+
'name',
17+
TextType::class,
18+
[
19+
'label' => 'Your name',
20+
'constraints' => [
21+
new NotBlank(),
22+
],
23+
]
24+
)->add(
25+
'submit',
26+
SubmitType::class,
27+
[
28+
'label' => 'Submit',
29+
]
30+
);
31+
}
32+
}

test/config.yml

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ services:
1818
tags:
1919
- { name: console.command }
2020

21+
name_without_default_value_command:
22+
class: Matthias\SymfonyConsoleForm\Tests\Command\PrintFormDataCommand
23+
arguments:
24+
- Matthias\SymfonyConsoleForm\Tests\Form\NameWithoutDefaultValueType
25+
- name_without_default_value
26+
tags:
27+
- { name: console.command }
28+
2129
color_command:
2230
class: Matthias\SymfonyConsoleForm\Tests\Command\PrintFormDataCommand
2331
arguments:

0 commit comments

Comments
 (0)