1
0
mirror of https://github.com/danog/amp.git synced 2024-12-11 17:09:40 +01:00
amp/test/WrapTest.php
2020-10-02 13:40:29 -05:00

43 lines
843 B
PHP

<?php
namespace Amp\Test;
use Amp\Deferred;
use Amp\PHPUnit\AsyncTestCase;
use Amp\Promise;
use function Amp\await;
class WrapTest extends AsyncTestCase
{
public function testSuccess(): void
{
$deferred = new Deferred();
$promise = Promise\wrap($deferred->promise(), function () {
return 2;
});
$deferred->resolve(1);
$result = await($promise);
$this->assertSame(2, $result);
}
public function testFailure(): void
{
$deferred = new Deferred();
$promise = Promise\wrap($deferred->promise(), function () {
throw new \Exception('bar');
});
$deferred->fail(new \Exception('foo'));
$this->expectException(\Exception::class);
$this->expectExceptionMessage('bar');
await($promise);
}
}