【问题标题】:Using makeWith in combination with mocking将 makeWith 与模拟结合使用
【发布时间】:2019-02-06 08:39:25
【问题描述】:

在我的代码中,我使用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

这是一个错误还是我遗漏了什么?

【问题讨论】:

    标签: laravel testing laravel-5.6 mockery


    【解决方案1】:

    设置模拟对象使用

    App::offsetSet('App\Item', $itemMock);
    

    现在

    App::makeWith('App\Item', ['name' => 'apple']);
    

    返回$itemMock

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多