GetByRefTest::multiplePathToArrayObject()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Communibase;
4
5
/**
6
 * @package Communibase
7
 * @author Kingsquare ([email protected])
8
 * @copyright Copyright (c) Kingsquare BV (http://www.kingsquare.nl)
9
 */
10
class GetByRefTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @expectedException Exception
14
     * @expectedExceptionMessage Please provide a documentReference object with a type and id
15
     */
16
    public function invalid()
17
    {
18
        $this->getMockConnector()->getByRef([]);
0 ignored issues
show
Bug introduced by
The method getByRef does only exist in Communibase\Connector, but not in PHPUnit_Framework_MockObject_MockObject.

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...
19
    }
20
21
    /**
22
     * @test
23
     * @throws Exception
24
     */
25 View Code Duplication
    public function singlePathToAttribute()
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...
26
    {
27
        $result = $this->getMockConnector()->getByRef([
0 ignored issues
show
Bug introduced by
The method getByRef does only exist in Communibase\Connector, but not in PHPUnit_Framework_MockObject_MockObject.

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...
28
            'rootDocumentEntityType' => 'Test',
29
            'rootDocumentId' => 'X',
30
            'path' => [
31
                [
32
                    'field' => 'singlePathToAttribute'
33
                ]
34
            ]
35
        ]);
36
37
        $this->assertSame('value', $result);
38
    }
39
40
    /**
41
     * @test
42
     * @throws Exception
43
     */
44 View Code Duplication
    public function multiplePathToAttribute()
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...
45
    {
46
        $result = $this->getMockConnector()->getByRef([
0 ignored issues
show
Bug introduced by
The method getByRef does only exist in Communibase\Connector, but not in PHPUnit_Framework_MockObject_MockObject.

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...
47
            'rootDocumentEntityType' => 'Test',
48
            'rootDocumentId' => 'X',
49
            'path' => [
50
                [
51
                    'field' => 'multiplePathToAttribute'
52
                ],
53
                [
54
                    'field' => 'field'
55
                ]
56
            ]
57
        ]);
58
59
        $this->assertSame('value', $result);
60
    }
61
62
    /**
63
     * @test
64
     * @throws Exception
65
     */
66 View Code Duplication
    public function multiplePathToAttributeDepth()
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...
67
    {
68
        $result = $this->getMockConnector()->getByRef([
0 ignored issues
show
Bug introduced by
The method getByRef does only exist in Communibase\Connector, but not in PHPUnit_Framework_MockObject_MockObject.

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...
69
            'rootDocumentEntityType' => 'Test',
70
            'rootDocumentId' => 'X',
71
            'path' => [
72
                [
73
                    'field' => 'multiplePathToAttributeDepth'
74
                ],
75
                [
76
                    'field' => 'field'
77
                ],
78
                [
79
                    'field' => 'field'
80
                ]
81
            ]
82
        ]);
83
84
        $this->assertSame('value', $result);
85
    }
86
87
    /**
88
     * @test
89
     * @throws Exception
90
     */
91
    public function singlePathToArrayObject()
92
    {
93
        $result = $this->getMockConnector()->getByRef([
0 ignored issues
show
Bug introduced by
The method getByRef does only exist in Communibase\Connector, but not in PHPUnit_Framework_MockObject_MockObject.

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...
94
            'rootDocumentEntityType' => 'Test',
95
            'rootDocumentId' => 'X',
96
            'path' => [
97
                [
98
                    'field' => 'singlePathToArrayObject',
99
                    'objectId' => 'value'
100
                ]
101
            ]
102
        ]);
103
104
        $this->assertSame(['_id' => 'value'], $result);
105
    }
106
107
    /**
108
     * @test
109
     * @throws Exception
110
     */
111 View Code Duplication
    public function multiplePathToArrayObject()
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...
112
    {
113
        $result = $this->getMockConnector()->getByRef([
0 ignored issues
show
Bug introduced by
The method getByRef does only exist in Communibase\Connector, but not in PHPUnit_Framework_MockObject_MockObject.

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...
114
            'rootDocumentEntityType' => 'Test',
115
            'rootDocumentId' => 'X',
116
            'path' => [
117
                [
118
                    'field' => 'multiplePathToArrayObject',
119
                ],
120
                [
121
                    'field' => 'field',
122
                    'objectId' => 'value'
123
                ]
124
            ]
125
        ]);
126
127
        $this->assertSame(['_id' => 'value'], $result);
128
    }
129
130
    /**
131
     * @return \PHPUnit_Framework_MockObject_MockObject|Connector
132
     */
133
    protected function getMockConnector()
134
    {
135
        $mock = $this->getMockBuilder(Connector::class)
136
            ->setMethods(['getById'])
137
            ->disableOriginalConstructor()
138
            ->getMock();
139
140
        $mock->method('getById')
141
            ->willReturn([
142
                '_id' => '1234',
143
                'singlePathToAttribute' => 'value',
144
                'multiplePathToAttribute' => [
145
                    'field' => 'value'
146
                ],
147
                'multiplePathToAttributeDepth' => [
148
                    'field' => [
149
                        'field' => 'value'
150
                    ],
151
                ],
152
                'singlePathToArrayObject' => [
153
                    [
154
                        '_id' => 'value'
155
                    ]
156
                ],
157
                'multiplePathToArrayObject' => [
158
                    'field' => [
159
                        [
160
                            '_id' => 'value'
161
                        ]
162
                    ]
163
                ],
164
                'multiplePathToArrayObjectDepth' => [
165
                    'field' => [
166
                        'field' => [
167
                            [
168
                                '_id' => 'value'
169
                            ]
170
                        ]
171
                    ]
172
                ],
173
            ]);
174
175
        return $mock;
176
    }
177
}
178