Passed
Push — master ( b091a1...a43e6f )
by Pavel
03:13
created

ClientExceptionsTest::testGuzzleException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace ScayTrase\Api\JsonRpc\Tests;
4
5
use GuzzleHttp\Exception\ServerException;
6
use GuzzleHttp\Psr7\Request;
7
use GuzzleHttp\Psr7\Uri;
8
use ScayTrase\Api\JsonRpc\JsonRpcClient;
9
use ScayTrase\Api\Rpc\Exception\RemoteCallFailedException;
10
11
class ClientExceptionsTest extends AbstractJsonRpcClientTest
12
{
13
    /**
14
     * @expectedException \InvalidArgumentException
15
     * @expectedExceptionMessage Request should be either array or single RpcRequestInterface instance
16
     */
17
    public function testInvalidArrayArgumentException()
18
    {
19
        $client = new JsonRpcClient($this->getClient(), new Uri());
20
        $client->invoke('test');
0 ignored issues
show
Documentation introduced by
'test' is of type string, but the function expects a object<ScayTrase\Api\Rpc...c\RpcRequestInterface>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
21
    }
22
23
    /**
24
     * @expectedException \ScayTrase\Api\Rpc\Exception\RemoteCallFailedException
25
     * @expectedExceptionMessage Error completing request
26
     */
27
    public function testGuzzleException()
28
    {
29
        $client = new JsonRpcClient($this->getClient(), new Uri());
30
        $exception = ServerException::create(new Request('GET', new Uri()));
31
        $request = $this->createRequestForSingleInvocation('test', [], $exception);
32
        $client->invoke($request)->getResponse($request);
33
    }
34
}
35