Behat / WebApiExtension

Behat extension to test web APIs
http://extensions.behat.org
MIT License
111 stars 114 forks source link

Pretty print JSON #24

Open dantleech opened 9 years ago

dantleech commented 9 years ago

This PR will pretty print json when print response is invoked and the Content-Type is application/json

Will add a feature/test if this is OK.

stof commented 9 years ago

I'm not sure this is a good idea. It means that the body being displayed is not the response body anymore. and it could cause weird issues in case your app is buggy and does not return valid JSON, making things very hard to debug.

dantleech commented 9 years ago

Well, if the JSON is invalid it should revert to the original $body. For me this helped alot with debugging, but your call, if you want to close this it's fine.

stof commented 9 years ago

no it won't. You don't validate the decoding of the JSON. So if decoding fails, you will reencode null, which is totally valid (it gives you $formattedJson = 'null';)

dantleech commented 9 years ago

Hmm, yeah, I didn't read the code properly. But it could validate the JSON. :)