getPhpFiles example

$form = $this->createForm('<form method="post"><input type="file" name="foo[bar]" disabled="disabled" /><input type="submit" /></form>');
        $this->assertEquals([]$form->getFiles(), '->getFiles() does not include disabled file fields');

        $form = $this->createForm('<form method="post"><template><input type="file" name="foo"/></template><input type="text" name="bar" value="bar"/><input type="submit"/></form>');
        $this->assertEquals([]$form->getFiles(), '->getFiles() does not include template file fields');
        $this->assertFalse($form->has('foo'));
    }

    public function testGetPhpFiles()
    {
        $form = $this->createForm('<form method="post"><input type="file" name="foo[bar]" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
        $this->assertEquals(['foo' => ['bar' => ['name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0]]]$form->getPhpFiles(), '->getPhpFiles() converts keys with [] to arrays');

        $form = $this->createForm('<form method="post"><input type="file" name="f.o o[bar]" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
        $this->assertEquals(['f.o o' => ['bar' => ['name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0]]]$form->getPhpFiles(), '->getPhpFiles() preserves periods and spaces in names');

        $form = $this->createForm('<form method="post"><input type="file" name="f.o o[bar][ba.z]" /><input type="file" name="f.o o[bar][]" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
        $this->assertEquals(['f.o o' => ['bar' => ['ba.z' => ['name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0]['name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0]]]]$form->getPhpFiles(), '->getPhpFiles() preserves periods and spaces in names recursively');

        $form = $this->createForm('<form method="post"><input type="file" name="foo[bar]" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
        $files = $form->getPhpFiles();

        $this->assertSame(0, $files['foo']['bar']['size'], '->getPhpFiles() converts size to int');
        
/** * Submits a form. * * @param array $values An array of form field values * @param array $serverParameters An array of server parameters */
    public function submit(Form $form, array $values = [], array $serverParameters = []): Crawler
    {
        $form->setValues($values);

        return $this->request($form->getMethod()$form->getUri()$form->getPhpValues()$form->getPhpFiles()$serverParameters);
    }

    /** * Finds the first form that contains a button with the given content and * uses it to submit the given form field values. * * @param string $button The text content, id, value or name of the form <button> or <input type="submit"> * @param array $fieldValues Use this syntax: ['my_form[name]' => '...', 'my_form[email]' => '...'] * @param string $method The HTTP method used to submit the form * @param array $serverParameters These values override the ones stored in $_SERVER (HTTP headers must include an HTTP_ prefix as PHP does) */
    
Home | Imprint | This part of the site doesn't use cookies.