|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2017 Facebook, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* You are hereby granted a non-exclusive, worldwide, royalty-free license to |
|
6
|
|
|
* use, copy, modify, and distribute this software in source code or binary |
|
7
|
|
|
* form for use in connection with the web services and APIs provided by |
|
8
|
|
|
* Facebook. |
|
9
|
|
|
* |
|
10
|
|
|
* As with any software that integrates with the Facebook platform, your use |
|
11
|
|
|
* of this software is subject to the Facebook Developer Principles and |
|
12
|
|
|
* Policies [http://developers.facebook.com/policy/]. This copyright notice |
|
13
|
|
|
* shall be included in all copies or substantial portions of the software. |
|
14
|
|
|
* |
|
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|
18
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
20
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
21
|
|
|
* DEALINGS IN THE SOFTWARE. |
|
22
|
|
|
*/ |
|
23
|
|
|
namespace Facebook\Tests; |
|
24
|
|
|
|
|
25
|
|
|
use Facebook\Application; |
|
26
|
|
|
use Facebook\Request; |
|
27
|
|
|
use Facebook\BatchRequest; |
|
28
|
|
|
use Facebook\FileUpload\File; |
|
29
|
|
|
use PHPUnit\Framework\TestCase; |
|
30
|
|
|
|
|
31
|
|
|
class BatchRequestTest extends TestCase |
|
32
|
|
|
{ |
|
33
|
|
|
const TESTING_GRAPH_VERSION = 'v1337'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var Application |
|
37
|
|
|
*/ |
|
38
|
|
|
private $app; |
|
39
|
|
|
|
|
40
|
|
|
protected function setUp() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->app = new Application('123', 'foo_secret'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testABatchRequestWillInstantiateWithTheProperProperties() |
|
46
|
|
|
{ |
|
47
|
|
|
$batchRequest = new BatchRequest($this->app, [], 'foo_token', 'v0.1337'); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertSame($this->app, $batchRequest->getApp()); |
|
50
|
|
|
$this->assertEquals('foo_token', $batchRequest->getAccessToken()); |
|
51
|
|
|
$this->assertEquals('POST', $batchRequest->getMethod()); |
|
52
|
|
|
$this->assertEquals('', $batchRequest->getEndpoint()); |
|
53
|
|
|
$this->assertEquals('v0.1337', $batchRequest->getGraphVersion()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testEmptyRequestWillFallbackToBatchDefaults() |
|
57
|
|
|
{ |
|
58
|
|
|
$request = new Request(); |
|
59
|
|
|
|
|
60
|
|
|
$this->createBatchRequest()->addFallbackDefaults($request); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertRequestContainsAppAndToken($request, $this->app, 'foo_token'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testRequestWithTokenOnlyWillFallbackToBatchDefaults() |
|
66
|
|
|
{ |
|
67
|
|
|
$request = new Request(null, 'bar_token'); |
|
68
|
|
|
|
|
69
|
|
|
$this->createBatchRequest()->addFallbackDefaults($request); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertRequestContainsAppAndToken($request, $this->app, 'bar_token'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testRequestWithAppOnlyWillFallbackToBatchDefaults() |
|
75
|
|
|
{ |
|
76
|
|
|
$customApp = new Application('1337', 'bar_secret'); |
|
77
|
|
|
$request = new Request($customApp); |
|
78
|
|
|
|
|
79
|
|
|
$this->createBatchRequest()->addFallbackDefaults($request); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertRequestContainsAppAndToken($request, $customApp, 'foo_token'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @expectedException \Facebook\Exception\SDKException |
|
86
|
|
|
*/ |
|
87
|
|
|
public function testWillThrowWhenNoThereIsNoAppFallback() |
|
88
|
|
|
{ |
|
89
|
|
|
$batchRequest = new BatchRequest(); |
|
90
|
|
|
|
|
91
|
|
|
$batchRequest->addFallbackDefaults(new Request(null, 'foo_token')); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @expectedException \Facebook\Exception\SDKException |
|
96
|
|
|
*/ |
|
97
|
|
|
public function testWillThrowWhenNoThereIsNoAccessTokenFallback() |
|
98
|
|
|
{ |
|
99
|
|
|
$request = new BatchRequest(); |
|
100
|
|
|
|
|
101
|
|
|
$request->addFallbackDefaults(new Request($this->app)); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @expectedException \InvalidArgumentException |
|
106
|
|
|
*/ |
|
107
|
|
|
public function testAnInvalidTypeGivenToAddWillThrow() |
|
108
|
|
|
{ |
|
109
|
|
|
$request = new BatchRequest(); |
|
110
|
|
|
|
|
111
|
|
|
$request->add('foo'); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function testAddingRequestsWillBeFormattedInAnArrayProperly() |
|
115
|
|
|
{ |
|
116
|
|
|
$requests = [ |
|
117
|
|
|
null => new Request(null, null, 'GET', '/foo'), |
|
118
|
|
|
'my-second-request' => new Request(null, null, 'POST', '/bar', ['foo' => 'bar']), |
|
119
|
|
|
'my-third-request' => new Request(null, null, 'DELETE', '/baz') |
|
120
|
|
|
]; |
|
121
|
|
|
|
|
122
|
|
|
$batchRequest = $this->createBatchRequest(); |
|
123
|
|
|
$batchRequest->add($requests[null]); |
|
124
|
|
|
$batchRequest->add($requests['my-second-request'], 'my-second-request'); |
|
125
|
|
|
$batchRequest->add($requests['my-third-request'], 'my-third-request'); |
|
126
|
|
|
|
|
127
|
|
|
$formattedRequests = $batchRequest->getRequests(); |
|
128
|
|
|
|
|
129
|
|
|
$this->assertRequestsMatch($requests, $formattedRequests); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
View Code Duplication |
public function testANumericArrayOfRequestsCanBeAdded() |
|
|
|
|
|
|
133
|
|
|
{ |
|
134
|
|
|
$requests = [ |
|
135
|
|
|
new Request(null, null, 'GET', '/foo'), |
|
136
|
|
|
new Request(null, null, 'POST', '/bar', ['foo' => 'bar']), |
|
137
|
|
|
new Request(null, null, 'DELETE', '/baz'), |
|
138
|
|
|
]; |
|
139
|
|
|
|
|
140
|
|
|
$formattedRequests = $this->createBatchRequestWithRequests($requests)->getRequests(); |
|
141
|
|
|
|
|
142
|
|
|
$this->assertRequestsMatch($requests, $formattedRequests); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
View Code Duplication |
public function testAnAssociativeArrayOfRequestsCanBeAdded() |
|
|
|
|
|
|
146
|
|
|
{ |
|
147
|
|
|
$requests = [ |
|
148
|
|
|
'req-one' => new Request(null, null, 'GET', '/foo'), |
|
149
|
|
|
'req-two' => new Request(null, null, 'POST', '/bar', ['foo' => 'bar']), |
|
150
|
|
|
'req-three' => new Request(null, null, 'DELETE', '/baz'), |
|
151
|
|
|
]; |
|
152
|
|
|
|
|
153
|
|
|
$formattedRequests = $this->createBatchRequestWithRequests($requests)->getRequests(); |
|
154
|
|
|
|
|
155
|
|
|
$this->assertRequestsMatch($requests, $formattedRequests); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function testRequestsCanBeInjectedIntoConstructor() |
|
159
|
|
|
{ |
|
160
|
|
|
$requests = [ |
|
161
|
|
|
new Request(null, null, 'GET', '/foo'), |
|
162
|
|
|
new Request(null, null, 'POST', '/bar', ['foo' => 'bar']), |
|
163
|
|
|
new Request(null, null, 'DELETE', '/baz'), |
|
164
|
|
|
]; |
|
165
|
|
|
|
|
166
|
|
|
$batchRequest = new BatchRequest($this->app, $requests, 'foo_token'); |
|
167
|
|
|
$formattedRequests = $batchRequest->getRequests(); |
|
168
|
|
|
|
|
169
|
|
|
$this->assertRequestsMatch($requests, $formattedRequests); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @expectedException \Facebook\Exception\SDKException |
|
174
|
|
|
*/ |
|
175
|
|
|
public function testAZeroRequestCountWithThrow() |
|
176
|
|
|
{ |
|
177
|
|
|
$batchRequest = new BatchRequest($this->app, [], 'foo_token'); |
|
178
|
|
|
|
|
179
|
|
|
$batchRequest->validateBatchRequestCount(); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @expectedException \Facebook\Exception\SDKException |
|
184
|
|
|
*/ |
|
185
|
|
|
public function testMoreThanFiftyRequestsWillThrow() |
|
186
|
|
|
{ |
|
187
|
|
|
$batchRequest = $this->createBatchRequest(); |
|
188
|
|
|
|
|
189
|
|
|
$this->createAndAppendRequestsTo($batchRequest, 51); |
|
190
|
|
|
|
|
191
|
|
|
$batchRequest->validateBatchRequestCount(); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
public function testLessOrEqualThanFiftyRequestsWillNotThrow() |
|
195
|
|
|
{ |
|
196
|
|
|
$batchRequest = $this->createBatchRequest(); |
|
197
|
|
|
|
|
198
|
|
|
$this->createAndAppendRequestsTo($batchRequest, 50); |
|
199
|
|
|
|
|
200
|
|
|
$batchRequest->validateBatchRequestCount(); |
|
201
|
|
|
|
|
202
|
|
|
$this->assertTrue(true); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @dataProvider requestsAndExpectedResponsesProvider |
|
207
|
|
|
* |
|
208
|
|
|
* @param mixed $request |
|
209
|
|
|
* @param mixed $expectedArray |
|
210
|
|
|
*/ |
|
211
|
|
|
public function testBatchRequestEntitiesProperlyGetConvertedToAnArray($request, $expectedArray) |
|
212
|
|
|
{ |
|
213
|
|
|
$batchRequest = $this->createBatchRequest(); |
|
214
|
|
|
$batchRequest->add($request, 'foo_name'); |
|
215
|
|
|
|
|
216
|
|
|
$requests = $batchRequest->getRequests(); |
|
217
|
|
|
$batchRequestArray = $batchRequest->requestEntityToBatchArray($requests[0]['request'], $requests[0]['name']); |
|
218
|
|
|
|
|
219
|
|
|
$this->assertEquals($expectedArray, $batchRequestArray); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
public function requestsAndExpectedResponsesProvider() |
|
223
|
|
|
{ |
|
224
|
|
|
$headers = $this->defaultHeaders(); |
|
225
|
|
|
|
|
226
|
|
|
return [ |
|
227
|
|
|
[ |
|
228
|
|
|
new Request(null, null, 'GET', '/foo', ['foo' => 'bar']), |
|
229
|
|
|
[ |
|
230
|
|
|
'headers' => $headers, |
|
231
|
|
|
'method' => 'GET', |
|
232
|
|
|
'relative_url' => '/foo?foo=bar&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9', |
|
233
|
|
|
'name' => 'foo_name', |
|
234
|
|
|
], |
|
235
|
|
|
], |
|
236
|
|
|
[ |
|
237
|
|
|
new Request(null, null, 'POST', '/bar', ['bar' => 'baz']), |
|
238
|
|
|
[ |
|
239
|
|
|
'headers' => $headers, |
|
240
|
|
|
'method' => 'POST', |
|
241
|
|
|
'relative_url' => '/bar', |
|
242
|
|
|
'body' => 'bar=baz&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9', |
|
243
|
|
|
'name' => 'foo_name', |
|
244
|
|
|
], |
|
245
|
|
|
], |
|
246
|
|
|
[ |
|
247
|
|
|
new Request(null, null, 'DELETE', '/bar'), |
|
248
|
|
|
[ |
|
249
|
|
|
'headers' => $headers, |
|
250
|
|
|
'method' => 'DELETE', |
|
251
|
|
|
'relative_url' => '/bar?access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9', |
|
252
|
|
|
'name' => 'foo_name', |
|
253
|
|
|
], |
|
254
|
|
|
], |
|
255
|
|
|
]; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
public function testBatchRequestsWithFilesGetConvertedToAnArray() |
|
259
|
|
|
{ |
|
260
|
|
|
$request = new Request(null, null, 'POST', '/bar', [ |
|
261
|
|
|
'message' => 'foobar', |
|
262
|
|
|
'source' => new File(__DIR__ . '/foo.txt'), |
|
263
|
|
|
]); |
|
264
|
|
|
|
|
265
|
|
|
$batchRequest = $this->createBatchRequest(); |
|
266
|
|
|
$batchRequest->add($request, 'foo_name'); |
|
267
|
|
|
|
|
268
|
|
|
$requests = $batchRequest->getRequests(); |
|
269
|
|
|
|
|
270
|
|
|
$attachedFiles = $requests[0]['attached_files']; |
|
271
|
|
|
|
|
272
|
|
|
$batchRequestArray = $batchRequest->requestEntityToBatchArray( |
|
273
|
|
|
$requests[0]['request'], |
|
274
|
|
|
$requests[0]['name'], |
|
275
|
|
|
$attachedFiles |
|
276
|
|
|
); |
|
277
|
|
|
|
|
278
|
|
|
$this->assertEquals([ |
|
279
|
|
|
'headers' => $this->defaultHeaders(), |
|
280
|
|
|
'method' => 'POST', |
|
281
|
|
|
'relative_url' => '/bar', |
|
282
|
|
|
'body' => 'message=foobar&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9', |
|
283
|
|
|
'name' => 'foo_name', |
|
284
|
|
|
'attached_files' => $attachedFiles, |
|
285
|
|
|
], $batchRequestArray); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
public function testBatchRequestsWithOptionsGetConvertedToAnArray() |
|
289
|
|
|
{ |
|
290
|
|
|
$request = new Request(null, null, 'GET', '/bar', [], null, self::TESTING_GRAPH_VERSION); |
|
291
|
|
|
$batchRequest = $this->createBatchRequest(); |
|
292
|
|
|
$batchRequest->add($request, [ |
|
293
|
|
|
'name' => 'foo_name', |
|
294
|
|
|
'omit_response_on_success' => false, |
|
295
|
|
|
]); |
|
296
|
|
|
|
|
297
|
|
|
$requests = $batchRequest->getRequests(); |
|
298
|
|
|
|
|
299
|
|
|
$options = $requests[0]['options']; |
|
300
|
|
|
$options['name'] = $requests[0]['name']; |
|
301
|
|
|
|
|
302
|
|
|
$batchRequestArray = $batchRequest->requestEntityToBatchArray($requests[0]['request'], $options); |
|
303
|
|
|
|
|
304
|
|
|
$this->assertEquals([ |
|
305
|
|
|
'headers' => $this->defaultHeaders(), |
|
306
|
|
|
'method' => 'GET', |
|
307
|
|
|
'relative_url' => '/' . $batchRequest->getGraphVersion() . '/bar?access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9', |
|
308
|
|
|
'name' => 'foo_name', |
|
309
|
|
|
'omit_response_on_success' => false, |
|
310
|
|
|
], $batchRequestArray); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
public function testPreppingABatchRequestProperlySetsThePostParams() |
|
314
|
|
|
{ |
|
315
|
|
|
$batchRequest = $this->createBatchRequest(); |
|
316
|
|
|
$batchRequest->add(new Request(null, 'bar_token', 'GET', '/foo'), 'foo_name'); |
|
317
|
|
|
$batchRequest->add(new Request(null, null, 'POST', '/bar', ['foo' => 'bar'])); |
|
318
|
|
|
$batchRequest->prepareRequestsForBatch(); |
|
319
|
|
|
|
|
320
|
|
|
$params = $batchRequest->getParams(); |
|
321
|
|
|
|
|
322
|
|
|
$expectedHeaders = json_encode($this->defaultHeaders()); |
|
323
|
|
|
$expectedBatchParams = [ |
|
324
|
|
|
'batch' => '[{"headers":' . $expectedHeaders . ',"method":"GET","relative_url":"\\/foo?access_token=bar_token&appsecret_proof=2ceec40b7b9fd7d38fff1767b766bcc6b1f9feb378febac4612c156e6a8354bd","name":"foo_name"},' |
|
325
|
|
|
. '{"headers":' . $expectedHeaders . ',"method":"POST","relative_url":"\\/bar","body":"foo=bar&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9"}]', |
|
326
|
|
|
'include_headers' => true, |
|
327
|
|
|
'access_token' => 'foo_token', |
|
328
|
|
|
'appsecret_proof' => 'df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9', |
|
329
|
|
|
]; |
|
330
|
|
|
$this->assertEquals($expectedBatchParams, $params); |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
public function testPreppingABatchRequestProperlyMovesTheFiles() |
|
334
|
|
|
{ |
|
335
|
|
|
$batchRequest = $this->createBatchRequest(); |
|
336
|
|
|
$batchRequest->add(new Request(null, 'bar_token', 'GET', '/foo'), 'foo_name'); |
|
337
|
|
|
$batchRequest->add(new Request(null, null, 'POST', '/me/photos', [ |
|
338
|
|
|
'message' => 'foobar', |
|
339
|
|
|
'source' => new File(__DIR__ . '/foo.txt'), |
|
340
|
|
|
])); |
|
341
|
|
|
$batchRequest->prepareRequestsForBatch(); |
|
342
|
|
|
|
|
343
|
|
|
$params = $batchRequest->getParams(); |
|
344
|
|
|
$files = $batchRequest->getFiles(); |
|
345
|
|
|
|
|
346
|
|
|
$attachedFiles = implode(',', array_keys($files)); |
|
347
|
|
|
|
|
348
|
|
|
$expectedHeaders = json_encode($this->defaultHeaders()); |
|
349
|
|
|
$expectedBatchParams = [ |
|
350
|
|
|
'batch' => '[{"headers":' . $expectedHeaders . ',"method":"GET","relative_url":"\\/foo?access_token=bar_token&appsecret_proof=2ceec40b7b9fd7d38fff1767b766bcc6b1f9feb378febac4612c156e6a8354bd","name":"foo_name"},' |
|
351
|
|
|
. '{"headers":' . $expectedHeaders . ',"method":"POST","relative_url":"\\/me\\/photos","body":"message=foobar&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9","attached_files":"' . $attachedFiles . '"}]', |
|
352
|
|
|
'include_headers' => true, |
|
353
|
|
|
'access_token' => 'foo_token', |
|
354
|
|
|
'appsecret_proof' => 'df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9', |
|
355
|
|
|
]; |
|
356
|
|
|
$this->assertEquals($expectedBatchParams, $params); |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
public function testPreppingABatchRequestWithOptionsProperlySetsThePostParams() |
|
360
|
|
|
{ |
|
361
|
|
|
$batchRequest = $this->createBatchRequest(); |
|
362
|
|
|
$batchRequest->add(new Request(null, null, 'GET', '/foo', [], null, self::TESTING_GRAPH_VERSION), [ |
|
363
|
|
|
'name' => 'foo_name', |
|
364
|
|
|
'omit_response_on_success' => false, |
|
365
|
|
|
]); |
|
366
|
|
|
|
|
367
|
|
|
$batchRequest->prepareRequestsForBatch(); |
|
368
|
|
|
$params = $batchRequest->getParams(); |
|
369
|
|
|
|
|
370
|
|
|
$expectedHeaders = json_encode($this->defaultHeaders()); |
|
371
|
|
|
$version = $batchRequest->getGraphVersion(); |
|
372
|
|
|
|
|
373
|
|
|
$expectedBatchParams = [ |
|
374
|
|
|
'batch' => '[{"headers":' . $expectedHeaders . ',"method":"GET","relative_url":"\\/' . $version . '\\/foo?access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9",' |
|
375
|
|
|
. '"name":"foo_name","omit_response_on_success":false}]', |
|
376
|
|
|
'include_headers' => true, |
|
377
|
|
|
'access_token' => 'foo_token', |
|
378
|
|
|
'appsecret_proof' => 'df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9', |
|
379
|
|
|
]; |
|
380
|
|
|
$this->assertEquals($expectedBatchParams, $params); |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
private function assertRequestContainsAppAndToken(Request $request, Application $expectedApp, $expectedToken) |
|
384
|
|
|
{ |
|
385
|
|
|
$app = $request->getApp(); |
|
386
|
|
|
$token = $request->getAccessToken(); |
|
387
|
|
|
|
|
388
|
|
|
$this->assertSame($expectedApp, $app); |
|
389
|
|
|
$this->assertEquals($expectedToken, $token); |
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
private function defaultHeaders() |
|
393
|
|
|
{ |
|
394
|
|
|
$headers = []; |
|
395
|
|
|
foreach (Request::getDefaultHeaders() as $name => $value) { |
|
396
|
|
|
$headers[] = $name . ': ' . $value; |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
return $headers; |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
private function createAndAppendRequestsTo(BatchRequest $batchRequest, $number) |
|
403
|
|
|
{ |
|
404
|
|
|
for ($i = 0; $i < $number; $i++) { |
|
405
|
|
|
$batchRequest->add(new Request()); |
|
406
|
|
|
} |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
private function createBatchRequest() |
|
410
|
|
|
{ |
|
411
|
|
|
return new BatchRequest($this->app, [], 'foo_token', self::TESTING_GRAPH_VERSION); |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
private function createBatchRequestWithRequests(array $requests) |
|
415
|
|
|
{ |
|
416
|
|
|
$batchRequest = $this->createBatchRequest(); |
|
417
|
|
|
$batchRequest->add($requests); |
|
418
|
|
|
|
|
419
|
|
|
return $batchRequest; |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
private function assertRequestsMatch($requests, $formattedRequests) |
|
423
|
|
|
{ |
|
424
|
|
|
$expectedRequests = []; |
|
425
|
|
|
foreach ($requests as $name => $request) { |
|
426
|
|
|
$expectedRequests[] = [ |
|
427
|
|
|
'name' => $name, |
|
428
|
|
|
'request' => $request, |
|
429
|
|
|
'attached_files' => null, |
|
430
|
|
|
'options' => [], |
|
431
|
|
|
]; |
|
432
|
|
|
} |
|
433
|
|
|
$this->assertEquals($expectedRequests, $formattedRequests); |
|
434
|
|
|
} |
|
435
|
|
|
} |
|
436
|
|
|
|