feature #30666 [Form][Console] Use dumper (ro0NL)
This PR was merged into the 4.3-dev branch.
Discussion
----------
[Form][Console] Use dumper
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License | MIT
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->
Continuation of #28898 for `debug:form`
Commits
-------
a94228edba
[Form][Console] Use dumper
This commit is contained in:
commit
31cd26b97e
@ -11,12 +11,10 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Console\Descriptor;
|
namespace Symfony\Component\Form\Console\Descriptor;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Helper\Dumper;
|
||||||
use Symfony\Component\Console\Helper\TableSeparator;
|
use Symfony\Component\Console\Helper\TableSeparator;
|
||||||
use Symfony\Component\Form\ResolvedFormTypeInterface;
|
use Symfony\Component\Form\ResolvedFormTypeInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
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>
|
* @author Yonel Ceruto <yonelceruto@gmail.com>
|
||||||
@ -97,7 +95,7 @@ class TextDescriptor extends Descriptor
|
|||||||
{
|
{
|
||||||
$definition = $this->getOptionDefinition($optionsResolver, $options['option']);
|
$definition = $this->getOptionDefinition($optionsResolver, $options['option']);
|
||||||
|
|
||||||
$dump = $this->getDumpFunction();
|
$dump = new Dumper($this->output);
|
||||||
$map = [];
|
$map = [];
|
||||||
if ($definition['deprecated']) {
|
if ($definition['deprecated']) {
|
||||||
$map = [
|
$map = [
|
||||||
@ -180,23 +178,4 @@ class TextDescriptor extends Descriptor
|
|||||||
|
|
||||||
return $options;
|
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']);
|
$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 = [])
|
private function createCommandTester(array $namespaces = ['Symfony\Component\Form\Extension\Core\Type'], array $types = [])
|
||||||
{
|
{
|
||||||
$formRegistry = new FormRegistry([], new ResolvedFormTypeFactory());
|
$formRegistry = new FormRegistry([], new ResolvedFormTypeFactory());
|
||||||
|
@ -29,15 +29,16 @@
|
|||||||
"symfony/validator": "~3.4|~4.0",
|
"symfony/validator": "~3.4|~4.0",
|
||||||
"symfony/dependency-injection": "~3.4|~4.0",
|
"symfony/dependency-injection": "~3.4|~4.0",
|
||||||
"symfony/config": "~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-foundation": "~3.4|~4.0",
|
||||||
"symfony/http-kernel": "~4.3",
|
"symfony/http-kernel": "~4.3",
|
||||||
"symfony/security-csrf": "~3.4|~4.0",
|
"symfony/security-csrf": "~3.4|~4.0",
|
||||||
"symfony/translation": "~4.2",
|
"symfony/translation": "~4.2",
|
||||||
"symfony/var-dumper": "~3.4|~4.0"
|
"symfony/var-dumper": "^4.3"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
|
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
|
||||||
|
"symfony/console": "<4.3",
|
||||||
"symfony/dependency-injection": "<3.4",
|
"symfony/dependency-injection": "<3.4",
|
||||||
"symfony/doctrine-bridge": "<3.4",
|
"symfony/doctrine-bridge": "<3.4",
|
||||||
"symfony/framework-bundle": "<3.4",
|
"symfony/framework-bundle": "<3.4",
|
||||||
|
Reference in New Issue
Block a user