Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed #19572

Copy link
Copy link
Closed
@PlamenVasilev

Description

@PlamenVasilev
Issue body actions

I'm trying to write white unit test to test my API with file uploads.

I'm following the docs about this using basic client request, not crawler.

The unit test is:

class RecordsControllerTest extends WebTestCase {

private $client;

public function __construct() {
    parent::__construct();
    $this->client = self::createClient();
    $this->client->insulate();
}

public function testApiPostUpload($params){
    $fileToUpload = realpath(__DIR__.'/../../resources/mpthreetest.mp3');
    $file = new UploadedFile(
        $fileToUpload,
        'mpthreetest.mp3',
        MimeTypeGuesser::getInstance()->guess($fileToUpload),
        filesize($fileToUpload)
    );
    $this->client->request('POST', '/records/'.$params['createdRecordId'].'/upload', array(), array('file' => $file) );

    $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
}
}

When I execute the test I receive an error:

Exception: Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed

/path/to/project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Client.php:165
/path/to/project/vendor/symfony/symfony/src/Symfony/Component/BrowserKit/Client.php:348
/path/to/project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Client.php:143
/path/to/project/vendor/symfony/symfony/src/Symfony/Component/BrowserKit/Client.php:313
/path/to/project/src/Bundle/Tests/Functional/Controller/RecordsControllerTest.php:182

Posting files is not working as it is described in the docs.

Any ideas?

musahcoding

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.