Mocking Input Facade in Laravel 4

后端 未结 1 844
难免孤独
难免孤独 2021-01-14 06:31

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

相关标签:
1条回答
  • 2021-01-14 07:03

    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];
    
    0 讨论(0)
提交回复
热议问题