1

Currently I have something like that (simplified version)

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

How can I mock this class and check get() method input?

This is not working.

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

and gives such an error

ErrorException : Undefined property: Mockery_1__demeter_d588e5bd79af839e05009e561399d4e0_Order::$Order
D.R.
  • 2,540
  • 3
  • 24
  • 49

1 Answers1

1

The solution was quite straighforward

$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;
        });
D.R.
  • 2,540
  • 3
  • 24
  • 49