44
55namespace Tests \Webclient \Extension \Cookie ;
66
7- use GuzzleHttp \Psr7 \Request ;
7+ use Nyholm \Psr7 \Request ;
88use PHPUnit \Framework \TestCase ;
99use Psr \Http \Client \ClientExceptionInterface ;
1010use Stuff \Webclient \Extension \Cookie \Handler ;
1111use Stuff \Webclient \Extension \Cookie \Storage ;
12- use Webclient \Extension \Cookie \Client ;
13- use Webclient \Fake \Client as FakeClient ;
12+ use Webclient \Extension \Cookie \CookieClientDecorator ;
13+ use Webclient \Fake \FakeHttpClient ;
1414
1515class CookieClientTest extends TestCase
1616{
17-
1817 /**
1918 * @param bool $secure
2019 * @param string $host
@@ -29,7 +28,7 @@ public function testSetToStorage(bool $secure, string $host, string $path)
2928
3029 $ storage = new Storage ();
3130
32- $ client = new Client (new FakeClient (new Handler ()), $ storage );
31+ $ client = new CookieClientDecorator (new FakeHttpClient (new Handler ()), $ storage );
3332
3433 $ set = [
3534 'cookie ' => [
@@ -44,13 +43,15 @@ public function testSetToStorage(bool $secure, string $host, string $path)
4443 $ request = new Request ('GET ' , $ uri , ['Accept ' => 'text/plain ' ]);
4544 $ client ->sendRequest ($ request );
4645
47- $ path = $ path ? $ path : '/ ' ;
46+ if ($ path === '' ) {
47+ $ path = '/ ' ;
48+ }
4849 $ cookies = $ storage ->getItems ();
4950 foreach ($ set ['cookie ' ] as $ name => $ value ) {
5051 $ this ->assertArrayHasKey ($ name , $ cookies );
5152 $ domain = in_array ($ name , $ set ['subdomain ' ]) ? '. ' . $ host : $ host ;
5253 $ temp = in_array ($ name , $ set ['temp ' ]);
53- $ this ->assertStoredCookie ($ cookies [$ name ], $ value , $ domain , $ path , true , $ secure , $ temp );
54+ $ this ->assertStoredCookie ($ cookies [$ name ], $ value , $ domain , $ path , $ secure , $ temp );
5455 }
5556 }
5657
@@ -129,7 +130,7 @@ public function testGetFromStorage(string $uri, array $expected)
129130 }
130131
131132
132- $ client = new Client (new FakeClient (new Handler ()), $ storage );
133+ $ client = new CookieClientDecorator (new FakeHttpClient (new Handler ()), $ storage );
133134 $ request = new Request ('GET ' , $ uri , ['Accept ' => 'text/plain ' ]);
134135 $ response = $ client ->sendRequest ($ request );
135136 $ json = $ response ->getBody ()->__toString ();
@@ -166,14 +167,13 @@ private function assertStoredCookie(
166167 string $ value ,
167168 string $ domain ,
168169 string $ path ,
169- bool $ httpOnly ,
170170 bool $ secure ,
171171 bool $ temporary
172172 ) {
173173 $ this ->assertSame ($ value , $ cookie ['value ' ]);
174174 $ this ->assertSame ($ domain , $ cookie ['domain ' ]);
175175 $ this ->assertSame ($ path , $ cookie ['path ' ]);
176- $ this ->assertSame ($ httpOnly , $ cookie ['httpOnly ' ]);
176+ $ this ->assertSame (true , $ cookie ['httpOnly ' ]);
177177 $ this ->assertSame ($ secure , $ cookie ['secure ' ]);
178178 $ this ->assertSame ($ temporary , $ cookie ['expired ' ] === 0 );
179179 }
0 commit comments