Hi,
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 by
MyCookie.php
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;
}
}
MyCookieTest.php
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));
}
}
Thanks