GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 48aa34...e9e817 )
by Mario
29:19 queued 01:50
created

testMapFormsToDataWithoutValidFieldDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 63
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 63
rs 9.4347
cc 1
eloc 44
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Netgen\Bundle\InformationCollectionBundle\Tests\Form\DataMapper;
4
5
use eZ\Publish\Core\FieldType\TextLine\Value as TextLineValue;
6
use eZ\Publish\Core\Repository\Values\ContentType\ContentType;
7
use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition;
8
use Netgen\Bundle\EzFormsBundle\Form\DataWrapper;
9
use Netgen\Bundle\InformationCollectionBundle\Form\DataMapper\InformationCollectionMapper;
10
use Netgen\Bundle\InformationCollectionBundle\Form\Payload\InformationCollectionStruct;
11
use PHPUnit\Framework\TestCase;
12
13
class InformationCollectionMapperTest extends TestCase
14
{
15
    /**
16
     * @var InformationCollectionMapper
17
     */
18
    private $mapper;
19
20
    /**
21
     * @var \PHPUnit_Framework_MockObject_MockObject
22
     */
23
    private $registry;
24
25
    /**
26
     * @var \PHPUnit_Framework_MockObject_MockObject
27
     */
28
    private $handler;
29
30
    /**
31
     * @var \PHPUnit_Framework_MockObject_MockObject
32
     */
33
    private $propertyAccessor;
34
35
    protected function setUp()
36
    {
37
        $this->propertyAccessor = $this->getMockBuilder('Symfony\Component\PropertyAccess\PropertyAccessorInterface')
38
            ->disableOriginalConstructor()
39
            ->setMethods(array())
40
            ->getMock();
41
42
        $this->registry = $this->getMockBuilder('Netgen\Bundle\EzFormsBundle\Form\FieldTypeHandlerRegistry')
43
            ->disableOriginalConstructor()
44
            ->setMethods(array())
45
            ->getMock();
46
47
        $this->handler = $this->getMockBuilder('Netgen\Bundle\EzFormsBundle\Form\FieldTypeHandlerInterface')
48
            ->disableOriginalConstructor()
49
            ->setMethods(array())
50
            ->getMock();
51
52
        $this->mapper = new InformationCollectionMapper($this->registry, $this->propertyAccessor);
53
    }
54
55
    public function testInstanceOfDataMapper()
56
    {
57
        $this->assertInstanceOf('\Netgen\Bundle\EzFormsBundle\Form\DataMapper', $this->mapper);
58
    }
59
60
    public function testMapFormsToData()
61
    {
62
        $contentType = new ContentType(
63
            array(
64
                'id' => 123,
65
                'fieldDefinitions' => array(
66
                    new FieldDefinition(
67
                        array(
68
                            'id' => 'id',
69
                            'identifier' => 'name',
70
                            'fieldTypeIdentifier' => 'eztext',
71
                            'defaultValue' => new TextLineValue('Some name'),
72
                        )
73
                    ),
74
                ),
75
            )
76
        );
77
78
        $this->registry->expects($this->once())
79
            ->method('get')
80
            ->with('eztext')
81
            ->will($this->returnValue($this->handler));
82
83
        $this->handler->expects($this->once())
84
            ->method('convertFieldValueFromForm')
85
            ->willReturn(new TextLineValue('Some name'));
86
87
        $infoStruct = new InformationCollectionStruct();
88
        $data = new DataWrapper($infoStruct, $contentType);
89
90
        $config = $this->getMockBuilder('Symfony\Component\Form\FormConfigBuilder')
91
            ->disableOriginalConstructor()
92
            ->setMethods(array('getMapped'))
93
            ->getMock();
94
95
        $config->expects($this->once())
96
            ->willReturn(true)
97
            ->method('getMapped');
98
99
        $propertyPath = $this->getMockBuilder('Symfony\Component\PropertyAccess\PropertyPathInterface')
100
            ->disableOriginalConstructor()
101
            ->setMethods(array('__toString'))
102
            ->getMockForAbstractClass();
103
104
        $propertyPath->expects($this->once())
105
            ->willReturn('name')
106
            ->method('__toString');
107
108
        $form = $this->getForm();
109
110
        $form->expects($this->once())
111
            ->willReturn(true)
112
            ->method('isSubmitted');
113
114
        $form->expects($this->once())
115
            ->willReturn(true)
116
            ->method('isSynchronized');
117
118
        $form->expects($this->once())
119
            ->willReturn(false)
120
            ->method('isDisabled');
121
122
        $form->expects($this->once())
123
            ->willReturn('Some name')
124
            ->method('getData');
125
126
        $form->expects($this->once())
127
            ->willReturn($config)
128
            ->method('getConfig');
129
130
        $form->expects($this->once())
131
            ->willReturn($propertyPath)
132
            ->method('getPropertyPath');
133
134
        $this->mapper->mapFormsToData(array($form), $data);
135
    }
136
137
    /**
138
     * @expectedException \RuntimeException
139
     */
140
    public function testMapFormsToDataWithoutValidFieldDefinition()
141
    {
142
        $contentType = new ContentType(
143
            array(
144
                'id' => 123,
145
                'fieldDefinitions' => array(
146
                    new FieldDefinition(
147
                        array(
148
                            'id' => 'id',
149
                            'identifier' => 'test',
150
                            'fieldTypeIdentifier' => 'eztext',
151
                            'defaultValue' => new TextLineValue('Some name'),
152
                        )
153
                    ),
154
                ),
155
            )
156
        );
157
158
        $infoStruct = new InformationCollectionStruct();
159
        $data = new DataWrapper($infoStruct, $contentType);
160
161
        $config = $this->getMockBuilder('Symfony\Component\Form\FormConfigBuilder')
162
            ->disableOriginalConstructor()
163
            ->setMethods(array('getMapped'))
164
            ->getMock();
165
166
        $config->expects($this->once())
167
            ->willReturn(true)
168
            ->method('getMapped');
169
170
        $propertyPath = $this->getMockBuilder('Symfony\Component\PropertyAccess\PropertyPathInterface')
171
            ->disableOriginalConstructor()
172
            ->setMethods(array('__toString'))
173
            ->getMockForAbstractClass();
174
175
        $propertyPath->expects($this->once())
176
            ->willReturn('name')
177
            ->method('__toString');
178
179
        $form = $this->getForm();
180
181
        $form->expects($this->once())
182
            ->willReturn(true)
183
            ->method('isSubmitted');
184
185
        $form->expects($this->once())
186
            ->willReturn(true)
187
            ->method('isSynchronized');
188
189
        $form->expects($this->once())
190
            ->willReturn(false)
191
            ->method('isDisabled');
192
193
        $form->expects($this->once())
194
            ->willReturn($config)
195
            ->method('getConfig');
196
197
        $form->expects($this->once())
198
            ->willReturn($propertyPath)
199
            ->method('getPropertyPath');
200
201
        $this->mapper->mapFormsToData(array($form), $data);
202
    }
203
204
    public function testMapDataToForms()
205
    {
206
        $contentType = new ContentType(
207
            array(
208
                'id' => 123,
209
                'fieldDefinitions' => array(
210
                    new FieldDefinition(
211
                        array(
212
                            'id' => 'id',
213
                            'identifier' => 'name',
214
                            'fieldTypeIdentifier' => 'eztext',
215
                            'defaultValue' => new TextLineValue('Some name'),
216
                        )
217
                    ),
218
                ),
219
            )
220
        );
221
222
        $this->registry->expects($this->once())
223
            ->method('get')
224
            ->with('eztext')
225
            ->will($this->returnValue($this->handler));
226
227
        $this->handler->expects($this->once())
228
            ->method('convertFieldValueToForm')
229
            ->willReturn('Some name');
230
231
        $infoStruct = new InformationCollectionStruct();
232
        $data = new DataWrapper($infoStruct, $contentType);
233
234
        $config = $this->getMockBuilder('Symfony\Component\Form\FormConfigBuilder')
235
            ->disableOriginalConstructor()
236
            ->setMethods(array('getMapped'))
237
            ->getMock();
238
239
        $config->expects($this->once())
240
            ->willReturn(true)
241
            ->method('getMapped');
242
243
        $propertyPath = $this->getMockBuilder('Symfony\Component\PropertyAccess\PropertyPathInterface')
244
            ->disableOriginalConstructor()
245
            ->setMethods(array('__toString'))
246
            ->getMockForAbstractClass();
247
248
        $propertyPath->expects($this->once())
249
            ->willReturn('name')
250
            ->method('__toString');
251
252
        $form = $this->getForm();
253
254
        $form->expects($this->once())
255
            ->method('setData');
256
257
        $form->expects($this->once())
258
            ->willReturn($config)
259
            ->method('getConfig');
260
261
        $form->expects($this->once())
262
            ->willReturn($propertyPath)
263
            ->method('getPropertyPath');
264
265
        $this->mapper->mapDataToForms($data, array($form));
266
    }
267
268
    /**
269
     * @expectedException \RuntimeException
270
     */
271
    public function testMapDataToFormsWithInvalidFieldDefinition()
272
    {
273
        $contentType = new ContentType(
274
            array(
275
                'id' => 123,
276
                'fieldDefinitions' => array(
277
                    new FieldDefinition(
278
                        array(
279
                            'id' => 'id',
280
                            'identifier' => 'test',
281
                            'fieldTypeIdentifier' => 'eztext',
282
                            'defaultValue' => new TextLineValue('Some name'),
283
                        )
284
                    ),
285
                ),
286
            )
287
        );
288
289
        $infoStruct = new InformationCollectionStruct();
290
        $data = new DataWrapper($infoStruct, $contentType);
291
292
        $config = $this->getMockBuilder('Symfony\Component\Form\FormConfigBuilder')
293
            ->disableOriginalConstructor()
294
            ->setMethods(array('getMapped'))
295
            ->getMock();
296
297
        $config->expects($this->once())
298
            ->willReturn(true)
299
            ->method('getMapped');
300
301
        $propertyPath = $this->getMockBuilder('Symfony\Component\PropertyAccess\PropertyPathInterface')
302
            ->disableOriginalConstructor()
303
            ->setMethods(array('__toString'))
304
            ->getMockForAbstractClass();
305
306
        $propertyPath->expects($this->once())
307
            ->willReturn('name')
308
            ->method('__toString');
309
310
        $form = $this->getForm();
311
312
        $form->expects($this->once())
313
            ->willReturn($config)
314
            ->method('getConfig');
315
316
        $form->expects($this->once())
317
            ->willReturn($propertyPath)
318
            ->method('getPropertyPath');
319
320
        $this->mapper->mapDataToForms($data, array($form));
321
    }
322
323
    private function getForm()
324
    {
325
        $form = $this->getMockBuilder('Symfony\Component\Form\Form')
326
            ->disableOriginalConstructor()
327
            ->setMethods(array('getData', 'setData', 'getPropertyPath', 'getConfig', 'isSubmitted', 'isSynchronized', 'isDisabled'))
328
            ->getMock();
329
330
        return $form;
331
    }
332
}
333