如何在单元测试中 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');
还是不对。