1 | <?php |
||
15 | class Juggler |
||
16 | { |
||
17 | const PARAM_REPLAYABLE = 'replayable'; |
||
18 | const PARAM_REMOVE_PROXIES = 'remove_proxies'; |
||
19 | const DEFAULT_PORT = 2525; |
||
20 | |||
21 | /** |
||
22 | * @var IHttpClient |
||
23 | */ |
||
24 | private $httpClient; |
||
25 | |||
26 | /** |
||
27 | * @var AbstractImposterBuilder |
||
28 | */ |
||
29 | private $abstractImposterBuilder; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $host; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | private $port; |
||
40 | |||
41 | /** |
||
42 | * Full URL to Juggler client |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | private $url; |
||
47 | |||
48 | /** |
||
49 | * @param string $host |
||
50 | * @param int $port |
||
51 | * @param IHttpClient $httpClient |
||
52 | */ |
||
53 | 16 | public function __construct($host, $port = self::DEFAULT_PORT, IHttpClient $httpClient = null) |
|
62 | |||
63 | /** |
||
64 | * @param string $host |
||
65 | * @param int $port |
||
66 | */ |
||
67 | 16 | private function setUrl($host, $port) |
|
71 | |||
72 | /** |
||
73 | * @return string |
||
74 | */ |
||
75 | 16 | public function getUrl() |
|
79 | |||
80 | /** |
||
81 | * @return string |
||
82 | */ |
||
83 | 1 | public function getHost() |
|
87 | |||
88 | /** |
||
89 | * @return int |
||
90 | */ |
||
91 | 1 | public function getPort() |
|
95 | |||
96 | /** |
||
97 | * @param string $path |
||
98 | * @throws \InvalidArgumentException in case contract contents are not valid JSON |
||
99 | * @throws \RuntimeException if save to filesystem failed |
||
100 | * @return Imposter |
||
101 | */ |
||
102 | 4 | public function createImposterFromFile($path) |
|
106 | |||
107 | /** |
||
108 | * @param string $path |
||
109 | * @throws MountebankException |
||
110 | * @throws \RuntimeException if file does not exist |
||
111 | * @return int Imposter port |
||
112 | */ |
||
113 | 1 | public function postImposterFromFile($path) |
|
117 | |||
118 | /** |
||
119 | * @param string $contract |
||
120 | * @throws MountebankException |
||
121 | * @return int Imposter port |
||
122 | */ |
||
123 | 1 | public function postImposterContract($contract) |
|
129 | |||
130 | /** |
||
131 | * @param int $port |
||
132 | * @param bool $replayable |
||
133 | * @param bool $remove_proxies |
||
134 | * @return HttpImposter |
||
135 | * @throws ClientException in case imposter mountebank returns is not http imposter |
||
136 | */ |
||
137 | public function getHttpImposter($port, $replayable = false, $remove_proxies = false) |
||
149 | |||
150 | /** |
||
151 | * Retrieves contract and builds Imposter |
||
152 | * |
||
153 | * @param int $port |
||
154 | * @param bool $replayable |
||
155 | * @param bool $remove_proxies |
||
156 | * @throws MountebankException |
||
157 | * @return Imposter |
||
158 | */ |
||
159 | 1 | public function getImposter($port, $replayable = false, $remove_proxies = false) |
|
163 | |||
164 | /** |
||
165 | * @param int $port |
||
166 | * @param bool $replayable |
||
167 | * @param bool $remove_proxies |
||
168 | * @throws MountebankException |
||
169 | * @return string |
||
170 | */ |
||
171 | 1 | public function getImposterContract($port, $replayable = false, $remove_proxies = false) |
|
177 | |||
178 | /** |
||
179 | * @param Imposter $imposter |
||
180 | * @return int Imposter port |
||
181 | */ |
||
182 | public function replaceImposter(Imposter $imposter) |
||
187 | |||
188 | /** |
||
189 | * @param int|Imposter $imposter Port or Imposter instance |
||
190 | * @param bool $replayable |
||
191 | * @param bool $remove_proxies |
||
192 | * |
||
193 | * @return string Imposter contract |
||
194 | * @throws MountebankException |
||
195 | */ |
||
196 | 5 | public function deleteImposter($imposter, $replayable = false, $remove_proxies = false) |
|
203 | |||
204 | /** |
||
205 | * @param int|Imposter $imposter |
||
206 | * @param bool $replayable |
||
207 | * @param bool $remove_proxies |
||
208 | * @return string|null Imposter contract or null if there was no requested imposter |
||
209 | */ |
||
210 | 2 | public function deleteImposterIfExists($imposter, $replayable = false, $remove_proxies = false) |
|
218 | |||
219 | /** |
||
220 | * @param Imposter $imposter |
||
221 | * @throws MountebankException |
||
222 | * @return int Imposter port |
||
223 | */ |
||
224 | 1 | public function postImposter(Imposter $imposter) |
|
233 | |||
234 | /** |
||
235 | * @throws MountebankException |
||
236 | */ |
||
237 | 1 | public function deleteImposters() |
|
241 | |||
242 | /** |
||
243 | * @param int $port |
||
244 | * @throws MountebankException |
||
245 | */ |
||
246 | 1 | public function removeProxies($port) |
|
251 | |||
252 | /** |
||
253 | * Retrieves imposter contract and saves it to a local filesystem |
||
254 | * |
||
255 | * @param int $port |
||
256 | * @param string $path |
||
257 | * @throws \RuntimeException if save to filesystem failed |
||
258 | */ |
||
259 | public function retrieveAndSaveContract($port, $path) |
||
263 | |||
264 | /** |
||
265 | * Saves Imposter contract to local filesystem |
||
266 | * |
||
267 | * @param Imposter $imposter |
||
268 | * @param string $path |
||
269 | * @throws \RuntimeException if save to filesystem failed |
||
270 | */ |
||
271 | 2 | public function saveContract(Imposter $imposter, $path) |
|
275 | |||
276 | /** |
||
277 | * mountebank API only supports string 'true' as boolean param value |
||
278 | * |
||
279 | * @param bool $replayable |
||
280 | * @param bool $remove_proxies |
||
281 | * |
||
282 | * @return string |
||
283 | */ |
||
284 | 7 | private function composeQueryString($replayable, $remove_proxies) |
|
291 | } |
||
292 |