1
0
mirror of https://github.com/danog/amp.git synced 2024-12-04 10:28:01 +01:00
amp/test/RethrowTest.php

33 lines
698 B
PHP
Raw Normal View History

<?php
2016-07-12 18:20:06 +02:00
namespace Amp\Test;
use Amp\Failure;
2020-09-28 05:19:52 +02:00
use Amp\PHPUnit\AsyncTestCase;
use Amp\Promise;
2021-03-26 22:34:32 +01:00
use Revolt\EventLoop\Loop;
use function Revolt\EventLoop\delay;
2016-07-12 18:20:06 +02:00
2020-09-28 05:19:52 +02:00
class RethrowTest extends AsyncTestCase
2018-06-18 20:00:01 +02:00
{
2020-09-28 05:19:52 +02:00
public function testRethrow(): void
2018-06-18 20:00:01 +02:00
{
2016-07-12 18:20:06 +02:00
$exception = new \Exception;
2020-09-28 05:19:52 +02:00
$promise = new Failure($exception);
2016-07-12 18:20:06 +02:00
2020-09-28 05:19:52 +02:00
Promise\rethrow($promise);
2016-07-12 18:20:06 +02:00
2020-09-28 05:19:52 +02:00
$invoked = false;
Loop::setErrorHandler(function (\Throwable $exception) use (&$invoked, &$reason): void {
$invoked = true;
$reason = $exception;
});
delay(0); // Tick the event loop.
2020-09-28 05:19:52 +02:00
2021-03-26 22:34:32 +01:00
self::assertTrue($invoked);
self::assertSame($reason, $exception);
2016-07-12 18:20:06 +02:00
}
}