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

FileFormSubmissionTypeTest::testFormType()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 9.504
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\FileFormSubmissionField;
6
use Kunstmaan\FormBundle\Form\FileFormSubmissionType;
7
use Symfony\Component\Form\Test\TypeTestCase;
8
use Symfony\Component\HttpFoundation\File\UploadedFile;
9
10
/**
11
 * Class FileFormSubmissionTypeTest
12
 * @package Tests\Kunstmaan\FormBundle\Entity
13
 */
14
class FileFormSubmissionTypeTest extends TypeTestCase
15
{
16
    /**
17
     * @var UploadedFile $file
18
     */
19
    private $file;
20
21
    /**
22
     * @var UploadedFile $image
23
     */
24
    private $image;
25
26
    public function setUp()
27
    {
28
        parent::setUp();
29
30
        $this->file = tempnam(sys_get_temp_dir(), 'upl'); // create file
0 ignored issues
show
Documentation Bug introduced by
It seems like tempnam(sys_get_temp_dir(), 'upl') of type string is incompatible with the declared type object<Symfony\Component...tion\File\UploadedFile> of property $file.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
31
32
        imagepng(imagecreatetruecolor(10, 10), $this->file); // create and write image/png to it
33
34
        $this->image = new UploadedFile(
35
            $this->file,
36
            'new_image.png'
37
        );
38
    }
39
40
    public function testFormType()
41
    {
42
        $formData = [
43
            'file' => $this->image,
44
        ];
45
46
        $field = new FileFormSubmissionField();
47
        $field->file = $this->image;
48
49
        $form = $this->factory->create(FileFormSubmissionType::class, $field);
50
51
52
53
        $form->submit($formData);
54
55
        $this->assertTrue($form->isSynchronized());
56
        $this->assertTrue($form->isValid());
57
        $this->assertEquals($field, $form->getData());
58
59
        $view = $form->createView();
60
        $children = $view->children;
61
62
        foreach (array_keys($formData) as $key) {
63
            $this->assertArrayHasKey($key, $children);
64
        }
65
    }
66
}