1: <?php
2:
3: namespace ShippoClient\Http\Request;
4:
5: use Guzzle\Http\Message\Response;
6: use Guzzle\Plugin\Mock\MockPlugin;
7: use ShippoClient\Http\Request;
8:
9: class MockCollection
10: {
11: 12: 13:
14: private static $instance = null;
15:
16: private static $container = [];
17:
18: private function __construct()
19: {
20: }
21:
22: public static function getInstance()
23: {
24: if (self::$instance !== null) {
25: return self::$instance;
26: }
27: self::$instance = new self();
28:
29: return self::$instance;
30: }
31:
32: public function has($endPoint)
33: {
34: return array_key_exists($endPoint, self::$container);
35: }
36:
37: 38: 39: 40:
41: public function getMockResponse($endPoint)
42: {
43: $response = new Response(self::$container[$endPoint]['statusCode']);
44: $response->setBody(json_encode(self::$container[$endPoint]['response']));
45: $mock = new MockPlugin();
46: $mock->addResponse($response);
47:
48: return $mock;
49: }
50:
51: public function add($path, $statusCode, $response)
52: {
53: self::$container[$path] = [
54: 'statusCode' => $statusCode,
55: 'response' => $response,
56: ];
57:
58: return $this;
59: }
60:
61: public function clear()
62: {
63: self::$container = [];
64: }
65: }
66: