Skip to content
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

[VarDumper] feat: function jd() to dump variables without html tags in json api call #54772

Open
wants to merge 1 commit into
base: 7.2
Choose a base branch
from

Conversation

pierresh
Copy link

@pierresh pierresh commented Apr 29, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
Issues Refs #49754
License MIT

dd() is really useful in the browser. However, when testing my endpoints with Behat in command line, the HTML tags generated by dd() make the result unreadable. To address this issue, I introduced the function jd() to simply dump the variables without generating HTML tags. This approach is more convenient than replacing dd() with var_dump() + die() + status 500.

Please see the example below:

currently, when dd(1,2,3);

current situation

And with jd(1,2,3);

new

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@pierresh pierresh changed the title feat: function js() to dump variables without html tags in json api call feat: function jd() to dump variables without html tags in json api call Apr 29, 2024
@alexandre-daubois
Copy link
Contributor

Why calling this function jd()? I assume it stands for "JSON dump", however, looking at the code, there's no mention about JSON.

I think you may instead set a new VarDumper handler in your tests context. This will allow you to use the CliDumper rather than HtmlDumper. You will have less noise in your output. You can have an example here: https://symfony.com/doc/current/components/var_dumper.html#advanced-usage. You may do this in a Behat step executed before each scenario or feature.

Alternatively, you can set the VAR_DUMPER_FORMAT env var to cli in your test env to achieve this.

@pierresh
Copy link
Author

pierresh commented Apr 30, 2024

Indeed, I called jd() for JSON. It might be wiser to rename it vd() or vdd() for var_dump() and die();

Yes, I could add some setup to my Behat tests for this, but I found that other people had the same needs as me in the issue 49754. So I believe it could be useful to have such a function for "off-road" debugging :).

@fabpot fabpot modified the milestones: 7.1, 7.2 May 1, 2024
@carsonbot carsonbot changed the title feat: function jd() to dump variables without html tags in json api call [VarDumper] feat: function jd() to dump variables without html tags in json api call May 2, 2024
@Jimbolino
Copy link

VAR_DUMPER_FORMAT=cli just writes to php://stdout, this is not useful when debugging api calls :)

There should be a "PlainTextDumper", and i would advocate that that would be the default,
unless there is a Accept: text/html header present, then HtmlDumper should be called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants