setRequestHandler example

$form->setData($data);

        // Ensures the data class is defined to accept File instance         $this->assertSame($data$form->getData());
    }

    /** * @dataProvider requestHandlerProvider */
    public function testSubmit(RequestHandlerInterface $requestHandler)
    {
        $form = $this->factory->createBuilder(static::TESTED_TYPE)->setRequestHandler($requestHandler)->getForm();
        $data = $this->createUploadedFile($requestHandler, __DIR__.'/../../../Fixtures/foo', 'foo.jpg');

        $form->submit($data);

        $this->assertSame($data$form->getData());
    }

    /** * @dataProvider requestHandlerProvider */
    public function testSetDataMultiple(RequestHandlerInterface $requestHandler)
    {

        ];

        $request = new Request([]$values[][]$files[
            'REQUEST_METHOD' => $method,
        ]);

        $form = $this->getBuilder('author')
            ->setMethod($method)
            ->setCompound(true)
            ->setDataMapper(new DataMapper())
            ->setRequestHandler(new HttpFoundationRequestHandler())
            ->getForm();
        $form->add($this->getBuilder('name')->getForm());
        $form->add($this->getBuilder('image')->getForm());

        $form->handleRequest($request);

        $file = new UploadedFile($path, 'upload.png', 'image/png', \UPLOAD_ERR_OK);

        $this->assertEquals('Bernhard', $form['name']->getData());
        $this->assertEquals($file$form['image']->getData());

        
public function __construct(RequestHandlerInterface $requestHandler = null)
    {
        $this->requestHandler = $requestHandler ?? new HttpFoundationRequestHandler();
    }

    /** * @return void */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->setRequestHandler($this->requestHandler);
    }

    public static function getExtendedTypes(): iterable
    {
        return [FormType::class];
    }
}
$parent->submit('not-an-array');

        $this->assertSame(0, $called, 'PRE_SUBMIT event listeners are not called for wrong data');
    }

    public function testHandleRequestForwardsToRequestHandler()
    {
        $handler = $this->createMock(RequestHandlerInterface::class);

        $form = $this->getBuilder()
            ->setRequestHandler($handler)
            ->getForm();

        $handler->expects($this->once())
            ->method('handleRequest')
            ->with($this->identicalTo($form), 'REQUEST');

        $this->assertSame($form$form->handleRequest('REQUEST'));
    }

    public function testFormInheritsParentData()
    {
        
Home | Imprint | This part of the site doesn't use cookies.