如何在单元测试中 mock Storage 的 get 方法?

我在controller中是这么写的:

$file = Storage::get('app.apk');
$ret = new Response ($file, 200);
$ret->header('Content-Type', 'application/vnd.android.package-archive');
return $ret;

我在单元测试中是这么写的:

Storage::shouldReceive('get')->with('app.apk')->andReturn('Android Data');
$response = $this->action('GET', 'DownloadController@download');
$this->assertEquals(200, $response->getStatusCode());

但是运行phpunit还是出现错误了:get() cannot be mocked as it a protected method and mocking protected methods is not allowed for this mock
(环境是Laravel5。)

大家遇到这样的问题吗?

另外,按照google的说法,改成Storage::shouldReceive('__call')->with('get', 'app.apk')->andReturn('Android Data');还是不对。

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 1
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!