Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking Input Facade in Laravel 4

I am using this is a Form service.

$files = Input::file('my_file');

I'm trying to test it, but I can't seem to properly mock Input. The docs say not to mock the Request facade. There is no mention of the Input facade, even though they both point to the same class in the IOC container.

I've tried several methods, but they don't work. Any ideas?

    $mockInput = Mockery::mock('\Illuminate\Http\Request');
    $mockInput->shouldReceive('file')->andReturn($my_test_data);
    Input::swap($mockInput);

and

    Input::shouldReceive('file')->andReturn($my_test_data);
like image 370
Eric Cope Avatar asked Nov 26 '25 12:11

Eric Cope


1 Answers

Apparently, I was wrong. This does work. It does help to have it in the right test.

$mockInput = Mockery::mock('\Illuminate\Http\Request');
$mockInput->shouldReceive('file')->andReturn($my_test_data);
Input::swap($mockInput);

Also, I created an UploadedFile object and andReturned it:

$media = new \Symfony\Component\HttpFoundation\File\UploadedFile(
     $path,
     'orig_name_1.jpg'
);
$my_test_data = [0 => $media];
like image 145
Eric Cope Avatar answered Nov 29 '25 07:11

Eric Cope



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!