UserResourceTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Bunq\Tests\Resource;
4
5
use Bunq\BunqClient;
6
use Bunq\Resource\UserResource;
7
use PHPUnit\Framework\TestCase;
8
use Prophecy\Prophecy\ObjectProphecy;
9
10
final class UserResourceTest extends TestCase
11
{
12
    /**
13
     * @var BunqClient|ObjectProphecy
14
     */
15
    private $bunqClient;
16
17
    /**
18
     * @var UserResource
19
     */
20
    private $resource;
21
22
    public function setUp()
23
    {
24
        $this->bunqClient = $this->prophesize(BunqClient::class);
25
        $this->resource   = new UserResource($this->bunqClient->reveal());
26
    }
27
28
    /**
29
     * @test
30
     */
31
    public function itReturnsAListOfUsers()
32
    {
33
        $this->bunqClient->get('/v1/user')->willReturn(
0 ignored issues
show
Bug introduced by
The method get does only exist in Bunq\BunqClient, 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...
34
            [
35
                'Response' => [
36
                    [
37
                        'UserCompany' => [
38
                            'id' => 1,
39
                        ],
40
                    ],
41
                ],
42
            ]
43
        );
44
45
        $result = $this->resource->listUsers();
46
47
        $expectedResult = [
48
            'Response' => [
49
                [
50
                    'UserCompany' => [
51
                        'id' => 1,
52
                    ],
53
                ],
54
            ],
55
        ];
56
57
        $this->assertEquals($expectedResult, $result);
58
    }
59
60
    /**
61
     * @test
62
     */
63 View Code Duplication
    public function itReturnsASingleUser()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $this->bunqClient->get('/v1/user/1')->willReturn(
0 ignored issues
show
Bug introduced by
The method get does only exist in Bunq\BunqClient, 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...
66
            [
67
                'Response' => [
68
                    [
69
                        'UserCompany' => [
70
                            'id' => 1,
71
                        ],
72
                    ],
73
                ],
74
            ]
75
        );
76
77
        $result = $this->resource->getUser(1);
78
79
        $expectedResult = [
80
            'id' => 1,
81
        ];
82
83
        $this->assertEquals($expectedResult, $result);
84
    }
85
}
86
87