Skip to content

Commit fad000c

Browse files
Merge pull request #30 from rpkamp/number-type
Add support for Symfony's NumberType
2 parents dc9fb20 + 5387adc commit fad000c

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public function iRunTheCommandAndIProvideAsInputOneLine($name, $input)
6262
public function theOutputShouldBe(PyStringNode $expectedOutput)
6363
{
6464
Assertion::same(
65-
StringUtil::trimLines((string) $expectedOutput),
66-
StringUtil::trimLines($this->getOutput())
65+
StringUtil::trimLines($this->getOutput()),
66+
StringUtil::trimLines((string) $expectedOutput)
6767
);
6868
}
6969

features/interactive.feature

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,16 @@ Feature: It is possible to interactively fill in a form from the CLI
194194
"""
195195
[street] => third street
196196
"""
197+
198+
Scenario: Provide a value for a form with a price
199+
When I run the command "form:price" and I provide as input
200+
"""
201+
10.95[enter]
202+
"""
203+
Then the output should be
204+
"""
205+
Price: Array
206+
(
207+
[price] => 10.95
208+
)
209+
"""
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Matthias\SymfonyConsoleForm\Bridge\Transformer;
5+
6+
final class NumberTransformer extends TextTransformer
7+
{
8+
}

src/Bundle/services.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ services:
3939
tags:
4040
- { name: form_to_question_transformer, form_type: Symfony\Component\Form\Extension\Core\Type\TextType }
4141

42+
matthias_symfony_console_form.number_transformer:
43+
class: Matthias\SymfonyConsoleForm\Bridge\Transformer\NumberTransformer
44+
parent: matthias_symfony_console_form.abstract_transformer
45+
public: false
46+
tags:
47+
- { name: form_to_question_transformer, form_type: Symfony\Component\Form\Extension\Core\Type\NumberType }
48+
4249
matthias_symfony_console_form.date_time_transformer:
4350
class: Matthias\SymfonyConsoleForm\Bridge\Transformer\DateTimeTransformer
4451
parent: matthias_symfony_console_form.abstract_transformer

test/Form/PriceType.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Matthias\SymfonyConsoleForm\Tests\Form;
5+
6+
use Symfony\Component\Form\AbstractType;
7+
use Symfony\Component\Form\Extension\Core\Type\NumberType;
8+
use Symfony\Component\Form\FormBuilderInterface;
9+
10+
final class PriceType extends AbstractType
11+
{
12+
public function buildForm(FormBuilderInterface $builder, array $options)
13+
{
14+
$builder->add('price', NumberType::class);
15+
}
16+
}

test/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ services:
8282
tags:
8383
- { name: console.command }
8484

85+
ask_price_command:
86+
class: Matthias\SymfonyConsoleForm\Tests\Command\PrintFormDataCommand
87+
arguments:
88+
- Matthias\SymfonyConsoleForm\Tests\Form\PriceType
89+
- price
90+
tags:
91+
- { name: console.command }
92+
8593
framework:
8694
form:
8795
csrf_protection: true

0 commit comments

Comments
 (0)