在我的代码中,我使用makeWith
来解决依赖关系。
在我的测试中,我正在创建一个应通过调用makeWith
在代码中解决的模拟。但是事实并非如此。
App::make('App\Item'); //ok: returns mock
App::makeWith('App\Item', ['name' => 'apple'];//not ok: doesn't return the mock but the class to be used outside the test environment
这是错误还是我错过了什么?
答案 0 :(得分:0)
要设置模拟对象,请使用
App::offsetSet('App\Item', $itemMock);
现在
App::makeWith('App\Item', ['name' => 'apple']);
返回$itemMock