PHPUnit:: How can function that set and get cookies, tested?

Odothethads

New Member
PHPUnit:: How can function that set and get cookies, tested without get error : headers already sent by?Example that give error:PHPUnit_Framework_Error_Warning: Cannot modify header information - headers already sent byMyCookie.php\[code\]class MyCookie{public static function createCookie(){ $uid = null; $cookieName='test_cookie'; if(!isset($_COOKIE[$cookieName])){ $uid = unique_hash(); setcookie($cookieName, $uid, 0, '', '', false, true); } else{ $uid=$_COOKIE[$cookieName]; } return $uid; }}\[/code\]MyCookieTest.php\[code\]class MyCookieTest extends PHPUnit_Framework_TestCase{ public function test_createCookie(){ MyCookie::createCookie(); assertThat(isset($_COOKIE['test_cookie']), is(true)); unset($_COOKIE['test_cookie']); MyCookie::createCookie(); assertThat(isset($_COOKIE['test_cookie']), is(true)); }}\[/code\]Thanks
 
Back
Top