Skip to content

Instantly share code, notes, and snippets.

@cspray
Created February 9, 2019 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cspray/37d202324a3a7568d9415c3e66334ba6 to your computer and use it in GitHub Desktop.
Save cspray/37d202324a3a7568d9415c3e66334ba6 to your computer and use it in GitHub Desktop.
AsyncTestCase example with amphp
<?php
// 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