[Form][Console] Use dumper
This commit is contained in:
parent
041f60f80a
commit
a94228edba
@ -11,12 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\Form\Console\Descriptor;
|
||||
|
||||
use Symfony\Component\Console\Helper\Dumper;
|
||||
use Symfony\Component\Console\Helper\TableSeparator;
|
||||
use Symfony\Component\Form\ResolvedFormTypeInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\VarDumper\Caster\Caster;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
|
||||
/**
|
||||
* @author Yonel Ceruto <yonelceruto@gmail.com>
|
||||
@ -97,7 +95,7 @@ class TextDescriptor extends Descriptor
|
||||
{
|
||||
$definition = $this->getOptionDefinition($optionsResolver, $options['option']);
|
||||
|
||||
$dump = $this->getDumpFunction();
|
||||
$dump = new Dumper($this->output);
|
||||
$map = [];
|
||||
if ($definition['deprecated']) {
|
||||
$map = [
|
||||
@ -180,23 +178,4 @@ class TextDescriptor extends Descriptor
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
private function getDumpFunction()
|
||||
{
|
||||
$cloner = new VarCloner();
|
||||
$cloner->addCasters(['Closure' => function ($c, $a) {
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
|
||||
return [
|
||||
$prefix.'file' => $a[$prefix.'file'],
|
||||
$prefix.'line' => $a[$prefix.'line'],
|
||||
];
|
||||
}]);
|
||||
$dumper = new CliDumper(null, null, CliDumper::DUMP_LIGHT_ARRAY | CliDumper::DUMP_COMMA_SEPARATOR);
|
||||
$dumper->setColors($this->output->isDecorated());
|
||||
|
||||
return function ($value) use ($dumper, $cloner) {
|
||||
return rtrim($dumper->dump($cloner->cloneVar($value)->withRefHandles(false), true));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -153,6 +153,43 @@ TXT
|
||||
$this->createCommandTester()->execute(['class' => 'test']);
|
||||
}
|
||||
|
||||
public function testDebugCustomFormTypeOption()
|
||||
{
|
||||
$tester = $this->createCommandTester([], [FooType::class]);
|
||||
$ret = $tester->execute(['class' => FooType::class, 'option' => 'foo'], ['decorated' => false]);
|
||||
|
||||
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
|
||||
$this->assertStringMatchesFormat(<<<'TXT'
|
||||
|
||||
Symfony\Component\Form\Tests\Command\FooType (foo)
|
||||
==================================================
|
||||
|
||||
---------------- ---------------------------------------------------------------------------%s
|
||||
Required true %w
|
||||
---------------- ---------------------------------------------------------------------------%s
|
||||
Default - %w
|
||||
---------------- ---------------------------------------------------------------------------%s
|
||||
Allowed types [ %w
|
||||
"string" %w
|
||||
] %w
|
||||
---------------- ---------------------------------------------------------------------------%s
|
||||
Allowed values [ %w
|
||||
"bar", %w
|
||||
"baz" %w
|
||||
] %w
|
||||
---------------- ---------------------------------------------------------------------------%s
|
||||
Normalizer Closure(Options $options, $value) { %w
|
||||
class: "Symfony\Component\Form\Tests\Command\FooType" %w
|
||||
this: Symfony\Component\Form\Tests\Command\FooType { …} %w
|
||||
file: "%s"%w
|
||||
line: "%d to %d"%w
|
||||
} %w
|
||||
---------------- ---------------------------------------------------------------------------%s
|
||||
|
||||
TXT
|
||||
, $tester->getDisplay(true));
|
||||
}
|
||||
|
||||
private function createCommandTester(array $namespaces = ['Symfony\Component\Form\Extension\Core\Type'], array $types = [])
|
||||
{
|
||||
$formRegistry = new FormRegistry([], new ResolvedFormTypeFactory());
|
||||
|
@ -29,15 +29,16 @@
|
||||
"symfony/validator": "~3.4|~4.0",
|
||||
"symfony/dependency-injection": "~3.4|~4.0",
|
||||
"symfony/config": "~3.4|~4.0",
|
||||
"symfony/console": "~3.4|~4.0",
|
||||
"symfony/console": "^4.3",
|
||||
"symfony/http-foundation": "~3.4|~4.0",
|
||||
"symfony/http-kernel": "~4.3",
|
||||
"symfony/security-csrf": "~3.4|~4.0",
|
||||
"symfony/translation": "~4.2",
|
||||
"symfony/var-dumper": "~3.4|~4.0"
|
||||
"symfony/var-dumper": "^4.3"
|
||||
},
|
||||
"conflict": {
|
||||
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
|
||||
"symfony/console": "<4.3",
|
||||
"symfony/dependency-injection": "<3.4",
|
||||
"symfony/doctrine-bridge": "<3.4",
|
||||
"symfony/framework-bundle": "<3.4",
|
||||
|
Reference in New Issue
Block a user