Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
AsyncTestCase example with amphp
// We assume that your PHPUnit bootstrap will include the appropriate class loader and setup your environment
use Amp\Delayed;
use Amp\Promise;
use Amp\PHPUnit\AsyncTestCase;
use function Amp\call;
class AsyncTestSubject {
public function doSomething() : Promise {
return call(function() {
yield new Delayed(250); // emulate a network call
yield new Delayed(100); // emulate a call to a file system
return 'We did it!';
class AsyncTestExample extends AsyncTestCase {
public function testThatWeCanDoIt() {
$subject = new AsyncTestSubject();
$response = yield $subject->doSomething();
$this->assertSame('We did it!', $response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment