Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Console] Add dumper#28898

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromro0NL:console-dump
Mar 24, 2019
Merged

[Console] Add dumper#28898

fabpot merged 1 commit intosymfony:masterfromro0NL:console-dump
Mar 24, 2019

Conversation

@ro0NL
Copy link
Contributor

@ro0NLro0NL commentedOct 17, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#...
LicenseMIT
Doc PRsymfony/symfony-docs#10502

This PR adds a newDumper helper in the Console component. As there are 2 types of dumps

For the latter we cannot use the global system (debug) dumper, i.e.VarDumper::dump(), we need something tied to the current output and dependency free. Here it is:

$io =newSymfonyStyle($input,$output);$dumper =newDumper($io);$io->writeln($dumper([-0.5,0,1]));$io->writeln($dumper(new \stdClass()));$io->writeln($dumper(123));$io->writeln($dumper('foo'));$io->writeln($dumper(null));$io->writeln($dumper(true));

With VarDumper comonent:

image

Without:

image

#27684 (comment) var-dumper is not a mandatory dep of fwb, can we do without?

Now we can :)

Koc, sstok, and yceruto reacted with thumbs up emojiyceruto and sstok reacted with hooray emoji
@nicolas-grekasnicolas-grekas added this to thenext milestoneOct 20, 2018
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

(a test case would be nice)

@ro0NL
Copy link
ContributorAuthor

for tests i like to embed/wait for#28931, so the fallback would be tested using@class-not-exists CliDumper

fabpot added a commit that referenced this pull requestDec 10, 2018
This PR was squashed before being merged into the 4.3-dev branch (closes#28931).Discussion----------[PhpUnitBridge] Added ClassExistsMock| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no     <!-- seehttps://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#10528I've thought about this before, and bumped into it again when trying to test#28898This PR allows to mock `class|interface|trait_exists` to enable specific code path testingCommits-------62caec1 [PhpUnitBridge] Added ClassExistsMock
@fabpot
Copy link
Member

#28931 was merged a while ago,@ro0NL can we move forward here?

@lyrixx
Copy link
Member

I already thought about something like that. IMHO the issue is somewhere else.
We taught us we should not let some debugging tools (var_dump / dump) in our code and I agree with that.

This PR solves this this issue only in CLI, and only in the main entry point (the Command class).
Almost all my commands have a very few line of code, because everything live in services. So now, I don't useOutput::writeln anymore, but insteadLogger::log. So I will not be able to leverage this new feature.

So here we go: Many other framework / language have atrace log level. I know we are a bit limited by PSR, but IMHO the way to go is to add a new log level, where we candump many things

@lyrixx
Copy link
Member

BTW, for now you can aleady achieve this with$logger->debug('Foo var', ['foo' => $foo']).
Seesymfony/monolog-bundle#297 for more confiiguration

@ro0NL
Copy link
ContributorAuthor

@lyrixx understood

Almost all my commands have a very few line of code, because everything live in services.

Also there might be e.g. "debug-commands" with lots of code / output control. My main goal here was to obtain the dump value so i can put it in a console table, and have DX friendly output (#24208,#27684)

for now you can aleady achieve this with $logger->debug('Foo var', ['foo' => $foo'])

Im not sure using the logger is possible in my case, im looking mostly for$pretty = $dumper($value);.

So maybe get rid ofDumper::dump + dumpln at least, to avoid coupling with output control here.

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedMar 4, 2019
edited
Loading

This PR solves this this issue only in CLI

True, if we get rid ofdump() / dumpln() it practically becomes a util to convert arbitrary values into pretty printable ones (with fallback support! that's still the sold feature)

In that case putting it in VarDumper might be a better place 🤔

edit: no, if we move it to vardumper we dont need fallback support :D the whole idea was to NOT require var-dumper, but use it if available.

@lyrixx
Copy link
Member

#24208 and#27684 are valid use case for this PR. I'm 👍 with it. Thanks

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedMar 8, 2019
edited
Loading

Cool :) tend to keepdump() /dumpln() actually, it's tied to console output; but we need that to know about colorization (maybe keep that dependency optional?)

Unless we prefer$output->writeln($dumper($var)) over$dumper->dumpln($var). Let me know.

@fabpot
Copy link
Member

I think I prefer composition, so$output->writeln($dumper($var)) would be my personal preference.

@ro0NL
Copy link
ContributorAuthor

ro0NL commentedMar 22, 2019
edited
Loading

i dont understand the failures yet, running a single test works as expected (--filter=testFallbackInvoke), but running theDumerTest fully it breaks the mocking.

In this caseclass_exists behaves very weird :/

var_dump(    class_exists::class,class_exists(CliDumper::class),\Symfony\Component\Console\Helper\class_exists(CliDumper::class),class_exists(CliDumper::class));// Symfony\Component\Console\Helper\class_exists"// bool(true) <-- unexpected// bool(false)// bool(false)

edit: i've split the tests for now into 2 individual suites, this seems to overcome the state issue.

@ro0NL
Copy link
ContributorAuthor

Green&ready 👍

status: needs review

@fabpot
Copy link
Member

Thank you@ro0NL.

ro0NL reacted with hooray emoji

@fabpotfabpot merged commitfc7465c intosymfony:masterMar 24, 2019
fabpot added a commit that referenced this pull requestMar 24, 2019
This PR was squashed before being merged into the 4.3-dev branch (closes#28898).Discussion----------[Console] Add dumper| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no     <!-- seehttps://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#10502This PR adds a new `Dumper` helper in the Console component. As there are 2 types of dumps- debug purpose (e.g. `dd()`, `dump()`)- output purpose (see#24208,#27684)For the latter we cannot use the global system (debug) dumper, i.e. `VarDumper::dump()`, we need something tied to the current output and dependency free. Here it is:```php$io = new SymfonyStyle($input, $output);$dumper = new Dumper($io);$io->writeln($dumper([-0.5, 0, 1]));$io->writeln($dumper(new \stdClass()));$io->writeln($dumper(123));$io->writeln($dumper('foo'));$io->writeln($dumper(null));$io->writeln($dumper(true));```With VarDumper comonent:![image](https://user-images.githubusercontent.com/1047696/47069483-4cc26f80-d1ef-11e8-902e-2f9b0f040f25.png)Without:![image](https://user-images.githubusercontent.com/1047696/47069517-6663b700-d1ef-11e8-9328-ae1db0b83d7e.png)>#27684 (comment) var-dumper is not a mandatory dep of fwb, can we do without?Now we can  :)Commits-------fc7465c [Console] Add dumper
@ro0NLro0NL deleted the console-dump branchMarch 24, 2019 10:34
@ro0NLro0NL mentioned this pull requestMar 24, 2019
fabpot added a commit that referenced this pull requestMar 25, 2019
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     <!-- seehttps://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-------a94228e [Form][Console] Use dumper
@nicolas-grekasnicolas-grekas modified the milestones:next,4.3Apr 30, 2019
@fabpotfabpot mentioned this pull requestMay 9, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@fabpotfabpotfabpot approved these changes

+3 more reviewers

@KocKocKoc left review comments

@ogizanagiogizanagiogizanagi left review comments

@stloydstloydstloyd requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.3

Development

Successfully merging this pull request may close these issues.

8 participants

@ro0NL@fabpot@lyrixx@stloyd@Koc@nicolas-grekas@ogizanagi@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp