public function testToString() { $expected = 'foo=bar; expires=Fri, 20 May 2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly';
$cookie = Cookie::
create('foo', 'bar',
$expire =
strtotime('Fri, 20 May 2011 15:25:52 GMT'
), '/', '.myfoodomain.com', true, true, false, null
);
$this->
assertEquals($expected,
(string) $cookie, '->__toString() returns string representation of the cookie'
);
$cookie = Cookie::
create('foo'
) ->
withValue('bar'
) ->
withExpires(strtotime('Fri, 20 May 2011 15:25:52 GMT'
)) ->
withDomain('.myfoodomain.com'
) ->
withSecure(true
) ->
withSameSite(null
);
$this->
assertEquals($expected,
(string) $cookie, '->__toString() returns string representation of the cookie'
);
$expected = 'foo=bar%20with%20white%20spaces; expires=Fri, 20 May 2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly';
$cookie = Cookie::
create('foo', 'bar with white spaces',
strtotime('Fri, 20 May 2011 15:25:52 GMT'
), '/', '.myfoodomain.com', true, true, false, null
);
$this->
assertEquals($expected,
(string) $cookie, '->__toString() encodes the value of the cookie according to RFC 3986 (white space = %20)'
);
$cookie = Cookie::
create('foo'
) ->
withValue('bar with white spaces'
) ->
withExpires(strtotime('Fri, 20 May 2011 15:25:52 GMT'
)) ->
withDomain('.myfoodomain.com'
) ->
withSecure(true
)