1

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

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

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

1 回答 1

1

解决方案非常简单

$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;
        });
于 2018-07-09T20:43:41.663 回答