Skip to content

Commit 0945b7c

Browse files
committed
Add test for prefilled data in collections
1 parent 57db6e8 commit 0945b7c

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

features/interactive.feature

+18
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,21 @@ Feature: It is possible to interactively fill in a form from the CLI
161161
"""
162162
[name] => Jelmer
163163
"""
164+
165+
Scenario: Remove an address from pre filled collection of blocked addresses
166+
When I run the command "form:blocked_addresses" and I provide as input
167+
"""
168+
[enter][enter][enter][enter][enter]n[enter][enter]
169+
"""
170+
And the output should contain
171+
"""
172+
[street] => first street
173+
"""
174+
And the output should contain
175+
"""
176+
[street] => second street
177+
"""
178+
And the output should not contain
179+
"""
180+
[street] => third street
181+
"""

test/Form/BlockedAddressesType.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Matthias\SymfonyConsoleForm\Tests\Form;
4+
5+
use Matthias\SymfonyConsoleForm\Tests\Form\Data\Address;
6+
use Symfony\Component\Form\AbstractType;
7+
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
8+
use Symfony\Component\Form\FormBuilderInterface;
9+
use Symfony\Component\OptionsResolver\OptionsResolver;
10+
11+
class BlockedAddressesType extends AbstractType
12+
{
13+
public function buildForm(FormBuilderInterface $builder, array $options)
14+
{
15+
$builder
16+
->add(
17+
'addresses',
18+
CollectionType::class,
19+
[
20+
'entry_type' => AddressType::class,
21+
'allow_add' => true,
22+
'allow_delete' => true,
23+
'label' => 'Blocked addresses',
24+
]
25+
)
26+
;
27+
}
28+
29+
public function configureOptions(OptionsResolver $resolver)
30+
{
31+
$resolver->setDefaults(
32+
[
33+
'data' => [
34+
'addresses' => [
35+
new Address('first street'),
36+
new Address('second street'),
37+
new Address('third street'),
38+
],
39+
],
40+
]
41+
);
42+
}
43+
}

test/Form/Data/Address.php

+8
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@
55
class Address
66
{
77
public $street;
8+
9+
/**
10+
* @param $street
11+
*/
12+
public function __construct($street)
13+
{
14+
$this->street = $street;
15+
}
816
}

test/config.yml

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ services:
2626
tags:
2727
- { name: console.command }
2828

29+
blocked_addresses_command:
30+
class: Matthias\SymfonyConsoleForm\Tests\Command\PrintFormDataCommand
31+
arguments:
32+
- Matthias\SymfonyConsoleForm\Tests\Form\BlockedAddressesType
33+
- blocked_addresses
34+
tags:
35+
- { name: console.command }
36+
2937
color_command:
3038
class: Matthias\SymfonyConsoleForm\Tests\Command\PrintFormDataCommand
3139
arguments:

0 commit comments

Comments
 (0)