8000 [Form][Console] Use dumper by ro0NL · Pull Request #30666 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form][Console] Use dumper #30666

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions src/Symfony/Component/Form/Console/Descriptor/TextDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -97,7 +95,7 @@ protected function describeOption(OptionsResolver $optionsResolver, array $optio
{
$definition = $this->getOptionDefinition($optionsResolver, $options['option']);

$dump = $this->getDumpFunction();
$dump = new Dumper($this->output);
$map = [];
if ($definition['deprecated']) {
$map = [
Expand Down Expand Up @@ -180,23 +178,4 @@ private function normalizeAndSortOptionsColumns(array $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));
};
}
}
37 changes: 37 additions & 0 deletions src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,43 @@ public function testDebugInvalidFormType()
$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());
Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Component/Form/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
0