Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8620387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:34:05+00:00 2026-06-12T06:34:05+00:00

When running a PHPUnit test, I would like to be able to dump output

  • 0

When running a PHPUnit test, I would like to be able to dump output so I can debug one or two things.

I have tried the following (similar to the PHPUnit Manual example);

class theTest extends PHPUnit_Framework_TestCase
{
    /**
     * @outputBuffering disabled
     */
    public function testOutput() {
        print_r("Hello World");
        print "Ping";
        echo "Pong";
        $out = "Foo";
        var_dump($out);
    }   
}

With the following result:

PHPUnit @package_version@ by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 3.00Mb

OK (1 test, 0 assertions)

Notice there is none of the expected output.

I’m using the HEAD versions of the git repos as of September 19th, 2011.

Output of php -version:

$ php -version
PHP 5.2.9 (cli) (built: Dec  8 2010 11:36:37) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

Is there anything I’m doing wrong, or is this potentially a PHPUnit bug?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:34:06+00:00Added an answer on June 12, 2026 at 6:34 am

    UPDATE

    Just realized another way to do this that works much better than the --verbose command line option:

    class TestSomething extends PHPUnit_Framework_TestCase {
        function testSomething() {
            $myDebugVar = array(1, 2, 3);
            fwrite(STDERR, print_r($myDebugVar, TRUE));
        }
    }
    

    This lets you dump anything to your console at any time without all the unwanted output that comes along with the --verbose CLI option.


    As other answers have noted, it’s best to test output using the built-in methods like:

    $this->expectOutputString('foo');
    

    However, sometimes it’s helpful to be naughty and see one-off/temporary debugging output from within your test cases. There is no need for the var_dump hack/workaround, though. This can easily be accomplished by setting the --verbose command line option when running your test suite. For example:

    $ phpunit --verbose -c phpunit.xml
    

    This will display output from inside your test methods when running in the CLI environment.

    See: Writing Tests for PHPUnit – Testing Output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running PHP unit as follows: phpunit --debug --verbose --coverage-clover=/tmp/test.xml and get the
Is there a simple Web interface to running PHPUnit test suites? i.e. a PHP
When running the mvn test command, the PHPUnit tests are run. The problem I
I'm having a problem when running my PHPUnit test of creating a new profile,
I have two installations of php on my server. One version of php is
I'm working on a test in phpunit and I'm running into an issue. I
PHPUnit runs the setUp() method of a test class prior to running a specific
I'm running server on Mandriva 2011 Apache 2.2.22 PHP 5.3.14 PHPUnit Version 3.3.17 Selenium
Running this program is printing forked! 7 times. Can someone explain how forked! is
Running SQL Server 2008 (not R2). I have a few reports that have URLs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.