Created
February 9, 2019 15:52
-
-
Save cspray/37d202324a3a7568d9415c3e66334ba6 to your computer and use it in GitHub Desktop.
AsyncTestCase example with amphp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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