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 |
|
|
|
|
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 |
|
|
|
|
48
|
|
|
->send($apiRequest->getRequest(), $apiRequest->getOptions()) |
49
|
|
|
->willThrow(new RequestException('Failed request', $apiRequest->getRequest())); |
50
|
|
|
|
51
|
|
|
$this->api->send($apiRequest); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
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.