Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a94228e

Browse files
committed
[Form][Console] Use dumper
1 parent 041f60f commit a94228e

File tree

3 files changed

+42
-25
lines changed

3 files changed

+42
-25
lines changed

src/Symfony/Component/Form/Console/Descriptor/TextDescriptor.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111

1212
namespace Symfony\Component\Form\Console\Descriptor;
1313

14+
use Symfony\Component\Console\Helper\Dumper;
1415
use Symfony\Component\Console\Helper\TableSeparator;
1516
use Symfony\Component\Form\ResolvedFormTypeInterface;
1617
use Symfony\Component\OptionsResolver\OptionsResolver;
17-
use Symfony\Component\VarDumper\Caster\Caster;
18-
use Symfony\Component\VarDumper\Cloner\VarCloner;
19-
use Symfony\Component\VarDumper\Dumper\CliDumper;
2018

2119
/**
2220
* @author Yonel Ceruto <[email protected]>
@@ -97,7 +95,7 @@ protected function describeOption(OptionsResolver $optionsResolver, array $optio
9795
{
9896
$definition = $this->getOptionDefinition($optionsResolver, $options['option']);
9997

100-
$dump = $this->getDumpFunction();
98+
$dump = new Dumper($this->output);
10199
$map = [];
102100
if ($definition['deprecated']) {
103101
$map = [
@@ -180,23 +178,4 @@ private function normalizeAndSortOptionsColumns(array $options)
180178

181179
return $options;
182180
}
183-
184-
private function getDumpFunction()
185-
{
186-
$cloner = new VarCloner();
187-
$cloner->addCasters(['Closure' => function ($c, $a) {
188-
$prefix = Caster::PREFIX_VIRTUAL;
189-
190-
return [
191-
$prefix.'file' => $a[$prefix.'file'],
192-
$prefix.'line' => $a[$prefix.'line'],
193-
];
194-
}]);
195-
$dumper = new CliDumper(null, null, CliDumper::DUMP_LIGHT_ARRAY | CliDumper::DUMP_COMMA_SEPARATOR);
196-
$dumper->setColors($this->output->isDecorated());
197-
198-
return function ($value) use ($dumper, $cloner) {
199-
return rtrim($dumper->dump($cloner->cloneVar($value)->withRefHandles(false), true));
200-
};
201-
}
202181
}

src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,43 @@ public function testDebugInvalidFormType()
153153
$this->createCommandTester()->execute(['class' => 'test']);
154154
}
155155

156+
public function testDebugCustomFormTypeOption()
157+
{
158+
$tester = $this->createCommandTester([], [FooType::class]);
159+
$ret = $tester->execute(['class' => FooType::class, 'option' => 'foo'], ['decorated' => false]);
160+
161+
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
162+
$this->assertStringMatchesFormat(<<<'TXT'
163+
164+
Symfony\Component\Form\Tests\Command\FooType (foo)
165+
==================================================
166+
167+
---------------- ---------------------------------------------------------------------------%s
168+
Required true %w
169+
---------------- ---------------------------------------------------------------------------%s
170+
Default - %w
171+
---------------- ---------------------------------------------------------------------------%s
172+
Allowed types [ %w
173+
"string" %w
174+
] %w
175+
---------------- ---------------------------------------------------------------------------%s
176+
Allowed values [ %w
177+
"bar", %w
178+
"baz" %w
179+
] %w
180+
---------------- ---------------------------------------------------------------------------%s
181+
Normalizer Closure(Options $options, $value) { %w
182+
class: "Symfony\Component\Form\Tests\Command\FooType" %w
183+
this: Symfony\Component\Form\Tests\Command\FooType { …} %w
184+
file: "%s"%w
185+
line: "%d to %d"%w
186+
} %w
187+
---------------- ---------------------------------------------------------------------------%s
188+
189+
TXT
190+
, $tester->getDisplay(true));
191+
}
192+
156193
private function createCommandTester(array $namespaces = ['Symfony\Component\Form\Extension\Core\Type'], array $types = [])
157194
{
158195
$formRegistry = new FormRegistry([], new ResolvedFormTypeFactory());

src/Symfony/Component/Form/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@
2929
"symfony/validator": "~3.4|~4.0",
3030
"symfony/dependency-injection": "~3.4|~4.0",
3131
"symfony/config": "~3.4|~4.0",
32-
"symfony/console": "~3.4|~4.0",
32+
"symfony/console": "^4.3",
3333
"symfony/http-foundation": "~3.4|~4.0",
3434
"symfony/http-kernel": "~4.3",
3535
"symfony/security-csrf": "~3.4|~4.0",
3636
"symfony/translation": "~4.2",
37-
"symfony/var-dumper": "~3.4|~4.0"
37+
"symfony/var-dumper": "^4.3"
3838
},
3939
"conflict": {
4040
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
41+
"symfony/console": "<4.3",
4142
"symfony/dependency-injection": "<3.4",
4243
"symfony/doctrine-bridge": "<3.4",
4344
"symfony/framework-bundle": "<3.4",

0 commit comments

Comments
 (0)