2

I am new to Phpunit, and by coincidence (as of Sept, 2012) I have installed the brand-new phpunit 3.7.0 (actually it's displayed as 3.7.1 because my phpunit installation is a git checkout)

What I want is an test-aware "echo" keyword or printf Function that does the same in a phpunit test class as does the diag() function or the note() function from perl's Test::More module.

diag

diag(@diagnostic_message);

Prints a diagnostic message which is guaranteed not to interfere with test output. Like print @diagnostic_message is simply concatenated together.

note

    note(@diagnostic_message);

Like diag(), except the message will not be seen when the test is run in a harness. It will only be visible in the verbose TAP stream.

Handy for putting in notes which might be useful for debugging, but don't indicate a problem.

I haven't yet discovered the way PHPUnit does this.

    Please note that PHPUnit swallows all output that is emitted during the execution of a test.
 In strict mode, a test that emits output will fail.

There are workarounds.

Community
  • 1
  • 1
knb
  • 9,138
  • 4
  • 58
  • 85
  • `phpunit --verbose` should do it if you want to see output generated inside your test ... –  Sep 26 '12 at 16:13
  • @frank-farmer There was no answer yet. I have edited this post substantially, now asking a different question I really wanted to ask in the first place. What about deleting your comment? Avoids confusion for prospective readers (I'll delete this comment, too) – knb Sep 27 '12 at 11:52
  • Related question, answer from edorian from Sep 27, 2012 contains a workaround: http://stackoverflow.com/questions/12610605/is-there-a-way-to-tell-if-debug-or-verbose-was-passed-to-phpunit-in-a-test – knb Oct 09 '12 at 14:03

1 Answers1

3

I'm not aware of any there is, you could create your own PHPUnit_Framework_TestListener and also extend your testcase to offer helper functions that are storing away those messages. After the test has been run, those messages can be output.

That is just an idea, I've never implemented a TestListener so far for Phpunit, however extended testcases which is fairly straight forward (manual says: "This is one of the easiest ways to extend PHPUnit.").

Hope this is already helpful, you might also have some requirements with the logging so not sure if the STDOUT you would create would do it finally, and this is PHPUnit 3.6 I hope this works pretty much the same with 3.7.

hakre
  • 193,403
  • 52
  • 435
  • 836