@@ -110,10 +110,22 @@ public function testGetCodeResponse4()
110
110
$ this ->assertEquals ('some response ' , $ this ->responses ->getCodeResponse (123 ));
111
111
}
112
112
113
+ /**
114
+ * Test get status code only response, with custom headers.
115
+ */
116
+ public function testGetCodeResponse5 ()
117
+ {
118
+ $ this ->willBeCalledGetMediaType ('some ' , 'type ' );
119
+ $ this ->willBeCalledGetSupportedExtensions (null );
120
+ $ headers = [Responses::HEADER_CONTENT_TYPE => 'some/type ' , 'X-Custom ' => 'Custom-Header ' ];
121
+ $ this ->willBeCalledCreateResponse (null , 123 , $ headers , 'some response ' );
122
+ $ this ->assertEquals ('some response ' , $ this ->responses ->getCodeResponse (123 , ['X-Custom ' => 'Custom-Header ' ]));
123
+ }
124
+
113
125
/**
114
126
* Test response.
115
127
*/
116
- public function testContentResponse ()
128
+ public function testContentResponse1 ()
117
129
{
118
130
$ data = new stdClass ();
119
131
$ links = ['some ' => 'links ' ];
@@ -126,10 +138,28 @@ public function testContentResponse()
126
138
$ this ->assertEquals ('some response ' , $ this ->responses ->getContentResponse ($ data , 321 , $ links , $ meta ));
127
139
}
128
140
141
+ /**
142
+ * Test content response, with custom headers.
143
+ */
144
+ public function testContentResponse2 ()
145
+ {
146
+ $ data = new stdClass ();
147
+ $ links = ['some ' => 'links ' ];
148
+ $ meta = ['some ' => 'meta ' ];
149
+ $ this ->willBeCalledGetMediaType ('some ' , 'type ' );
150
+ $ this ->willBeCalledGetSupportedExtensions (null );
151
+ $ this ->willBeCalledEncoderForData ($ data , 'some json api ' , $ links , $ meta );
152
+ $ headers = [Responses::HEADER_CONTENT_TYPE => 'some/type ' , 'X-Custom ' => 'Custom-Header ' ];
153
+ $ this ->willBeCalledCreateResponse ('some json api ' , 321 , $ headers , 'some response ' );
154
+ $ this ->assertEquals ('some response ' , $ this ->responses ->getContentResponse ($ data , 321 , $ links , $ meta , [
155
+ 'X-Custom ' => 'Custom-Header ' ,
156
+ ]));
157
+ }
158
+
129
159
/**
130
160
* Test response.
131
161
*/
132
- public function testCreatedResponse ()
162
+ public function testCreatedResponse1 ()
133
163
{
134
164
$ resource = new stdClass ();
135
165
$ links = ['some ' => 'links ' ];
@@ -146,10 +176,33 @@ public function testCreatedResponse()
146
176
$ this ->assertEquals ('some response ' , $ this ->responses ->getCreatedResponse ($ resource , $ links , $ meta ));
147
177
}
148
178
179
+ /**
180
+ * Test response, with custom headers
181
+ */
182
+ public function testCreatedResponse2 ()
183
+ {
184
+ $ resource = new stdClass ();
185
+ $ links = ['some ' => 'links ' ];
186
+ $ meta = ['some ' => 'meta ' ];
187
+ $ this ->willBeCalledGetMediaType ('some ' , 'type ' );
188
+ $ this ->willBeCalledGetSupportedExtensions (null );
189
+ $ this ->willBeCalledEncoderForData ($ resource , 'some json api ' , $ links , $ meta );
190
+ $ this ->willBeCreatedResourceLocationUrl ($ resource , 'http://server.tld ' , '/resource-type/123 ' );
191
+ $ headers = [
192
+ Responses::HEADER_CONTENT_TYPE => 'some/type ' ,
193
+ Responses::HEADER_LOCATION => 'http://server.tld/resource-type/123 ' ,
194
+ 'X-Custom ' => 'Custom-Header ' ,
195
+ ];
196
+ $ this ->willBeCalledCreateResponse ('some json api ' , Responses::HTTP_CREATED , $ headers , 'some response ' );
197
+ $ this ->assertEquals ('some response ' , $ this ->responses ->getCreatedResponse ($ resource , $ links , $ meta , [
198
+ 'X-Custom ' => 'Custom-Header ' ,
199
+ ]));
200
+ }
201
+
149
202
/**
150
203
* Test response.
151
204
*/
152
- public function testMetaResponse ()
205
+ public function testMetaResponse1 ()
153
206
{
154
207
$ meta = new stdClass ();
155
208
$ this ->willBeCalledGetMediaType ('some ' , 'type ' );
@@ -160,6 +213,22 @@ public function testMetaResponse()
160
213
$ this ->assertEquals ('some response ' , $ this ->responses ->getMetaResponse ($ meta , 321 ));
161
214
}
162
215
216
+ /**
217
+ * Test response, with custom headers
218
+ */
219
+ public function testMetaResponse2 ()
220
+ {
221
+ $ meta = new stdClass ();
222
+ $ this ->willBeCalledGetMediaType ('some ' , 'type ' );
223
+ $ this ->willBeCalledGetSupportedExtensions (null );
224
+ $ this ->willBeCalledEncoderForMeta ($ meta , 'some json api ' );
225
+ $ headers = [Responses::HEADER_CONTENT_TYPE => 'some/type ' , 'X-Custom ' => 'Custom-Header ' ];
226
+ $ this ->willBeCalledCreateResponse ('some json api ' , 321 , $ headers , 'some response ' );
227
+ $ this ->assertEquals ('some response ' , $ this ->responses ->getMetaResponse ($ meta , 321 , [
228
+ 'X-Custom ' => 'Custom-Header ' ,
229
+ ]));
230
+ }
231
+
163
232
/**
164
233
* Test response.
165
234
*/
@@ -203,6 +272,22 @@ public function testErrorResponse3()
203
272
$ this ->assertEquals ('some response ' , $ this ->responses ->getErrorResponse ($ errors , 321 ));
204
273
}
205
274
275
+ /**
276
+ * Test response, with custom headers.
277
+ */
278
+ public function testErrorResponse4 ()
279
+ {
280
+ $ error = new Error ();
281
+ $ this ->willBeCalledGetMediaType ('some ' , 'type ' );
282
+ $ this ->willBeCalledGetSupportedExtensions (null );
283
+ $ this ->willBeCalledEncoderForError ($ error , 'some json api ' );
284
+ $ headers = [Responses::HEADER_CONTENT_TYPE => 'some/type ' , 'X-Custom ' => 'Custom-Header ' ];
285
+ $ this ->willBeCalledCreateResponse ('some json api ' , 321 , $ headers , 'some response ' );
286
+ $ this ->assertEquals ('some response ' , $ this ->responses ->getErrorResponse ($ error , 321 , [
287
+ 'X-Custom ' => 'Custom-Header ' ,
288
+ ]));
289
+ }
290
+
206
291
/**
207
292
* @param string $type
208
293
* @param string $subType
0 commit comments