Quick Tip

Quick Tip – Outputting variables in PHPUnit

I’ve been running through PHPUnit a bit lately, and sometimes I need to track some of the variables as I’m going through the tests. I’ve found two tricks that have helped…

Quick Tip

var_dump and –debug

If you add a var_dump($variable) to your unit test, you can use the –debug flag when running the unit tests to see the var_dump in the output. This is particularly helpful with arrays or objects.

stderr output

If you need to output a single variable, or sometimes just a basic message, you can write to stderr, which in turn will push the message out to the screen

fwrite(STDERR, print_r('Message', TRUE));

That’s it. Oh, and I like to use the –tap option for a little more verbose output when running the tests.



2 thoughts on “Quick Tip – Outputting variables in PHPUnit”

  1. Have you looked at xdebug.profiler_enable ?

    Might be faster than having to type out print lines.

What are your 10 bits on the matter? I want to know!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s