mirror of
https://github.com/danog/amp.git
synced 2024-12-11 17:09:40 +01:00
6d5e0f5ff7
Avoids creating unnecessary promise objects. delay(0) ticking the loop only once required using delay(x) instead of delay(0) in some tests.
30 lines
626 B
PHP
30 lines
626 B
PHP
<?php
|
|
|
|
namespace Amp\Test;
|
|
|
|
use Amp\Loop;
|
|
use Amp\PHPUnit\AsyncTestCase;
|
|
use Amp\PHPUnit\TestException;
|
|
use function Amp\defer;
|
|
use function Amp\delay;
|
|
|
|
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(1); // Tick event loop.
|
|
|
|
$this->assertSame($exception, $reason);
|
|
}
|
|
}
|