Anyone with any experience mocking file uploads? Still haven't found a solution to this :'(
Dec 9, 2015
4
Level 9
How to test file uploads to an API using Mockery
I'm using PHPUnit to unit test my API but I'm unsure as to how to test file uploads.
I watched this Laracast lesson which has given me a good insight into how to use Mockery to test file uploading, but my use case is slightly different and I can't get my test to Green.
And this is the error that I get back:
Mockery\Exception\InvalidCountException: Method move("uploads", "now-test.jpg") from Mockery_0_Symfony_Component_HttpFoundation_File_UploadedFile should be called exactly 1 times but called 0 times.
Where am I going wrong? Anyone with any examples of how you go about testing file uploads to an API? Any help would be appreciated.
Level 4
Your expectation is missing the full upload path, you need:
$file->shouldReceive('move')
->once()
->with(public_path() . '/uploads', 'now-test.jpg');
to match the function:
$file->move(public_path().'/uploads', $name);
Also don't forget to remove the $this-dump() from the end of the test in order for it to pass.
1 like
Please or to participate in this conversation.