title: Laravel - Cache test no matching handler for set
body: <p>In my Laravel application I have a service that uses <code>Cache</code> facade and executes a set, like this:</p>
  <pre><code>public function setCache(): void
  {
     Cache::set(&quot;my-key&quot;, &quot;my-val&quot;);
  
     // Other stuff
  
     Cache::delete(&quot;my-key&quot;);
  }
  </code></pre>
  <p>I would like to test that the cache is set, so I'm trying to use <code>shouldReceive</code> on <code>Cache</code> in my test</p>
  <pre><code>it('cache test', function() {
      Cache::shouldReceive(&quot;set&quot;)
          -&gt;once()
          -&gt;with(&quot;my-key&quot;)
          -&gt;andReturn(&quot;my-val&quot;);
  
     $service = new MyService();
     $service-&gt;setCache();
  });
  </code></pre>
  <p>After executing this method, I get this error:</p>
  <pre><code>Mockery\Exception\NoMatchingExpectationException : No matching handler found for Mockery_0_Illuminate_Cache_CacheManager::set('my-key', 'my-val'). Either the method was unexpected or its arguments matched no expected argument list for this method
  
  
   /var/www/html/vendor/mockery/mockery/library/Mockery/ExpectationDirector.php:92
   /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:261
  </code></pre>
  <p>Looking <a href="https://stackoverflow.com/questions/62512681/mocking-laravel-cache-helper">this</a> thread it seems that CacheManager dont have a set method, so i recreated my test as shown in this post, like so:</p>
  <pre><code>it(&quot;another test&quot;, function () {
      $cacheRepository = Cache::driver();
      $cacheRepositorySpy = \Mockery::spy($cacheRepository);
      Cache::swap($cacheRepositorySpy);
  
      $service = new MyService();
      $service-&gt;setCache();
  
      $cacheRepositorySpy
          -&gt;shouldHaveReceived(&quot;set&quot;)
          -&gt;once()
          -&gt;with(&quot;my-key&quot;, \Closure::class)
          -&gt;andReturns(&quot;my-val&quot;);
  });
  </code></pre>
  <p>And, with this I get another error:</p>
  <pre><code>Mockery\Exception\InvalidCountException : Method set(&lt;Any Arguments&gt;) from Mockery_0_Illuminate_Cache_Repository_Illuminate_Cache_Repository should be called
   exactly 1 times but called 0 times.
  </code></pre>
  <p>How I can make an assertion that tests the cache as shown above?</p>