1 | <?php |
||
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')); |
||
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 |