Completed
Push — master ( b91597...be19b0 )
by Mitchel
02:09
created

BunqExceptionTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 3
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B itRepresentsABunqException() 0 25 1
1
<?php
2
3
namespace Bunq\Tests\Exception;
4
5
use Bunq\Exception\BunqException;
6
use GuzzleHttp\Exception\ClientException;
7
use PHPUnit\Framework\TestCase;
8
use Prophecy\Prophecy\ObjectProphecy;
9
use Psr\Http\Message\RequestInterface;
10
use Psr\Http\Message\ResponseInterface;
11
use Psr\Http\Message\UriInterface;
12
13
final class BunqExceptionTest extends TestCase
14
{
15
    /**
16
     * @test
17
     */
18
    public function itRepresentsABunqException()
19
    {
20
        /** @var UriInterface|ObjectProphecy $uri */
21
        $uri = $this->prophesize(UriInterface::class);
22
        $uri->getPath()->willReturn('/path');
0 ignored issues
show
Bug introduced by
The method getPath does only exist in Psr\Http\Message\UriInterface, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
23
24
        /** @var RequestInterface|ObjectProphecy $request */
25
        $request  = $this->prophesize(RequestInterface::class);
26
        $request->getUri()->willReturn($uri);
0 ignored issues
show
Bug introduced by
The method getUri does only exist in Psr\Http\Message\RequestInterface, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
27
28
        /** @var ResponseInterface|ObjectProphecy $response */
29
        $response = $this->prophesize(ResponseInterface::class);
30
        $response->getBody()->willReturn('body');
0 ignored issues
show
Bug introduced by
The method getBody does only exist in Psr\Http\Message\ResponseInterface, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
31
        $response->getStatusCode()->willReturn(403);
0 ignored issues
show
Bug introduced by
The method getStatusCode does only exist in Psr\Http\Message\ResponseInterface, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
32
33
        $clientException = new ClientException('Message', $request->reveal(), $response->reveal());
0 ignored issues
show
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Psr\Http\Message\RequestInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Psr\Http\Message\ResponseInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
34
35
        $bunqException = new BunqException($clientException);
36
37
        $this->assertInstanceOf(BunqException::class, $bunqException);
38
        $this->assertInstanceOf(\Exception::class, $bunqException);
39
        $this->assertSame('Path: /path, Message: body', $bunqException->getMessage());
40
        $this->assertSame(403, $bunqException->getCode());
41
42
    }
43
}
44