@@ -14,8 +14,8 @@ public function testFromString(string $cookieString, SetCookie $expectedSetCooki
1414 {
1515 $ setCookie = SetCookie::fromString ($ cookieString );
1616
17- self :: assertEquals ($ expectedSetCookie , $ setCookie );
18- self :: assertEquals ($ cookieString , (string ) $ setCookie );
17+ $ this -> assertEquals ($ expectedSetCookie , $ setCookie );
18+ $ this -> assertEquals ($ cookieString , (string ) $ setCookie );
1919 }
2020
2121 public function provideParsesFromSetCookieStringData () : array
@@ -110,25 +110,69 @@ public function provideParsesFromSetCookieStringData() : array
110110 ->withSecure (true )
111111 ->withHttpOnly (true ),
112112 ],
113+ [
114+ 'lu=Rg3vHJZnehYLjVg7qi3bZjzg; Domain=.example.com; Path=/; Expires=Tue, 15 Jan 2013 21:47:38 GMT; Max-Age=500; Secure; HttpOnly; SameSite=Strict ' ,
115+ SetCookie::create ('lu ' )
116+ ->withValue ('Rg3vHJZnehYLjVg7qi3bZjzg ' )
117+ ->withExpires (new \DateTime ('Tue, 15-Jan-2013 21:47:38 GMT ' ))
118+ ->withMaxAge (500 )
119+ ->withPath ('/ ' )
120+ ->withDomain ('.example.com ' )
121+ ->withSecure (true )
122+ ->withHttpOnly (true )
123+ ->withSameSite ('strict ' ),
124+ ],
125+ [
126+ 'lu=Rg3vHJZnehYLjVg7qi3bZjzg; Domain=.example.com; Path=/; Expires=Tue, 15 Jan 2013 21:47:38 GMT; Max-Age=500; Secure; HttpOnly; SameSite=Lax ' ,
127+ SetCookie::create ('lu ' )
128+ ->withValue ('Rg3vHJZnehYLjVg7qi3bZjzg ' )
129+ ->withExpires (new \DateTime ('Tue, 15-Jan-2013 21:47:38 GMT ' ))
130+ ->withMaxAge (500 )
131+ ->withPath ('/ ' )
132+ ->withDomain ('.example.com ' )
133+ ->withSecure (true )
134+ ->withHttpOnly (true )
135+ ->withSameSite ('lax ' ),
136+ ],
113137 ];
114138 }
115139
116140 public function testExpireCookies () : void
117141 {
118142 $ setCookie = SetCookie::createExpired ('expire_immediately ' );
119143
120- self :: assertLessThan (\time (), $ setCookie ->getExpires ());
144+ $ this -> assertLessThan (\time (), $ setCookie ->getExpires ());
121145 }
122146
123- public function TestLongLivingCookies () : void
147+ public function testLongLivingCookies () : void
124148 {
125149 $ setCookie = SetCookie::createRememberedForever ('remember_forever ' );
126150
127151 $ fourYearsFromNow = (new \DateTime ('+4 years ' ))->getTimestamp ();
128- self ::assertGreaterThan ($ fourYearsFromNow , $ setCookie ->getExpires ());
152+ $ this ->assertGreaterThan ($ fourYearsFromNow , $ setCookie ->getExpires ());
153+ }
154+
155+ public function testSameSite () : void
156+ {
157+ $ setCookie = SetCookie::create ('foo ' , 'bar ' );
158+
159+ $ this ->assertNull ($ setCookie ->getSameSite ());
160+ $ this ->assertSame ('foo=bar ' , $ setCookie ->__toString ());
161+
162+ $ setCookie = $ setCookie ->withSameSite ('strict ' );
163+
164+ $ this ->assertEquals ('Strict ' , $ setCookie ->getSameSite ());
165+ $ this ->assertSame ('foo=bar; SameSite=Strict ' , $ setCookie ->__toString ());
166+
167+ $ setCookie = $ setCookie ->withoutSameSite ();
168+ $ this ->assertNull ($ setCookie ->getSameSite ());
169+ $ this ->assertSame ('foo=bar ' , $ setCookie ->__toString ());
170+
171+ $ this ->expectException (\InvalidArgumentException::class);
172+ $ setCookie = $ setCookie ->withSameSite ('foo ' );
129173 }
130174
131- public function TestInvalid () : void
175+ public function testInvalid () : void
132176 {
133177 $ setCookie = SetCookie::create ('foo ' , 'bar ' );
134178
0 commit comments