File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change 77use GuzzleHttp \Psr7 \Response ;
88use Psr \Http \Message \RequestInterface ;
99
10+ /**
11+ * HTTP adapter mock
12+ *
13+ * This mock is most useful in tests. It does not send requests but stores them
14+ * for later retrieval. Additionally, you can set an exception to test
15+ * exception handling.
16+ */
1017class MockHttpAdapter implements HttpAdapter
1118{
12- private $ requests = array () ;
19+ private $ requests = [] ;
1320 private $ exception ;
1421
1522 /**
@@ -18,11 +25,7 @@ class MockHttpAdapter implements HttpAdapter
1825 public function sendRequest (RequestInterface $ request , array $ options = [])
1926 {
2027 $ this ->requests [] = $ request ;
21-
22- if ($ this ->exception ) {
23- throw $ this ->exception ;
24- }
25-
28+
2629 return new Response ();
2730 }
2831
@@ -33,19 +36,19 @@ public function sendRequests(array $requests, array $options = [])
3336 {
3437 $ responses = [];
3538 $ exceptions = new MultiHttpAdapterException ();
36-
39+
3740 foreach ($ requests as $ request ) {
3841 try {
3942 $ responses [] = $ this ->sendRequest ($ request );
4043 } catch (\Exception $ e ) {
4144 $ exceptions ->addException ($ e );
4245 }
4346 }
44-
47+
4548 if ($ exceptions ->hasExceptions ()) {
4649 throw $ exceptions ;
4750 }
48-
51+
4952 return $ responses ;
5053 }
5154
@@ -63,12 +66,12 @@ public function getName()
6366 {
6467 return 'mock ' ;
6568 }
66-
69+
6770 public function getRequests ()
6871 {
6972 return $ this ->requests ;
7073 }
71-
74+
7275 public function clear ()
7376 {
7477 $ this ->exception = null ;
You can’t perform that action at this time.
0 commit comments