[UPHPU] PHP way of grabbing headers

Walt Haas haas at xmission.com
Wed Aug 16 14:48:34 MDT 2006


I'm trying to write a PHPUnit test for HTML output.  For the HTML that
comes after the headers, it's easy:

      ob_start();
      call_code_to_generate_html();
      $this->assertEquals("<html>...</html>", ob_get_clean());

But the output buffer calls don't grab the HTTP header records.
Furthermore, if you run this under PHPUnit, there has already been
some output written to stdout so header(whatever) calls in the code
being tested generate a warning message.

One solution might be to have the test start a subprocess which runs
the code being tested in its own shell, then grabs all the output to
stdout from the shell.  This could likely be made to work on any given
copy of Linux/Unix but if there is a purely PHP solution it would be a
lot more portable.  Does anybody know of a purely PHP way to do this?

TIA  -- Walt
-------
Walt Haas          The Website Doctor - Cures Sick Websites
(801) 534-1262     http://thewebsitedoctor.net


More information about the UPHPU mailing list