Completed
Push — master ( 38b697...f99019 )
by Robin
8s
created

GetByRefTest::getMockConnector()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 45
rs 8.8571
cc 1
eloc 25
nc 1
nop 0
1
<?php
2
namespace Communibase;
3
4
/**
5
 * @package Communibase
6
 * @author Kingsquare ([email protected])
7
 * @copyright Copyright (c) Kingsquare BV (http://www.kingsquare.nl)
8
 */
9
class GetByRefTest extends \PHPUnit_Framework_TestCase
10
{
11
12
    /**
13
     *
14
     * @expectedException Exception
15
     * @expectedExceptionMessage Please provide a documentReference object with a type and id
16
     */
17
    public function invalid()
18
    {
19
        $this->getMockConnector()->getByRef([]);
20
    }
21
22
    /**
23
     * @test
24
     */
25
    public function singlePathToAttribute()
26
    {
27
28
        $result = $this->getMockConnector()->getByRef([
29
            'rootDocumentEntityType' => 'Test',
30
            'rootDocumentId' => 'X',
31
            'path' => [
32
                [
33
                    'field' => 'singlePathToAttribute'
34
                ]
35
            ]
36
        ]);
37
38
        $this->assertSame('value', $result);
39
    }
40
41
    /**
42
     * @test
43
     */
44
    public function multiplePathToAttribute()
45
    {
46
47
        $result = $this->getMockConnector()->getByRef([
48
            'rootDocumentEntityType' => 'Test',
49
            'rootDocumentId' => 'X',
50
            'path' => [
51
                [
52
                    'field' => 'multiplePathToAttribute'
53
                ],
54
                [
55
                    'field' => 'field'
56
                ]
57
            ]
58
        ]);
59
60
        $this->assertSame('value', $result);
61
    }
62
63
    /**
64
     * @test
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
69
        $result = $this->getMockConnector()->getByRef([
70
            'rootDocumentEntityType' => 'Test',
71
            'rootDocumentId' => 'X',
72
            'path' => [
73
                [
74
                    'field' => 'multiplePathToAttributeDepth'
75
                ],
76
                [
77
                    'field' => 'field'
78
                ],
79
                [
80
                    'field' => 'field'
81
                ]
82
            ]
83
        ]);
84
85
        $this->assertSame('value', $result);
86
    }
87
88
    /**
89
     * @test
90
     */
91
    public function singlePathToArrayObject()
92
    {
93
94
        $result = $this->getMockConnector()->getByRef([
95
            'rootDocumentEntityType' => 'Test',
96
            'rootDocumentId' => 'X',
97
            'path' => [
98
                [
99
                    'field' => 'singlePathToArrayObject',
100
                    'objectId' => 'value'
101
                ]
102
            ]
103
        ]);
104
105
        $this->assertSame(['_id' => 'value'], $result);
106
    }
107
108
    /**
109
     * @test
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
114
        $result = $this->getMockConnector()->getByRef([
115
            'rootDocumentEntityType' => 'Test',
116
            'rootDocumentId' => 'X',
117
            'path' => [
118
                [
119
                    'field' => 'multiplePathToArrayObject',
120
                ],
121
                [
122
                    'field' => 'field',
123
                    'objectId' => 'value'
124
                ]
125
            ]
126
        ]);
127
128
        $this->assertSame(['_id' => 'value'], $result);
129
    }
130
131
    /**
132
     * @return \Communibase\Connector
133
     */
134
    protected function getMockConnector() {
135
136
        $mock = $this->getMockBuilder('Communibase\Connector')
137
            ->setMethods(['getById'])
138
            ->disableOriginalConstructor()
139
            ->getMock();
140
141
        $mock->expects($this->any())
142
            ->method('getById')
143
            ->will($this->returnValue([
144
                '_id' => '1234',
145
                'singlePathToAttribute' => 'value',
146
                'multiplePathToAttribute' => [
147
                    'field' => 'value'
148
                ],
149
                'multiplePathToAttributeDepth' => [
150
                    'field' => [
151
                        'field' => 'value'
152
                    ],
153
                ],
154
                'singlePathToArrayObject' => [
155
                    [
156
                        '_id' => 'value'
157
                    ]
158
                ],
159
                'multiplePathToArrayObject' => [
160
                    'field' => [
161
                        [
162
                            '_id' => 'value'
163
                        ]
164
                    ]
165
                ],
166
                'multiplePathToArrayObjectDepth' => [
167
                    'field' => [
168
                        'field' => [
169
                            [
170
                                '_id' => 'value'
171
                            ]
172
                        ]
173
                    ]
174
                ],
175
            ]));
176
177
        return $mock;
178
    }
179
180
}
181