Code Duplication    Length = 46-51 lines in 3 locations

tests/Adapter/CurlAdapterTest.php 3 locations

@@ 260-305 (lines=46) @@
257
     *
258
     * @return void
259
     */
260
    public function sendCurlGetinfoFailsOnHeaderSize()
261
    {
262
        \Chadicus\FunctionRegistry::set(
263
            __NAMESPACE__,
264
            'curl_init',
265
            function () {
266
                return true;
267
            }
268
        );
269
270
        \Chadicus\FunctionRegistry::set(
271
            __NAMESPACE__,
272
            'curl_setopt_array',
273
            function ($curl, array $options) {
274
                return true;
275
            }
276
        );
277
278
        \Chadicus\FunctionRegistry::set(
279
            __NAMESPACE__,
280
            'curl_exec',
281
            function ($curl) {
282
                return "HTTP/1.1 200 OK\r\nContent-Length: 2\r\nContent-Type: application/json\r\n\n[]";
283
            }
284
        );
285
286
        \Chadicus\FunctionRegistry::set(
287
            __NAMESPACE__,
288
            'curl_error',
289
            function ($curl) {
290
                return '';
291
            }
292
        );
293
294
        \Chadicus\FunctionRegistry::set(
295
            __NAMESPACE__,
296
            'curl_getinfo',
297
            function ($curl, $option) {
298
                if ($option === CURLINFO_HEADER_SIZE) {
299
                    return false;
300
                }
301
            }
302
        );
303
304
        (new CurlAdapter())->send(new Request('not under test', 'get', [], []));
305
    }
306
307
    /**
308
     * Verify behavior when curl_getinfo return false for CURLINFO_HTTP_CODE.
@@ 317-366 (lines=50) @@
314
     *
315
     * @return void
316
     */
317
    public function sendCurlGetinfoFailsOnHttpCode()
318
    {
319
        \Chadicus\FunctionRegistry::set(
320
            __NAMESPACE__,
321
            'curl_init',
322
            function () {
323
                return true;
324
            }
325
        );
326
327
        \Chadicus\FunctionRegistry::set(
328
            __NAMESPACE__,
329
            'curl_setopt_array',
330
            function ($curl, array $options) {
331
                return true;
332
            }
333
        );
334
335
        \Chadicus\FunctionRegistry::set(
336
            __NAMESPACE__,
337
            'curl_exec',
338
            function ($curl) {
339
                return "HTTP/1.1 200 OK\r\nContent-Length: 4\r\nContent-Type: application/json\r\n\n[]";
340
            }
341
        );
342
343
        \Chadicus\FunctionRegistry::set(
344
            __NAMESPACE__,
345
            'curl_error',
346
            function ($curl) {
347
                return '';
348
            }
349
        );
350
351
        \Chadicus\FunctionRegistry::set(
352
            __NAMESPACE__,
353
            'curl_getinfo',
354
            function ($curl, $option) {
355
                if ($option === CURLINFO_HEADER_SIZE) {
356
                    return 69;
357
                }
358
359
                if ($option === CURLINFO_HTTP_CODE) {
360
                    return false;
361
                }
362
            }
363
        );
364
365
        (new CurlAdapter())->send(new Request('not under test', 'get', [], []));
366
    }
367
368
    /**
369
     * Verify behavior when json_last_error returns a value other than JSON_ERROR_NONE.
@@ 378-428 (lines=51) @@
375
     *
376
     * @return void
377
     */
378
    public function sendInvalidJsonInResult()
379
    {
380
        \Chadicus\FunctionRegistry::set(
381
            __NAMESPACE__,
382
            'curl_init',
383
            function () {
384
                return true;
385
            }
386
        );
387
388
        \Chadicus\FunctionRegistry::set(
389
            __NAMESPACE__,
390
            'curl_setopt_array',
391
            function ($curl, array $options) {
392
                return true;
393
            }
394
        );
395
396
        \Chadicus\FunctionRegistry::set(
397
            __NAMESPACE__,
398
            'curl_exec',
399
            function ($curl) {
400
                // contains syntax error
401
                return "HTTP/1.1 200 OK\r\nContent-Length: 4\r\nContent-Type: application/json\r\n\n{xx}}";
402
            }
403
        );
404
405
        \Chadicus\FunctionRegistry::set(
406
            __NAMESPACE__,
407
            'curl_error',
408
            function ($curl) {
409
                return '';
410
            }
411
        );
412
413
        \Chadicus\FunctionRegistry::set(
414
            __NAMESPACE__,
415
            'curl_getinfo',
416
            function ($curl, $option) {
417
                if ($option === CURLINFO_HEADER_SIZE) {
418
                    return 69;
419
                }
420
421
                if ($option === CURLINFO_HTTP_CODE) {
422
                    return 200;
423
                }
424
            }
425
        );
426
427
        (new CurlAdapter())->send(new Request('not under test', 'get', [], []));
428
    }
429
}
430