php - Problems Unit Testing with Simpletest -


I am using PHP and simpletest for unit testing. My test works fine until I try and set a cookie

  try {setcookie ($ name, $ cookie, $ cookie_expires); } Exception exception ($ E) {blah}   

The exception has been thrown because the simplest has already written the header information, so I get the following:

Unexpected PHP error [Can not modify header information - Headers that are already sent (output starts at /tests/simpletest/reporter.php:43)] Seriousness [ E_WARNING] in [blah_code.php line 280]

I call it $ this-> gt; Have seen unclear explanations on catching with the expectException (new exception); But what documentation or examples do work, can someone provide an example of doing work or can I tell about the documentation? to be clear. This is not my code output but the simple test.

One way to go around this is to output buffering.

You can change it in PHP configuration (and possibly in .htaccess), or you can use it and its related work ( ob_get_clean () , Ob_end_flush () , etc.). For example:

  ob_start (); // Your header here is your header / cookie manipulation here   

and then:

  ob_end_clean (); // Stop buffering and dump everything (do not echo). Ob_end_flush (); // Close buffering off and resume buffer ob_get_clean (); // Stop buffering and return everything as a string.   

or other related functions I believe PHP call ob_flush () at the end of the file if you do not.

Comments