1 | <?php |
||
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 |