File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44API for "the software to mock third-party responses" to include in your application's API tests.
55  ;
66  ;
7+
8+ ## Use Proxy / Automatic Mode
9+ To automatically forward requests to the API mock there is the possibility to use a ` HandlerStack ` for ` Guzzle ` .
10+ The ` HandlerStack ` checks if a request has already been saved and if not,
11+ the request will be sent to the correct host and then the response will be cached,
12+ so that the next time a request will be sent to the API mock, and the cached response will be returned.
13+
14+ ``` php
15+ <?php
16+ //...
17+ $apiMockClient = new \GuzzleHttp\Client([/*...*/]);
18+ $apiMock = new \ApiMock\Core\ApiMock($apiMockClient);
19+ $proxyStack = new \ApiMock\Proxy\ProxyStack($apiMock);
20+
21+ $myDefaultClient = new \GuzzleHttp\Client([
22+ /*...*/
23+ 'handler' => $proxyStack,
24+ ]);
25+
26+ // Will be sent against example.org
27+ $myDefaultClient->get('https://example.org', []);
28+ // Will be sent against API Mock
29+ $myDefaultClient->get('https://example.org', []);
30+ ```
31+
32+
733## <a id =" Troubleshooting " href =" #Troubleshooting " >Troubleshooting</a >
834---
935#### I used a requestKey, but the ` ApiMock::getClientRequest() ` gets a 404/null
You can’t perform that action at this time.
0 commit comments