Laravel 5.6。嘲讽。 属性 上的模拟方法

Laravel 5.6. Mockery. Mock method on property

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

app(ShopifySDK::class)->Order->get($params)

如何模拟此 class 并检查 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

解决方案非常简单

$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;
        });