mirror of
https://github.com/danog/amp.git
synced 2024-12-11 00:49:48 +01:00
57 lines
1.2 KiB
PHP
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);
|
|
}
|
|
}
|