2020-10-04 17:22:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp\Test;
|
|
|
|
|
|
|
|
use Amp\Loop;
|
|
|
|
use Amp\PHPUnit\AsyncTestCase;
|
|
|
|
use Amp\PHPUnit\TestException;
|
|
|
|
use function Amp\defer;
|
2020-10-07 06:40:14 +02:00
|
|
|
use function Amp\delay;
|
2020-10-04 17:22:21 +02:00
|
|
|
|
|
|
|
class DeferTest extends AsyncTestCase
|
|
|
|
{
|
|
|
|
public function testExceptionsRethrownToLoopHandler(): void
|
|
|
|
{
|
|
|
|
Loop::setErrorHandler(function (\Throwable $exception) use (&$reason): void {
|
|
|
|
$reason = $exception;
|
|
|
|
});
|
|
|
|
|
|
|
|
$exception = new TestException;
|
|
|
|
|
2020-11-30 05:36:55 +01:00
|
|
|
defer(fn() => throw $exception);
|
2020-10-04 17:22:21 +02:00
|
|
|
|
2020-11-30 05:36:55 +01:00
|
|
|
delay(5); // Tick event loop.
|
2020-10-04 17:22:21 +02:00
|
|
|
|
|
|
|
$this->assertSame($exception, $reason);
|
|
|
|
}
|
|
|
|
}
|