Completed
Push — master ( 6d6774...64f3ed )
by Jeroen
11:23 queued 05:13
created

Tests/unit/Form/ChoiceFormSubmissionTypeTest.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
namespace Kunstmaan\FormBundle\Tests\Form;
4
5
use Kunstmaan\FormBundle\Entity\FormSubmissionFieldTypes\ChoiceFormSubmissionField;
6
use Kunstmaan\FormBundle\Form\ChoiceFormSubmissionType;
7
use Symfony\Component\Form\Test\TypeTestCase;
8
9
/**
10
 * Class ChoiceFormSubmissionTypeTest
11
 */
12
class ChoiceFormSubmissionTypeTest extends TypeTestCase
13
{
14
    public function testFormType()
15
    {
16
        $formData = [
17
            'value' => 'beer',
18
        ];
19
20
        $form = $this->factory->create(ChoiceFormSubmissionType::class, null, ['choices' => [
21
            'beer' => 'bier',
22
            'wine' => 'wijn',
23
        ]]);
24
25
        $object = new ChoiceFormSubmissionField();
26
        $object->setValue('beer');
0 ignored issues
show
'beer' is of type string, but the function expects a array.

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...
27
28
        $form->submit($formData);
29
30
        $this->assertTrue($form->isSynchronized());
31
        $this->assertTrue($form->isValid());
32
        $this->assertEquals($object, $form->getData());
33
34
        $view = $form->createView();
35
        $children = $view->children;
36
37
        foreach (array_keys($formData) as $key) {
38
            $this->assertArrayHasKey($key, $children);
39
        }
40
    }
41
}
42