|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Ivory Http Adapter package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Ivory\HttpAdapter; |
|
13
|
|
|
|
|
14
|
|
|
use Ivory\HttpAdapter\Message\InternalRequestInterface; |
|
15
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @author GeLo <[email protected]> |
|
19
|
|
|
* @author Timothée Barray <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class MockHttpAdapter extends AbstractHttpAdapter |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
private $queuedResponses = []; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
private $receivedRequests = []; |
|
32
|
|
|
|
|
33
|
9 |
|
public function reset() |
|
34
|
|
|
{ |
|
35
|
9 |
|
$this->receivedRequests = []; |
|
36
|
9 |
|
$this->queuedResponses = []; |
|
37
|
9 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return array |
|
41
|
|
|
*/ |
|
42
|
27 |
|
public function getReceivedRequests() |
|
43
|
|
|
{ |
|
44
|
27 |
|
return $this->receivedRequests; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
36 |
|
public function getQueuedResponses() |
|
51
|
|
|
{ |
|
52
|
36 |
|
return $this->queuedResponses; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param ResponseInterface $response |
|
57
|
|
|
*/ |
|
58
|
27 |
|
public function appendResponse(ResponseInterface $response) |
|
59
|
|
|
{ |
|
60
|
27 |
|
$this->queuedResponses[] = $response; |
|
61
|
27 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritdoc} |
|
65
|
|
|
*/ |
|
66
|
9 |
|
public function getName() |
|
67
|
|
|
{ |
|
68
|
9 |
|
return 'mock'; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritdoc} |
|
73
|
|
|
*/ |
|
74
|
27 |
|
protected function sendInternalRequest(InternalRequestInterface $internalRequest) |
|
75
|
|
|
{ |
|
76
|
27 |
|
if (count($this->queuedResponses) <= 0) { |
|
77
|
9 |
|
throw new \OutOfBoundsException('You must append a response in the queue before sending a request.'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
18 |
|
$this->receivedRequests[] = $internalRequest; |
|
81
|
|
|
|
|
82
|
18 |
|
return array_shift($this->queuedResponses); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|