Completed
Push — master ( a97f84...b5df1f )
by
unknown
11:58
created

Widget/FormSonataNativeCollectionWidgetTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Form\Widget;
15
16
use Sonata\AdminBundle\Form\Extension\Field\Type\FormTypeFieldExtension;
17
use Sonata\AdminBundle\Form\Type\CollectionType;
18
use Symfony\Component\Form\FormTypeGuesserInterface;
19
use Symfony\Component\Form\Tests\Fixtures\TestExtension;
20
21
class FormSonataNativeCollectionWidgetTest extends BaseWidgetTest
22
{
23
    protected $type = 'form';
24
25
    public function setUp(): void
26
    {
27
        parent::setUp();
28
    }
29
30
    public function prototypeRenderingProvider()
31
    {
32
        return [
33
            'shrinkable collection' => [['allow_delete' => true]],
34
            'unshrinkable collection' => [['allow_delete' => false]],
35
        ];
36
    }
37
38
    /**
39
     * @dataProvider prototypeRenderingProvider
40
     */
41
    public function testPrototypeIsDeletableNoMatterTheShrinkability(array $options): void
42
    {
43
        $choice = $this->factory->create(
44
            $this->getChoiceClass(),
45
            null,
46
            ['allow_add' => true] + $options
47
        );
48
49
        $html = $this->renderWidget($choice->createView());
50
51
        $this->assertContains(
52
            'sonata-collection-delete',
53
            $this->cleanHtmlWhitespace($html)
54
        );
55
    }
56
57
    protected function getExtensions()
58
    {
59
        $extensions = parent::getExtensions();
60
        $guesser = $this->getMockForAbstractClass(FormTypeGuesserInterface::class);
61
        $extension = new TestExtension($guesser);
0 ignored issues
show
$guesser is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...rmTypeGuesserInterface>.

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...
62
63
        $extension->addTypeExtension(new FormTypeFieldExtension([], [
64
            'form_type' => 'vertical',
65
        ]));
66
        $extensions[] = $extension;
67
68
        return $extensions;
69
    }
70
71
    protected function getChoiceClass()
72
    {
73
        return CollectionType::class;
74
    }
75
}
76