title: How to test a method which takes a callable as argument with PhpUnit and Prophecy
body: <p>I'm using Guzzle's asynchronous request and have them implemented in a service that I would like to test now. </p>
  
  <p>My method looks like this (pseudo, so if it's not 100% valid, please excuse)</p>
  
  <pre><code>public function getPlayer(string $uiid, array &amp;$player = [])
  {
      $options['query'] = ['id' =&gt; $uiid];
  
      $promise = $this-&gt;requestAsync('GET', $this-&gt;endpoint, $options);
      $promise-&gt;then(function (ResponseInterface $response) use (&amp;$player) {
          $player = $response-&gt;getBody()-&gt;getContents();
      });
  
      return $players;
  }
  </code></pre>
  
  <p>Now I want to test it, but I don't really know how to mock the callable, because I'm always getting the error</p>
  
  <p><code>1) tzfrs\PlayerBundle\Tests\Api\Player\PlayerServiceTest::testGetPlayer
  Prophecy\Exception\InvalidArgumentException: Expected callable or instance of PromiseInterface, but got object.</code></p>
  
  <p>This is how I have it implemented currently</p>
  
  <pre><code>/** @var ObjectProphecy|PromiseInterface $response */
  $promise = $this-&gt;prophesize(PromiseInterface::class);
  
  $promise-&gt;then()-&gt;will($this-&gt;returnCallback(function (ResponseInterface $response) use (&amp;$player){}));
  </code></pre>
  
  <p>Didn't work. And this</p>
  
  <p><code>$this-&gt;returnCallback(function (ResponseInterface $response) use (&amp;$player){})</code></p>
  
  <p>didn't work either. Same error. And when simply trying a dummy callback</p>
  
  <p><code>$promise-&gt;then(function(){});</code></p>
  
  <p>I get the error <code>Error: Call to a member function then() on string</code>, even after <code>-&gt;reveal()</code>ing the promise first. Any ideas?</p>