1
0
mirror of https://github.com/danog/amp.git synced 2024-12-03 18:07:57 +01:00
amp/test/DeferTest.php

30 lines
626 B
PHP
Raw Normal View History

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;
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;
defer(function () use ($exception): void {
throw $exception;
});
delay(0); // Tick event loop.
2020-10-04 17:22:21 +02:00
$this->assertSame($exception, $reason);
}
}