Howto get PHPUnit2 talk to a browser

posted: January 22nd, 2006 · by: Sven

in: Programming · tagged as: , ·  0 comments »

Ok, I admit it took me a while to figure out how to run a PHPUnit2 testcase via http rather than cli on a Windows box.

First thing I needed to understand is that PHPUnit2_Util_Printer::__construct() sets fopen(‘php://stdout’, ‘r’); as output stream by default. This won’t output anything, so one has to advise the printer to use php://output.

Next thing was that I started the TestRunner by run(). Wrong way … this instantiated a new PHPUnit2_TextUI_TestRunner object and my output stream was send to nirvana.

The following works though:

$suite = new PHPUnit2_Framework_TestSuite();
$suite->addTestSuite(new ReflectionClass('MyTestCase'));
$runner = new PHPUnit2_TextUI_TestRunner();
$printer = new PHPUnit2_TextUI_ResultPrinter('php://output');
$runner->setPrinter($printer);
echo '<pre>';
$result = $runner->doRun($suite);

And don’t tell me to rtfm. I’ve found no docs on this. Nothing. I don’t think there are any. :(

Leave a comment

Name required
E-Mail and Website optional

If you can read this, you don't use a typical webbrowser that plays nice with CSS.
Please do not fill in anything here!

Hint: Markdown will be applied to your comment. If you post any code, be sure to escape underscores (like so: \_) if you do not want them to be converted to an <em>phasis.

artweb design
Sven Fuchs
Grünberger Str. 65
10245 Berlin, Germany


http://www.artweb-design.de

Fon +49 (30) 47 98 69 96
Fax +49 (30) 47 98 69 97