1
0
mirror of https://github.com/danog/amp.git synced 2024-12-11 00:49:48 +01:00
amp/test/RethrowTest.php
2020-10-06 23:40:14 -05:00

57 lines
1.2 KiB
PHP

<?php
namespace Amp\Test;
use Amp\Failure;
use Amp\Loop;
use Amp\PHPUnit\AsyncTestCase;
use Amp\Promise;
use function React\Promise\reject;
use function Amp\delay;
class RethrowTest extends AsyncTestCase
{
public function testRethrow(): void
{
$exception = new \Exception;
$promise = new Failure($exception);
Promise\rethrow($promise);
$invoked = false;
Loop::setErrorHandler(function (\Throwable $exception) use (&$invoked, &$reason): void {
$invoked = true;
$reason = $exception;
});
delay(0); // Tick the event loop.
$this->assertTrue($invoked);
$this->assertSame($reason, $exception);
}
/**
* @depends testRethrow
*/
public function testReactPromise(): void
{
$exception = new \Exception;
$promise = reject($exception);
Promise\rethrow($promise);
$invoked = false;
Loop::setErrorHandler(function (\Throwable $exception) use (&$invoked, &$reason): void {
$invoked = true;
$reason = $exception;
});
delay(0); // Tick the event loop.
$this->assertTrue($invoked);
$this->assertSame($reason, $exception);
}
}