Note that there are some explanatory texts on larger screens.

plurals
  1. POPHPUnit - Dumping variables
    primarykey
    data
    text
    <p>I've just started using PHPUnit and am wondering if there is a build in way of dumping the contents of a variable? </p> <p>The use-case being that since I am already talking to the code I'm developing, I can use PHPUnit not only to test the stability of that code but also to output debug info while being in development.</p> <p>I know xdebug can fill this gap for me, but sometimes it's just easier to dump some info in the output rather than fiddling with my IDE debugger, which is more useful for tracing back the cause of a bug.</p> <p>I know I can just do a regular var_dump, I'm simply wondering if PHPUnit has an interface for this.</p> <p>Thanks!</p> <p><strong>Edit:</strong></p> <p>Decided to hack it together following David's answer.</p> <p>By no means a perfect solution, but it does the job for me. If anyone is interested:</p> <pre><code>*** PHPUnit-3.6.3/PHPUnit/Framework/TestCase.php 2011-11-09 12:25:38.000000000 -0500 --- PHPUnit/Framework/TestCase.php 2011-11-09 15:27:02.193317219 -0500 *************** *** 291,296 **** --- 291,298 ---- * @var boolean */ private $outputBufferingActive = FALSE; + + public static $ob_output = array(); /** * Constructs a test case with the given name. *************** *** 913,921 **** --- 915,927 ---- } try { + ob_start(); $testResult = $method-&gt;invokeArgs( $this, array_merge($this-&gt;data, $this-&gt;dependencyInput) ); + + Static::$ob_output[ $method-&gt;name ] = ob_get_contents(); + ob_end_clean(); } catch (Exception $e) { </code></pre> <p>And for use with VisualPHPUnit:</p> <pre><code>*** NSinopoli-VisualPHPUnit-b7ba91a/ui/test.html 2011-11-08 15:38:44.000000000 -0500 --- ui/test.html 2011-11-09 15:38:44.797329455 -0500 *************** *** 3,15 **** &lt;div class="name" title="Test Status: &lt;?php echo ucfirst($test['status']);?&gt;"&gt;&lt;?php echo $test['name'];?&gt;&lt;/div&gt; &lt;div class="stats"&gt;&lt;?php echo $test['message'];?&gt;&lt;/div&gt; &lt;div class="expand button"&gt;&lt;?php echo $test['expand'];?&gt;&lt;/div&gt; ! &lt;div class="more test &lt;?php echo $test['display'];?&gt;"&gt; &lt;div class="variables rounded &lt;?php echo $test['variables_display'];?&gt;"&gt; &lt;pre&gt;&lt;?php echo $test['variables_message'];?&gt;&lt;/pre&gt; ! &lt;/div&gt; &lt;div class="stacktrace rounded &lt;?php echo $test['trace_display'];?&gt;"&gt; &lt;pre&gt;&lt;?php echo $test['trace_message'];?&gt;&lt;/pre&gt; ! &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php if ( $test['separator_display'] ) { ?&gt; --- 3,21 ---- &lt;div class="name" title="Test Status: &lt;?php echo ucfirst($test['status']);?&gt;"&gt;&lt;?php echo $test['name'];?&gt;&lt;/div&gt; &lt;div class="stats"&gt;&lt;?php echo $test['message'];?&gt;&lt;/div&gt; &lt;div class="expand button"&gt;&lt;?php echo $test['expand'];?&gt;&lt;/div&gt; ! &lt;div class="more test &lt;?php echo $test['display'];?&gt;"&gt; &lt;div class="variables rounded &lt;?php echo $test['variables_display'];?&gt;"&gt; &lt;pre&gt;&lt;?php echo $test['variables_message'];?&gt;&lt;/pre&gt; ! &lt;/div&gt; &lt;div class="stacktrace rounded &lt;?php echo $test['trace_display'];?&gt;"&gt; &lt;pre&gt;&lt;?php echo $test['trace_message'];?&gt;&lt;/pre&gt; ! &lt;/div&gt; ! &lt;?php if (isset(PHPUnit_Framework_TestCase::$ob_output[$test['name']])) { ?&gt; ! &lt;h3&gt;OB Output&lt;/h3&gt; ! &lt;div class="variables rounded"&gt; ! &lt;pre&gt;&lt;?php echo PHPUnit_Framework_TestCase::$ob_output[$test['name']]; ?&gt;&lt;/pre&gt; ! &lt;/div&gt; ! &lt;?php } ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php if ( $test['separator_display'] ) { ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload