模拟输入立面在Laravel 4中 [英] Mocking Input Facade in Laravel 4

查看:69
本文介绍了模拟输入立面在Laravel 4中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这是一项表单服务.

I am using this is a Form service.

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

我正在尝试对其进行测试,但似乎无法正确模拟Input.文档说不要嘲笑请求"外观.即使它们都指向IOC容器中的同一类,也没有提及Input门面.

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);

    Input::shouldReceive('file')->andReturn($my_test_data);

推荐答案

显然,我错了.这确实有效.正确进行测试确实有帮助.

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);

我还创建了一个UploadedFile对象,并将其返回:

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];

这篇关于模拟输入立面在Laravel 4中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆