Repository: symfony/symfony
File: src/Symfony/Component/Form/Tests/AbstractRequestHandlerTestCase.php (PHP)

Code before:
        $this->setRequestData('POST', [
            'root' => [
                'items' => [
                    1 => [
                        'item' => 'test',
                    ],
                ],
            ],
        ], [
            'root' => [
                'items' => [
                    0 => [
                        'file' => $file,
                    ],
                    1 => [
                        'file' => $file2,
                    ],
                ],
            ],
        ]);

        $this->requestHandler->handleRequest($form, $this->request);

        $itemsForm = $form->get('items');
        $data = $itemsForm->getData();
        $this->assertTrue($form->isSubmitted());
        $this->assertTrue($form->isValid());

        $this->assertCount(2, $data);
        $this->assertArrayHasKey(0, $data);
        $this->assertArrayHasKey(1, $data);

        $this->assertEquals('test', $itemsForm->get('1')->get('item')->getData());
        $this->assertNotNull($itemsForm->get('0')->get('file'));
    }

    /**
     * @dataProvider methodExceptGetProvider
     */
    public function testSubmitFileIfNoParam($method)
    {
        $form = $this->createBuilder('param1', false, ['allow_file_upload' => true])
            ->setMethod($method)
            ->getForm();
        $file = $this->getUploadedFile();

        $this->setRequestData($method, [
            'param1' => null,
        ], [
            'param1' => $file,
        ]);

Review comment (suggestion):
this misses assertions on `$itemsForm->get('0')->get('name')` and `$itemsForm->get('1')->get('file')`

Code after:
            'root' => [
                'items' => [
                    0 => [
                        'file' => $file,
                    ],
                    1 => [
                        'file' => $file2,
                    ],
                ],
            ],
        ]);

        $this->requestHandler->handleRequest($form, $this->request);

        $itemsForm = $form->get('items');
        $data = $itemsForm->getData();
        $this->assertTrue($form->isSubmitted());
        $this->assertTrue($form->isValid());

        $this->assertCount(2, $data);
        $this->assertArrayHasKey(0, $data);
        $this->assertArrayHasKey(1, $data);

        $this->assertNull($itemsForm->get('0')->get('item')->getData());
        $this->assertNotNull($itemsForm->get('0')->get('file')->getData());
        $this->assertEquals('test', $itemsForm->get('1')->get('item')->getData());
        $this->assertNotNull($itemsForm->get('1')->get('file')->getData());
    }

    /**
     * @dataProvider methodExceptGetProvider
     */
    public function testSubmitFileIfNoParam($method)
    {
        $form = $this->createBuilder('param1', false, ['allow_file_upload' => true])
            ->setMethod($method)
            ->getForm();
        $file = $this->getUploadedFile();

        $this->setRequestData($method, [
            'param1' => null,
        ], [
            'param1' => $file,
        ]);

        $this->requestHandler->handleRequest($form, $this->request);

        $this->assertTrue($form->isSubmitted());
        $this->assertSame($file, $form->getData());
    }