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

GuzzleApiClientSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 54
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 18 1
A it_is_initializable() 0 5 1
A it_should_get_and_set_default_options() 0 5 1
A it_should_add_default_options() 0 7 1
A it_should_add_default_options_when_making_a_call() 0 12 1
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
use Prophecy\Argument;
18
use Superdesk\ContentApiSdk\Api\Request;
19
use Superdesk\ContentApiSdk\Api\Authentication\OAuthPasswordAuthentication;
20
use Superdesk\ContentApiSdk\Client\ClientInterface;
21
22
class GuzzleApiClientSpec extends ObjectBehavior
23
{
24
    function let(
25
        ClientInterface $client,
26
        OAuthPasswordAuthentication $authentication,
27
        Request $request
28
    ) {
29
        $this->beConstructedWith($client, $authentication);
30
31
        $baseUrl = 'http://httpbin.org/';
32
        $fullUrl = sprintf('%s/%s', $baseUrl, 'status/200');
33
        $headers = array('Accept' => 'application/json');
34
        $newHeaders = array('Accept' => 'application/json', 'Authorization' => 'OAuth2 some_access_token');
35
        $request->getBaseUrl()->willReturn($baseUrl);
36
        $request->getFullUrl()->willReturn($fullUrl);
37
        $request->getHeaders()->willReturn($headers);
38
        $request->setHeaders($newHeaders)->willReturn($request);
39
        $authentication->setBaseUrl($baseUrl)->willReturn($authentication);
40
        $authentication->getAccessToken()->willReturn('some_access_token');
41
    }
42
43
    function it_is_initializable()
44
    {
45
        $this->shouldHaveType('\SWP\Bundle\BridgeBundle\Client\GuzzleApiClient');
46
        $this->shouldImplement('\Superdesk\ContentApiSdk\Client\ApiClientInterface');
47
    }
48
49
    function it_should_get_and_set_default_options()
50
    {
51
        $defaultOptions = array('some_option_key' => 'some_option_value');
52
        $this->setOptions($defaultOptions)->getOptions()->shouldReturn($defaultOptions);
53
    }
54
55
    function it_should_add_default_options()
56
    {
57
        $defaultOptions = array('headers' => array('User-Agent' => 'guzzle_api_spec_test'));
58
        $fakeRequestOptions = array('some_options' => 'some_value');
59
        $this->setOptions($defaultOptions);
60
        $this->addDefaultOptions($fakeRequestOptions)->shouldReturn(array_merge($fakeRequestOptions, $defaultOptions));
61
    }
62
63
    function it_should_add_default_options_when_making_a_call($client, $request)
64
    {
65
        $options = array('headers' => array('User-Agent' => 'guzzle_api_spec_test'));
0 ignored issues
show
Unused Code introduced by
$options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
66
        $request->getOptions()->shouldBeCalled()->willReturn(array());
67
        $request->setOptions(Argument::type('array'))->shouldBeCalled();
68
        $client->makeCall(
69
            $request->getWrappedObject()->getFullUrl(),
70
            $request->getWrappedObject()->getHeaders(),
71
            array()
72
        )->shouldBeCalled()->willReturn(array('headers' => array(), 'status' => 200, 'body' => '{"pubstatus": "usable", "_links": {"parent": {"href": "/", "title": "home"}, "collection": {"href": "items", "title": "items"}, "self": {"href": "items/tag:example.com,0001:newsml_BRE9A607", "title": "Item"}}, "body_text": "Andromeda and Milky Way will collide in about 2 billion years", "type": "text", "language": "en", "versioncreated": "2015-03-09T16:32:23+0000", "uri": "http://api.master.dev.superdesk.org/items/tag%3Aexample.com%2C0001%3Anewsml_BRE9A607", "version": "2", "headline": "Andromeda on a collision course"}'));
73
        $this->makeApiCall($request);
74
    }
75
}
76