44
55use Github \HttpClient \CachedHttpClient ;
66use Github \HttpClient \Message \Response ;
7- use Github \HttpClient \Message \Request ;
87
98class CachedHttpClientTest extends HttpClientTest
109{
@@ -14,7 +13,8 @@ class CachedHttpClientTest extends HttpClientTest
1413 public function shouldCacheResponseAtFirstTime ()
1514 {
1615 $ cache = $ this ->getCacheMock ();
17- $ httpClient = new CachedHttpClient (
16+
17+ $ httpClient = new TestCachedHttpClient (
1818 array ('base_url ' => '' ),
1919 $ this ->getMock ('Buzz\Client\ClientInterface ' , array ('setTimeout ' , 'setVerifyPeer ' , 'send ' )),
2020 $ cache
@@ -35,18 +35,19 @@ public function shouldGetCachedResponseWhileResourceNotModified()
3535
3636 $ cache = $ this ->getCacheMock ();
3737
38- $ httpClient = new CachedHttpClient (
38+ $ response = new Response ;
39+ $ response ->addHeader ('HTTP/1.1 304 Not Modified ' );
40+
41+ $ httpClient = new TestCachedHttpClient (
3942 array ('base_url ' => '' ),
4043 $ client ,
4144 $ cache
4245 );
46+ $ httpClient ->fakeResponse = $ response ;
4347
4448 $ cache ->expects ($ this ->once ())->method ('get ' )->with ('test ' );
4549
46- $ response = new Response ;
47- $ response ->addHeader ('HTTP/1.1 304 Not Modified ' );
48-
49- $ httpClient ->request ('test ' , array (), 'GET ' , array (), $ response );
50+ $ httpClient ->get ('test ' );
5051 }
5152
5253 /**
@@ -59,23 +60,34 @@ public function shouldRenewCacheWhenResourceHasChanged()
5960
6061 $ cache = $ this ->getCacheMock ();
6162
62- $ httpClient = new CachedHttpClient (
63+ $ response = new Response ;
64+ $ response ->addHeader ('HTTP/1.1 200 OK ' );
65+
66+ $ httpClient = new TestCachedHttpClient (
6367 array ('base_url ' => '' ),
6468 $ client ,
6569 $ cache
6670 );
67-
68- $ response = new Response ;
69- $ response ->addHeader ('HTTP/1.1 200 OK ' );
71+ $ httpClient ->fakeResponse = $ response ;
7072
7173 $ cache ->expects ($ this ->once ())->method ('set ' )->with ('test ' , $ response );
7274 $ cache ->expects ($ this ->once ())->method ('getModifiedSince ' )->with ('test ' )->will ($ this ->returnValue (1256953732 ));
7375
74- $ httpClient ->request ('test ' , array (), ' GET ' , array (), $ response );
76+ $ httpClient ->get ('test ' );
7577 }
7678
7779 public function getCacheMock ()
7880 {
7981 return $ this ->getMock ('Github\HttpClient\Cache\CacheInterface ' );
8082 }
8183}
84+
85+ class TestCachedHttpClient extends CachedHttpClient
86+ {
87+ public $ fakeResponse ;
88+
89+ protected function createResponse ()
90+ {
91+ return $ this ->fakeResponse ?: new Response ();
92+ }
93+ }
0 commit comments