[FrameworkBundle] Functional tests, to test functional test simulated file uploads #1891

wants to merge 1 commit into

3 participants


I have been having great difficulty testing file uploads in a Symfony app. The app code works but I can't write tests to confirm it.

The documentation states the following should work:

$client->request('POST', '/submit', array('name' => 'Fabien'), array('photo' => '/path/to/photo'));

So I've created a Functional test for the framework to test this. All I have modified is the photo path to be the test file it's self. This way I know the file exists and it removes this doubt.

I am unsure if this is even the right location for this test or if its even appropriate. But this seemed the best way to test if things are working or not.

I hope it's not a problem between keyboard and chair as it's taken me about 7 hours of chasing code down to decide to put this pull request together.


@fabpot Is there any chance of an opinion on this issue? I understand you are a very busy man, but a little look would be appreciated.

I had issues with the upload code today that I was trying to test and not being about to fire my unit tests was a right pain.

It's especially frustrating because I'm still not sure if this is a bug or something I've done stupid. :(

Symfony member

@johnwards: I'm on holidays for another two weeks and I try to work as little as possible ;)


Enjoy your holiday! I'm now on holiday for 10 days where I will also try and work as little a possible...


Hey @fabpot, by the activity in the commits it looks like you are back from your holiday. Hope it was restful.

Any chance you could look at this and at least confirm that it is a bug? I'm still on holiday until Monday but this one is playing on my mind as I'm still not sure if its something I've done stupid.

Maybe @weaverryan could comment on the line from the docs? As it's pretty much copy and paste for this functional test.

Symfony member

I actually haven't touched that one part of the docs, meaning that the line itself is quite old: it is very possible that it's out of date. Unfortunately, I don't have any other information right now :/


Okay, thanks for looking @weaverryan.

@fabpot, we at @whiteoctober are happy to look at this but we don't want to try and fix something if we are just doing it wrong. So confirmation on it being broken would be good, and any direction in the code history as to when it would have worked would also be handy.

Symfony member

Sorry for the late response (I thought the problem would have taken some time to resolve, but actually it was quite simple).

Basically, the documentation was out of date. It's fixed now (symfony/symfony-docs@e6027eb). By the way, it's much simpler to use a crawler to simulate form submission (I've also added a tip about that in the doc).

I've also added an exception when you do what you've tried as the error was silently ignored (symfony/symfony@1c7694f).

@fabpot fabpot closed this Aug 25, 2011

@fabpot thanks! I'm glad it was a simple fix.

I couldn't use a Crawler because this was testing a POST api. Well I couldn't figure out how to use a crawler as it expected some html, I tried to fake it but gave up in the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment