1

so I am trying to test some routes and controller functions that I have created. The other routes that return views work fine, and I was told by my professor that I could test the routes by just putting a vardump in the controller function they are pointing to.

Now, this doesn't really make sense to me, because the functions never return any view or ui data, they just return JSON responses.

Am I correct that there is no way to test routes like that using vardumps? Just confused here.

1
  • 1
    You can still var_dump anything you want in those functions. You would see that information in the debugger or console depending on which developer tools/browser you are using. Doing this will likely break your app because javascript isn't expecting all the extra info. I'm confused about the point of doing this though. If it's returning the json, what's the var_dump supposed to be actually testing? Commented Mar 10, 2014 at 14:50

1 Answer 1

1

When developing REST API's with Laravel (which I tend to return JSON from by default), I use the Postman client for testing. A var_dump() is pretty ugly when looking at the response if you have xdebug installed (which I do), so I tend to use print_r instead.

For example, just this morning testing something out, I added this line in my controller:

print_r($files); exit;

And this is what postman showed me:

enter image description here

You can also use var_dump if you choose to. If you don't include an exit() statement, the application will continue to run and depending and how you have things setup, you may get more than you were looking for. For me, it is just easier to dump what I need and stop the application so I can quickly see what I need to.

Sign up to request clarification or add additional context in comments.

1 Comment

Don't forget the Laravel way of dump and die! dd(...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.