Skip to content

Commit 2850c46

Browse files
committed
Improve docs
1 parent dde75cc commit 2850c46

6 files changed

+36
-2
lines changed

docs/docs.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ Response constructor.
212212

213213
## Class: \donatj\MockWebServer\ResponseStack
214214

215+
ResponseStack is used to store multiple responses for a request issued by the server in order.
216+
217+
When the stack is empty, the server will return a customizable response defaulting to a 404.
218+
215219
### Method: ResponseStack->__construct
216220

217221
```php
@@ -230,6 +234,8 @@ Accepts a variable number of RequestInterface objects
230234
function getPastEndResponse()
231235
```
232236

237+
Gets the response returned when the stack is exhausted.
238+
233239
#### Returns:
234240

235241
- ***\donatj\MockWebServer\ResponseInterface***
@@ -242,12 +248,16 @@ function getPastEndResponse()
242248
function setPastEndResponse(\donatj\MockWebServer\ResponseInterface $pastEndResponse)
243249
```
244250

251+
Set the response to return when the stack is exhausted.
252+
245253
#### Parameters:
246254

247255
- ***\donatj\MockWebServer\ResponseInterface*** `$pastEndResponse`
248256

249257
## Class: \donatj\MockWebServer\ResponseByMethod
250258

259+
ResponseByMethod is used to vary the response to a request by the called HTTP Method.
260+
251261
```php
252262
<?php
253263
namespace donatj\MockWebServer;
@@ -274,7 +284,7 @@ MethodResponse constructor.
274284

275285
#### Parameters:
276286

277-
- ***\donatj\MockWebServer\ResponseInterface[]*** `$responses` - An array of responses keyed by their method.
287+
- ***\donatj\MockWebServer\ResponseInterface[]*** `$responses` - A map of responses keyed by their method.
278288
- ***\donatj\MockWebServer\ResponseInterface*** | ***null*** `$defaultResponse` - The fallthrough response to return if a response for a given
279289
method is not found. If this is not defined the server will return an HTTP 501 error.
280290

@@ -297,6 +307,8 @@ Set the Response for the Given Method
297307

298308
DelayedResponse wraps a response, causing it when called to be delayed by a specified number of microseconds.
299309

310+
This is useful for simulating slow responses and testing timeouts.
311+
300312
### Method: DelayedResponse->__construct
301313

302314
```php

src/DelayedResponse.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
/**
66
* DelayedResponse wraps a response, causing it when called to be delayed by a specified number of microseconds.
7+
*
8+
* This is useful for simulating slow responses and testing timeouts.
79
*/
810
class DelayedResponse implements InitializingResponseInterface, MultiResponseInterface {
911

src/InitializingResponseInterface.php

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace donatj\MockWebServer;
44

5+
/**
6+
* InitializingResponseInterface is used to initialize a response before headers are sent.
7+
*/
58
interface InitializingResponseInterface extends ResponseInterface {
69

710
/**

src/MultiResponseInterface.php

+5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
namespace donatj\MockWebServer;
44

5+
/**
6+
* MultiResponseInterface is used to vary the response to a request.
7+
*/
58
interface MultiResponseInterface extends ResponseInterface {
69

710
/**
11+
* Called after each request is sent
12+
*
813
* @internal
914
* @return bool
1015
*/

src/ResponseByMethod.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace donatj\MockWebServer;
44

5+
/**
6+
* ResponseByMethod is used to vary the response to a request by the called HTTP Method.
7+
*/
58
class ResponseByMethod implements ResponseInterface {
69

710
const METHOD_GET = 'GET';
@@ -22,7 +25,7 @@ class ResponseByMethod implements ResponseInterface {
2225
/**
2326
* MethodResponse constructor.
2427
*
25-
* @param ResponseInterface[] $responses An array of responses keyed by their method.
28+
* @param ResponseInterface[] $responses A map of responses keyed by their method.
2629
* @param ResponseInterface|null $defaultResponse The fallthrough response to return if a response for a given
2730
* method is not found. If this is not defined the server will return an HTTP 501 error.
2831
*/

src/ResponseStack.php

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
use donatj\MockWebServer\Exceptions\RuntimeException;
66

7+
/**
8+
* ResponseStack is used to store multiple responses for a request issued by the server in order.
9+
*
10+
* When the stack is empty, the server will return a customizable response defaulting to a 404.
11+
*/
712
class ResponseStack implements MultiResponseInterface {
813

914
private $ref;
@@ -92,13 +97,17 @@ public function getStatus( RequestInfo $request ) {
9297
}
9398

9499
/**
100+
* Gets the response returned when the stack is exhausted.
101+
*
95102
* @return \donatj\MockWebServer\ResponseInterface
96103
*/
97104
public function getPastEndResponse() {
98105
return $this->pastEndResponse;
99106
}
100107

101108
/**
109+
* Set the response to return when the stack is exhausted.
110+
*
102111
* @param \donatj\MockWebServer\ResponseInterface $pastEndResponse
103112
*/
104113
public function setPastEndResponse( ResponseInterface $pastEndResponse ) {

0 commit comments

Comments
 (0)