Completed
Push — 3.x ( e95e95...638cd1 )
by Oskar
05:54
created

AdminHelperTest::testAppendFormFieldElement()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 100

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 100
rs 8
c 0
b 0
f 0
cc 3
nc 4
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
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Admin;
15
16
use Doctrine\Common\Collections\Collection;
17
use PHPUnit\Framework\TestCase;
18
use Sonata\AdminBundle\Admin\AdminHelper;
19
use Sonata\AdminBundle\Admin\AdminInterface;
20
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
21
use Sonata\AdminBundle\Admin\Pool;
22
use Sonata\AdminBundle\Tests\Fixtures\Entity\Foo;
23
use Symfony\Component\DependencyInjection\ContainerInterface;
24
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
25
use Symfony\Component\Form\DataMapperInterface;
26
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
27
use Symfony\Component\Form\FormBuilder;
28
use Symfony\Component\Form\FormFactoryInterface;
29
use Symfony\Component\Form\FormView;
30
use Symfony\Component\HttpFoundation\ParameterBag;
31
use Symfony\Component\HttpFoundation\Request;
32
use Symfony\Component\PropertyAccess\PropertyAccessorBuilder;
33
34
class AdminHelperTest extends TestCase
35
{
36
    /**
37
     * @var AdminHelper
38
     */
39
    protected $helper;
40
41
    public function setUp(): void
42
    {
43
        $container = $this->createMock(ContainerInterface::class);
44
45
        $pool = new Pool($container, 'title', 'logo.png');
0 ignored issues
show
Documentation introduced by
$container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...ion\ContainerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
        $this->helper = new AdminHelper($pool);
47
    }
48
49
    public function testGetChildFormBuilder(): void
50
    {
51
        $formFactory = $this->createMock(FormFactoryInterface::class);
52
        $eventDispatcher = $this->createMock(EventDispatcherInterface::class);
53
54
        $formBuilder = new FormBuilder('test', 'stdClass', $eventDispatcher, $formFactory);
0 ignored issues
show
Compatibility introduced by
$eventDispatcher of type object<PHPUnit\Framework\MockObject\MockObject> is not a sub-type of object<Symfony\Component...entDispatcherInterface>. It seems like you assume a child interface of the interface PHPUnit\Framework\MockObject\MockObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Documentation introduced by
$formFactory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...m\FormFactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
56
        $childFormBuilder = new FormBuilder('elementId', 'stdClass', $eventDispatcher, $formFactory);
0 ignored issues
show
Compatibility introduced by
$eventDispatcher of type object<PHPUnit\Framework\MockObject\MockObject> is not a sub-type of object<Symfony\Component...entDispatcherInterface>. It seems like you assume a child interface of the interface PHPUnit\Framework\MockObject\MockObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Documentation introduced by
$formFactory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...m\FormFactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
        $formBuilder->add($childFormBuilder);
58
59
        $this->assertNull($this->helper->getChildFormBuilder($formBuilder, 'foo'));
60
        $this->isInstanceOf(FormBuilder::class, $this->helper->getChildFormBuilder($formBuilder, 'test_elementId'));
0 ignored issues
show
Unused Code introduced by
The call to AdminHelperTest::isInstanceOf() has too many arguments starting with $this->helper->getChildF...lder, 'test_elementId').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
61
    }
62
63
    public function testGetChildFormView(): void
64
    {
65
        $formView = new FormView();
66
        $formView->vars['id'] = 'test';
67
        $child = new FormView($formView);
0 ignored issues
show
Documentation introduced by
$formView is of type object<Symfony\Component\Form\FormView>, but the function expects a null|object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
        $child->vars['id'] = 'test_elementId';
69
70
        $this->assertNull($this->helper->getChildFormView($formView, 'foo'));
71
        $this->isInstanceOf(FormView::class, $this->helper->getChildFormView($formView, 'test_elementId'));
0 ignored issues
show
Unused Code introduced by
The call to AdminHelperTest::isInstanceOf() has too many arguments starting with $this->helper->getChildF...View, 'test_elementId').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
72
    }
73
74
    public function testAddNewInstance(): void
75
    {
76
        $admin = $this->createMock(AdminInterface::class);
77
        $admin->expects($this->once())->method('getNewInstance')->willReturn(new \stdClass());
78
79
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
80
        $fieldDescription->expects($this->once())->method('getAssociationAdmin')->willReturn($admin);
81
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['fieldName' => 'fooBar']);
82
83
        $object = $this->getMockBuilder('stdClass')
84
            ->setMethods(['addFooBar'])
85
            ->getMock();
86
        $object->expects($this->once())->method('addFooBar');
87
88
        $this->helper->addNewInstance($object, $fieldDescription);
0 ignored issues
show
Documentation introduced by
$fieldDescription is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...ldDescriptionInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
89
    }
90
91
    public function testAddNewInstancePlural(): void
92
    {
93
        $admin = $this->createMock(AdminInterface::class);
94
        $admin->expects($this->once())->method('getNewInstance')->willReturn(new \stdClass());
95
96
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
97
        $fieldDescription->expects($this->once())->method('getAssociationAdmin')->willReturn($admin);
98
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['fieldName' => 'fooBars']);
99
100
        $object = $this->getMockBuilder('stdClass')
101
            ->setMethods(['addFooBar'])
102
            ->getMock();
103
        $object->expects($this->once())->method('addFooBar');
104
105
        $this->helper->addNewInstance($object, $fieldDescription);
0 ignored issues
show
Documentation introduced by
$fieldDescription is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...ldDescriptionInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
106
    }
107
108
    public function testAddNewInstanceInflector(): void
109
    {
110
        $admin = $this->createMock(AdminInterface::class);
111
        $admin->expects($this->once())->method('getNewInstance')->willReturn(new \stdClass());
112
113
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
114
        $fieldDescription->expects($this->once())->method('getAssociationAdmin')->willReturn($admin);
115
        $fieldDescription->expects($this->once())->method('getAssociationMapping')->willReturn(['fieldName' => 'entries']);
116
117
        $object = $this->getMockBuilder('stdClass')
118
            ->setMethods(['addEntry'])
119
            ->getMock();
120
        $object->expects($this->once())->method('addEntry');
121
122
        $this->helper->addNewInstance($object, $fieldDescription);
0 ignored issues
show
Documentation introduced by
$fieldDescription is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundl...ldDescriptionInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
123
    }
124
125
    public function testGetElementAccessPath(): void
126
    {
127
        $object = $this->getMockBuilder('stdClass')
128
            ->setMethods(['getPathToObject'])
129
            ->getMock();
130
        $subObject = $this->getMockBuilder('stdClass')
131
            ->setMethods(['getAnother'])
132
            ->getMock();
133
        $sub2Object = $this->getMockBuilder('stdClass')
134
            ->setMethods(['getMoreThings'])
135
            ->getMock();
136
137
        $object->expects($this->atLeastOnce())->method('getPathToObject')->willReturn([$subObject]);
138
        $subObject->expects($this->atLeastOnce())->method('getAnother')->willReturn($sub2Object);
139
        $sub2Object->expects($this->atLeastOnce())->method('getMoreThings')->willReturn('Value');
140
141
        $path = $this->helper->getElementAccessPath('uniquePartOfId_path_to_object_0_another_more_things', $object);
142
143
        $this->assertSame('path_to_object[0].another.more_things', $path);
144
    }
145
146
    public function testItThrowsExceptionWhenDoesNotFindTheFullPath(): void
147
    {
148
        $path = 'uniquePartOfId_path_to_object_0_more_calls';
149
        $object = $this->getMockBuilder('stdClass')
150
            ->setMethods(['getPathToObject'])
151
            ->getMock();
152
        $subObject = $this->getMockBuilder('stdClass')
153
            ->setMethods(['getMore'])
154
            ->getMock();
155
156
        $object->expects($this->atLeastOnce())->method('getPathToObject')->willReturn([$subObject]);
157
        $subObject->expects($this->atLeastOnce())->method('getMore')->willReturn('Value');
158
159
        $this->expectException(\Exception::class, 'Could not get element id from '.$path.' Failing part: calls');
0 ignored issues
show
Unused Code introduced by
The call to AdminHelperTest::expectException() has too many arguments starting with 'Could not get element i... ' Failing part: calls'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
160
161
        $this->helper->getElementAccessPath($path, $object);
162
    }
163
164
    public function testAppendFormFieldElement(): void
165
    {
166
        $container = $this->createMock(ContainerInterface::class);
167
168
        $propertyAccessorBuilder = new PropertyAccessorBuilder();
169
        $propertyAccesor = $propertyAccessorBuilder->getPropertyAccessor();
170
        $pool = new Pool($container, 'title', 'logo.png', [], $propertyAccesor);
0 ignored issues
show
Documentation introduced by
$container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...ion\ContainerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
171
        $helper = new AdminHelper($pool);
172
173
        $admin = $this->createMock(AdminInterface::class);
174
        $admin
175
            ->expects($this->any())
176
            ->method('getClass')
177
            ->willReturn(Foo::class);
178
179
        $associationMapping = [
180
            'fieldName' => 'bar',
181
            'targetEntity' => Foo::class,
182
            'sourceEntity' => Foo::class,
183
            'isOwningSide' => false,
184
        ];
185
186
        $fieldDescription = $this->createMock(FieldDescriptionInterface::class);
187
        $fieldDescription->expects($this->any())->method('getAssociationAdmin')->willReturn($admin);
188
        $fieldDescription->expects($this->any())->method('getAssociationMapping')->willReturn($associationMapping);
189
190
        $admin
191
            ->expects($this->any())
192
            ->method('getFormFieldDescription')
193
            ->willReturn($fieldDescription);
194
195
        $admin
196
            ->expects($this->any())
197
            ->method('getFormFieldDescriptions')
198
            ->willReturn([
199
                'bar' => $fieldDescription,
200
            ]);
201
202
        $request = $this->createMock(Request::class);
203
        $request
204
            ->expects($this->any())
205
            ->method('get')
206
            ->willReturn([
207
                'bar' => [
208
                    [
209
                        'baz' => [
210
                            'baz' => true,
211
                        ],
212
                    ],
213
                    ['_delete' => true],
214
                ],
215
            ]);
216
217
        $request->request = new ParameterBag();
0 ignored issues
show
Bug introduced by
Accessing request on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
218
219
        $admin
220
            ->expects($this->any())
221
            ->method('getRequest')
222
            ->will($this->onConsecutiveCalls($request, $request, $request, null, $request, $request, $request, $request, null, $request));
223
224
        $foo = $this->createMock(Foo::class);
225
226
        $collection = $this->createMock(Collection::class);
227
        $foo->setBar($collection);
228
229
        $dataMapper = $this->createMock(DataMapperInterface::class);
230
        $formFactory = $this->createMock(FormFactoryInterface::class);
231
        $eventDispatcher = $this->createMock(EventDispatcherInterface::class);
232
        $formBuilder = new FormBuilder('test', \get_class($foo), $eventDispatcher, $formFactory);
0 ignored issues
show
Compatibility introduced by
$eventDispatcher of type object<PHPUnit\Framework\MockObject\MockObject> is not a sub-type of object<Symfony\Component...entDispatcherInterface>. It seems like you assume a child interface of the interface PHPUnit\Framework\MockObject\MockObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Documentation introduced by
$formFactory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...m\FormFactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
233
        $childFormBuilder = new FormBuilder('bar', \stdClass::class, $eventDispatcher, $formFactory);
0 ignored issues
show
Compatibility introduced by
$eventDispatcher of type object<PHPUnit\Framework\MockObject\MockObject> is not a sub-type of object<Symfony\Component...entDispatcherInterface>. It seems like you assume a child interface of the interface PHPUnit\Framework\MockObject\MockObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Documentation introduced by
$formFactory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...m\FormFactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
234
        $childFormBuilder->setCompound(true);
235
        $childFormBuilder->setDataMapper($dataMapper);
0 ignored issues
show
Documentation introduced by
$dataMapper is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Symfony\Comp...rm\DataMapperInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
236
        $subChildFormBuilder = new FormBuilder('baz', \stdClass::class, $eventDispatcher, $formFactory);
0 ignored issues
show
Compatibility introduced by
$eventDispatcher of type object<PHPUnit\Framework\MockObject\MockObject> is not a sub-type of object<Symfony\Component...entDispatcherInterface>. It seems like you assume a child interface of the interface PHPUnit\Framework\MockObject\MockObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Documentation introduced by
$formFactory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...m\FormFactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
237
        $subChildFormBuilder->setCompound(true);
238
        $subChildFormBuilder->setDataMapper($dataMapper);
0 ignored issues
show
Documentation introduced by
$dataMapper is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Symfony\Comp...rm\DataMapperInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
239
        $childFormBuilder->add($subChildFormBuilder);
240
241
        $formBuilder->setCompound(true);
242
        $formBuilder->setDataMapper($dataMapper);
0 ignored issues
show
Documentation introduced by
$dataMapper is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Symfony\Comp...rm\DataMapperInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
243
        $formBuilder->add($childFormBuilder);
244
245
        $admin->expects($this->any())->method('getFormBuilder')->willReturn($formBuilder);
246
        $admin->expects($this->any())->method('getSubject')->willReturn($foo);
247
248
        $finalForm = $helper->appendFormFieldElement($admin, $foo, 'test_bar')[1];
0 ignored issues
show
Documentation introduced by
$admin is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundle\Admin\AdminInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
249
250
        foreach ($finalForm->get($childFormBuilder->getName()) as $childField) {
251
            $this->assertFalse($childField->has('_delete'));
252
        }
253
254
        $deleteFormBuilder = new FormBuilder('_delete', null, $eventDispatcher, $formFactory);
0 ignored issues
show
Compatibility introduced by
$eventDispatcher of type object<PHPUnit\Framework\MockObject\MockObject> is not a sub-type of object<Symfony\Component...entDispatcherInterface>. It seems like you assume a child interface of the interface PHPUnit\Framework\MockObject\MockObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Documentation introduced by
$formFactory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...m\FormFactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
255
        $subChildFormBuilder->add($deleteFormBuilder, CheckboxType::class, ['delete' => false]);
256
257
        $finalForm = $helper->appendFormFieldElement($admin, $foo, 'test_bar')[1];
0 ignored issues
show
Documentation introduced by
$admin is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundle\Admin\AdminInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
258
259
        foreach ($finalForm->get($childFormBuilder->getName()) as $childField) {
260
            $this->assertTrue($childField->has('_delete'));
261
            $this->assertSame('', $childField->get('_delete')->getData());
262
        }
263
    }
264
265
    public function testAppendFormFieldElementNested(): void
266
    {
267
        $admin = $this->createMock(AdminInterface::class);
268
        $object = $this->getMockBuilder('stdClass')
269
            ->setMethods(['getSubObject'])
270
            ->getMock();
271
        $simpleObject = $this->getMockBuilder('stdClass')
272
            ->setMethods(['getSubObject'])
273
            ->getMock();
274
        $subObject = $this->getMockBuilder('stdClass')
275
            ->setMethods(['getAnd'])
276
            ->getMock();
277
        $sub2Object = $this->getMockBuilder('stdClass')
278
            ->setMethods(['getMore'])
279
            ->getMock();
280
        $sub3Object = $this->getMockBuilder('stdClass')
281
            ->setMethods(['getFinalData'])
282
            ->getMock();
283
        $dataMapper = $this->createMock(DataMapperInterface::class);
284
        $formFactory = $this->createMock(FormFactoryInterface::class);
285
        $eventDispatcher = $this->createMock(EventDispatcherInterface::class);
286
        $formBuilder = new FormBuilder('test', \get_class($simpleObject), $eventDispatcher, $formFactory);
0 ignored issues
show
Compatibility introduced by
$eventDispatcher of type object<PHPUnit\Framework\MockObject\MockObject> is not a sub-type of object<Symfony\Component...entDispatcherInterface>. It seems like you assume a child interface of the interface PHPUnit\Framework\MockObject\MockObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Documentation introduced by
$formFactory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...m\FormFactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
287
        $childFormBuilder = new FormBuilder('subObject', \get_class($subObject), $eventDispatcher, $formFactory);
0 ignored issues
show
Compatibility introduced by
$eventDispatcher of type object<PHPUnit\Framework\MockObject\MockObject> is not a sub-type of object<Symfony\Component...entDispatcherInterface>. It seems like you assume a child interface of the interface PHPUnit\Framework\MockObject\MockObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Documentation introduced by
$formFactory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...m\FormFactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
288
289
        $object->expects($this->atLeastOnce())->method('getSubObject')->willReturn([$subObject]);
290
        $subObject->expects($this->atLeastOnce())->method('getAnd')->willReturn($sub2Object);
291
        $sub2Object->expects($this->atLeastOnce())->method('getMore')->willReturn([$sub3Object]);
292
        $sub3Object->expects($this->atLeastOnce())->method('getFinalData')->willReturn('value');
293
294
        $formBuilder->setCompound(true);
295
        $formBuilder->setDataMapper($dataMapper);
0 ignored issues
show
Documentation introduced by
$dataMapper is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Symfony\Comp...rm\DataMapperInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
296
        $formBuilder->add($childFormBuilder);
297
298
        $admin->expects($this->once())->method('getFormBuilder')->willReturn($formBuilder);
299
        $admin->expects($this->once())->method('getSubject')->willReturn($object);
300
301
        $this->expectException(\Exception::class, 'unknown collection class');
0 ignored issues
show
Unused Code introduced by
The call to AdminHelperTest::expectException() has too many arguments starting with 'unknown collection class'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
302
303
        $this->helper->appendFormFieldElement($admin, $simpleObject, 'uniquePartOfId_sub_object_0_and_more_0_final_data');
0 ignored issues
show
Documentation introduced by
$admin is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\AdminBundle\Admin\AdminInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
304
    }
305
}
306