1
0
mirror of https://github.com/danog/amp.git synced 2024-12-02 17:37:50 +01:00
amp/test/RethrowTest.php
2020-10-02 13:40:29 -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\sleep;
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;
});
sleep(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;
});
sleep(0); // Tick the event loop.
$this->assertTrue($invoked);
$this->assertSame($reason, $exception);
}
}