Completed
Push — master ( 3cd231...d48ef1 )
by
unknown
153:58 queued 132:33
created

ChoiceFormSubmissionTypeTest::testFormType()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
nc 2
cc 2
nop 0
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
Documentation introduced by
'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