Completed
Push — master ( 0708d4...99f0e4 )
by Rafał
02:36
created

GuzzleClientSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Bridge for the Content API.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace spec\SWP\Bundle\BridgeBundle\Client;
15
16
use PhpSpec\ObjectBehavior;
17
18
class GuzzleClientSpec extends ObjectBehavior
19
{
20
    function it_is_initializable()
21
    {
22
        $this->shouldHaveType('\SWP\Bundle\BridgeBundle\Client\GuzzleClient');
23
        $this->shouldImplement('\Superdesk\ContentApiSdk\Client\ClientInterface');
24
    }
25
26
    function its_method_make_call_should_make_a_generic_http_request()
27
    {
28
        $response = $this->makeCall('http://httpbin.org/status/200', array());
29
        $response->shouldHaveKey('headers');
30
        $response->shouldHaveKeyWithValue('status', 200);
31
        $response->shouldHaveKeyWithValue('body', '');
32
    }
33
34
    function its_method_make_call_should_set_correct_status_codes()
35
    {
36
        $this->makeCall('http://httpbin.org/status/404')->shouldHaveKeyWithValue('status', 404);
37
        $this->makeCall('http://httpbin.org/status/500')->shouldHaveKeyWithValue('status', 500);
38
    }
39
40
    function its_method_make_call_should_send_headers()
41
    {
42
        $headers = array(
43
            'Authorization: some authorization token',
44
            'X-Custom-Header: Blaat blaat',
45
        );
46
        $response = $this->makeCall('http://httpbin.org/headers', $headers);
47
        $response->shouldHaveKey('body');
48
49
        foreach ($headers as $header) {
50
            list($key, $value) = explode(': ', $header);
51
            $response['body']->shouldMatch(sprintf('/%s/i', $key));
52
            $response['body']->shouldMatch(sprintf('/%s/i', $value));
53
        }
54
    }
55
56
    function its_method_make_call_should_support_post_requests()
57
    {
58
        $postData = 'some random post data';
59
        $response = $this->makeCall(
60
            'http://httpbin.org/post',
61
            array(),
62
            array(),
63
            'POST',
64
            $postData
65
        );
66
        $response->shouldHaveKey('body');
67
        $response['body']->shouldMatch(sprintf('/%s/i', $postData));
68
    }
69
70
    function it_should_throw_an_exception_when_an_error_occurs()
71
    {
72
        $this->shouldThrow('\Superdesk\ContentApiSdk\Exception\ClientException')->duringMakeCall('some random url that is invalid');
73
    }
74
}
75