Laravel 5.6。嘲笑。属性的模拟方法

时间:2018-07-09 18:43:55

标签: laravel mocking laravel-5.6 mockery laravel-testing

目前我有类似的东西(简化版)

get()

如何模拟此类并检查$this->app->bind(ShopifySDK::class, function () { return Mockery::mock(ShopifySDK::class) ->shouldReceive('Order->get') ->once() ->with([ 'status' => 'any', 'updated_at_min' => '2010-01-01T00:00:00+00:00', 'order' => 'updated_at asc', 'limit' => 250, 'page' => 1, ])->getMock(); }); 方法的输入?

这不起作用。

ErrorException : Undefined property: Mockery_1__demeter_d588e5bd79af839e05009e561399d4e0_Order::$Order

并给出这样的错误

{{1}}

1 个答案:

答案 0 :(得分:0)

解决方案很简单

$this->app->bind(ShopifySDK::class, function () use ($apiResponse) {
            $mock        = Mockery::mock(ShopifySDK::class)->makePartial();
            $mock->Order = Mockery::mock(ShopifySDK::class)
                                  ->shouldReceive('get')
                                  ->with([
                                      'status'         => 'any',
                                      'updated_at_min' => '2010-01-01T00:00:00+00:00',
                                      'order'          => 'updated_at asc',
                                      'limit'          => 250,
                                      'page'           => 1,
                                  ])->getMock();
            return $mock;
        });