ApiTest::testSuccessSend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Franjid\ApiWrapperBundle\Tests\Api;
4
5
use Franjid\ApiWrapperBundle\Api\Api;
6
use Franjid\ApiWrapperBundle\Api\ApiRequest;
7
use Franjid\ApiWrapperBundle\Api\ApiResponseInterface;
8
use GuzzleHttp\ClientInterface;
9
use GuzzleHttp\Exception\RequestException;
10
use Psr\Http\Message\ResponseInterface;
11
12
class ApiTest extends \PHPUnit_Framework_TestCase
13
{
14
    /** @var ClientInterface $client */
15
    protected $client;
16
17
    /** @var ResponseInterface $response */
18
    protected $response;
19
20
    /** @var Api $api */
21
    protected $api;
22
23
    public function setUp()
24
    {
25
        $this->client = $this->prophesize(ClientInterface::class);
26
        $this->response = $this->prophesize(ResponseInterface::class);
27
28
        $this->api = new Api($this->client->reveal());
29
    }
30
31
    public function testSuccessSend()
32
    {
33
        $apiRequest = new ApiRequest('GET', '/');
34
        $this->client
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<Psr\Http\Message\ResponseInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
            ->send($apiRequest->getRequest(), $apiRequest->getOptions())
36
            ->willReturn($this->response);
37
38
        $this->assertInstanceOf(ApiResponseInterface::class, $this->api->send($apiRequest));
39
    }
40
41
    /**
42
     * @expectedException \Franjid\ApiWrapperBundle\Api\ApiException
43
     */
44
    public function testFailSend()
45
    {
46
        $apiRequest = new ApiRequest('GET', '/');
47
        $this->client
0 ignored issues
show
Bug introduced by
The method willThrow() does not seem to exist on object<Psr\Http\Message\ResponseInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
            ->send($apiRequest->getRequest(), $apiRequest->getOptions())
49
            ->willThrow(new RequestException('Failed request', $apiRequest->getRequest()));
50
51
        $this->api->send($apiRequest);
52
    }
53
}
54