DefaultClientSpec::it_is_initializable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 5
rs 9.4285
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Updater Bundle.
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\UpdaterBundle\Client;
15
16
use PhpSpec\ObjectBehavior;
17
18
class DefaultClientSpec extends ObjectBehavior
19
{
20
    function it_is_initializable()
21
    {
22
        $this->shouldHaveType('SWP\UpdaterBundle\Client\DefaultClient');
23
        $this->shouldImplement('SWP\UpdaterBundle\Client\ClientInterface');
24
    }
25
26
    function let()
27
    {
28
    	$config = array('base_uri' => 'http://httpbin.org');
29
    	$this->beConstructedWith($config);
30
    }
31
32
    function it_should_make_a_call_to_remote_server()
33
    {
34
        $this->call('/status/200')->shouldBe('');
35
    }
36
37
    function it_should_throw_exceptions_when_an_error_occurs()
38
    {
39
        $this->shouldThrow('SWP\UpdaterBundle\Client\ClientException')->duringCall('/status/404');
40
        $this->shouldThrow('SWP\UpdaterBundle\Client\ClientException')->duringCall('/status/500');
41
    }
42
43
    function it_should_be_able_to_return_string()
44
    {
45
        $response = $this->call('/headers');
46
        $response->shouldBeString();
47
    }
48
49
    function it_should_return_full_response_as_an_array()
50
    {
51
        $response = $this->call('/headers', array(), array(), true);
52
        $response->shouldBeArray();
53
    }
54
55
    function it_should_be_able_to_return_json_format_by_default_when_full_response()
56
    {
57
        $response = $this->call('/headers', array(), array(), true);
58
        $response['body']->shouldBeString();
59
    }
60
61
    function it_should_be_able_to_return_xml_format()
62
    {
63
        $options = array(
64
            'options' => array(
65
                'Content-Type' => 'application/xml'
66
            )
67
        );
68
69
        $response = $this->call('/xml', array(), $options, true);
70
        $response['body']->shouldBeString();
71
    }
72
73
    function it_should_be_able_to_accept_query_parameters_as_string()
74
    {
75
        $arguments = array(
76
            'Server=httpbin'
77
        );
78
79
        $response = $this->call('/response-headers', $arguments, array(), true);
80
        $response['body']->shouldBeString();
81
    }
82
83
    function it_should_be_able_to_accept_query_parameters_as_array()
84
    {
85
        $arguments = array(
86
            'Server' => 'httpbin'
87
        );
88
89
        $response = $this->call('/response-headers', $arguments);
90
        $response->shouldBeString();
91
    }
92
93
    function it_should_save_the_file()
94
    {
95
        $filePath = __DIR__.'/../../../file.png';
96
        $response = $this->saveFile('http://httpbin.org/image/png', $filePath);
97
        $response->shouldBe(true);
98
    }
99
100
    function it_should_not_save_the_file()
101
    {
102
        $response = $this->saveFile('fake_url', __DIR__.'/../../../file.png');
103
        $response->shouldBe(false);
104
    }
105
}
106