0

I'm using Mockery with Laravel 5.6. And currently I need to check what has been passed on the 100-th call.

Here is an example check, that I want to perform.

Mockery::mock(ShopifySDK::class)
       ->shouldReceive('get')
       ->with(['key' => 'val']) //I need to check passed array on the 100-th call of the "get" method
       ->getMock();

Is it possible to do it? If it is, then how to do it?

D.R.
  • 2,540
  • 3
  • 24
  • 49
  • Not sure if https://stackoverflow.com/questions/50900843/how-to-throw-an-exception-on-the-nth-call-of-a-mock-method-with-mockery may help, but worth a try. – Nigel Ren Jul 15 '18 at 14:29
  • @NigelRen looks like, but is there any other...more "native" way to do it? – D.R. Jul 15 '18 at 16:50

1 Answers1

0

Thanks to @NigelRen This is the solution I found. A little bit ugly, but good enough for me.

Mockery::mock(ShopifySDK::class)
       ->shouldReceive('get')
       ->withArgs(function ($params) {
           static $counter = 0;

           if ($counter++ === 100) {
               //checks...

               return true;
           }

           return false;
       })->getMock();
D.R.
  • 2,540
  • 3
  • 24
  • 49