1 | <?php |
||
24 | abstract class AbstractRequester |
||
25 | { |
||
26 | protected $method = 'get'; |
||
27 | protected $path = '/'; |
||
28 | protected $requestHeader = []; |
||
29 | protected $query = []; |
||
30 | protected $requestBody = null; |
||
31 | /** |
||
32 | * @var Schema |
||
33 | */ |
||
34 | protected $schema = null; |
||
35 | |||
36 | protected $statusExpected = 200; |
||
37 | protected $assertHeader = []; |
||
38 | |||
39 | public function __construct() |
||
42 | |||
43 | /** |
||
44 | * abstract function to be implemented by derived classes |
||
45 | * |
||
46 | * This function must be implemented by derived classes. It should process |
||
47 | * the given request and return an according response. |
||
48 | * |
||
49 | * @param RequestInterface $request |
||
50 | * @return ResponseInterface |
||
51 | */ |
||
52 | abstract protected function handleRequest(RequestInterface $request); |
||
53 | |||
54 | /** |
||
55 | * @param Schema $schema |
||
56 | * @return $this |
||
57 | */ |
||
58 | public function withSchema($schema) |
||
59 | { |
||
60 | $this->schema = $schema; |
||
61 | |||
62 | return $this; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return bool |
||
67 | */ |
||
68 | public function hasSchema() |
||
69 | { |
||
70 | return !empty($this->schema); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param string $method |
||
75 | * @return $this |
||
76 | */ |
||
77 | public function withMethod($method) |
||
83 | |||
84 | /** |
||
85 | * @param string $path |
||
86 | * @return $this |
||
87 | */ |
||
88 | public function withPath($path) |
||
94 | |||
95 | /** |
||
96 | * @param array $requestHeader |
||
97 | * @return $this |
||
98 | */ |
||
99 | public function withRequestHeader($requestHeader) |
||
110 | |||
111 | /** |
||
112 | * @param array $query |
||
113 | * @return $this |
||
114 | */ |
||
115 | public function withQuery($query) |
||
126 | |||
127 | /** |
||
128 | * @param null $requestBody |
||
129 | * @return $this |
||
130 | */ |
||
131 | public function withRequestBody($requestBody) |
||
137 | |||
138 | public function assertResponseCode($code) |
||
144 | |||
145 | public function assertHeaderContains($header, $contains) |
||
151 | |||
152 | /** |
||
153 | * @return mixed |
||
154 | * @throws Exception\DefinitionNotFoundException |
||
155 | * @throws Exception\HttpMethodNotFoundException |
||
156 | * @throws Exception\InvalidDefinitionException |
||
157 | * @throws Exception\PathNotFoundException |
||
158 | * @throws GuzzleException |
||
159 | * @throws NotMatchedException |
||
160 | * @throws StatusCodeNotMatchedException |
||
161 | */ |
||
162 | public function send() |
||
238 | } |
||
239 |