title: Testing async methods with PHPUnit
body: <p>I tried using a sleep and try approach. But it fails sometimes. What is the standard? Can't find anything obvious around. Thanks.</p>
  
  <pre><code>function foo($callback)
  {
      $bar-&gt;asyncCall($callback);
  }
  
  function testFoo()
  {
      $semaphore = 1;
      foo(function() {
          $semaphore = 0;
      });
      sleep(5) until $semaphore == 0;
  }
  </code></pre>
  
  <p>With this approach testFoo() sometimes never returns. I suspect a deadlock somewhere.</p>