1 | <?php |
||
8 | abstract class Imposter implements \JsonSerializable |
||
9 | { |
||
10 | const PROTOCOL_HTTPS = 'https'; |
||
11 | const PROTOCOL_HTTP = 'http'; |
||
12 | const PROTOCOL_TCP = 'tcp'; |
||
13 | const PROTOCOL_SMTP = 'smtp'; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $protocol; |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $requests; |
||
24 | |||
25 | /** |
||
26 | * @var int|null |
||
27 | */ |
||
28 | private $port; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $name; |
||
34 | |||
35 | /** |
||
36 | * @param int|null $port |
||
37 | * @param array $requests |
||
38 | */ |
||
39 | 23 | public function __construct($port = null, array $requests = []) |
|
40 | { |
||
41 | 23 | if (null !== $port) { |
|
42 | 5 | $this->setPort($port); |
|
43 | 5 | } |
|
44 | |||
45 | 23 | $this->setRequests($requests); |
|
46 | 23 | } |
|
47 | |||
48 | /** |
||
49 | * @param array $requests |
||
50 | */ |
||
51 | 23 | private function setRequests(array $requests) |
|
55 | |||
56 | /** |
||
57 | * @return bool |
||
58 | */ |
||
59 | 8 | public function hasRequests() |
|
63 | |||
64 | /** |
||
65 | * @return array |
||
66 | */ |
||
67 | public function getRequests() |
||
71 | |||
72 | /** |
||
73 | * @param array|callable $criteria |
||
74 | * @param int $exactly Expect exactly n occurrences |
||
75 | * @return bool |
||
76 | * @throws NotFoundException |
||
77 | */ |
||
78 | 1 | public function hasRequestsByCriteria($criteria, $exactly = null) |
|
87 | |||
88 | /** |
||
89 | * @param array|callable $criteria |
||
90 | * @return int |
||
91 | */ |
||
92 | 1 | public function countRequestsByCriteria($criteria) |
|
100 | |||
101 | /** |
||
102 | * @param array|callable $criteria |
||
103 | * @return array[] |
||
104 | * @throws NotFoundException |
||
105 | * @throws \InvalidArgumentException |
||
106 | */ |
||
107 | 3 | public function findRequests($criteria) |
|
128 | |||
129 | /** |
||
130 | * @param array $criteria |
||
131 | * @return array |
||
132 | */ |
||
133 | 2 | private function findRequestsWithSubarray($criteria) |
|
144 | |||
145 | /** |
||
146 | * @param callback $callback |
||
147 | * @return array |
||
148 | */ |
||
149 | 1 | private function findRequestsWithCallable($callback) |
|
160 | |||
161 | /** |
||
162 | * @return int|null |
||
163 | */ |
||
164 | 11 | public function getPort() |
|
168 | |||
169 | /** |
||
170 | * @param int $port |
||
171 | */ |
||
172 | 6 | public function setPort($port) |
|
176 | |||
177 | /** |
||
178 | * @return string |
||
179 | */ |
||
180 | 10 | public function getProtocol() |
|
184 | |||
185 | /** |
||
186 | * @return bool |
||
187 | */ |
||
188 | 1 | public function hasName() |
|
192 | |||
193 | /** |
||
194 | * @return string|null |
||
195 | */ |
||
196 | 11 | public function getName() |
|
200 | |||
201 | /** |
||
202 | * @param string $name |
||
203 | */ |
||
204 | 5 | public function setName($name) |
|
208 | |||
209 | /** |
||
210 | * @return bool |
||
211 | */ |
||
212 | 1 | public function hasPort() |
|
216 | } |
||
217 |