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 |
|
|
|
|
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
|
|
|
} |
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..