mirror of
https://github.com/danog/amp.git
synced 2024-12-11 08:59:46 +01:00
c12828081f
This has been an edge case potentially hiding some exceptions. The tests have been refactored to error if the loop has watchers leaking from one test to another test.
57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Amp\Test;
|
|
|
|
use Amp\Failure;
|
|
use Amp\Loop;
|
|
use Amp\Promise;
|
|
use function React\Promise\reject;
|
|
|
|
class RethrowTest extends BaseTest
|
|
{
|
|
public function testRethrow()
|
|
{
|
|
$exception = new \Exception;
|
|
|
|
try {
|
|
Loop::run(function () use ($exception) {
|
|
$promise = new Failure($exception);
|
|
|
|
Promise\rethrow($promise);
|
|
});
|
|
} catch (\Exception $reason) {
|
|
$this->assertSame($exception, $reason);
|
|
return;
|
|
}
|
|
|
|
$this->fail('Failed promise reason should be thrown from loop');
|
|
}
|
|
|
|
/**
|
|
* @depends testRethrow
|
|
*/
|
|
public function testReactPromise()
|
|
{
|
|
$exception = new \Exception;
|
|
|
|
try {
|
|
Loop::run(function () use ($exception) {
|
|
$promise = reject($exception);
|
|
|
|
Promise\rethrow($promise);
|
|
});
|
|
} catch (\Exception $reason) {
|
|
$this->assertSame($exception, $reason);
|
|
return;
|
|
}
|
|
|
|
$this->fail('Failed promise reason should be thrown from loop');
|
|
}
|
|
|
|
public function testNonPromise()
|
|
{
|
|
$this->expectException(\TypeError::class);
|
|
Promise\rethrow(42);
|
|
}
|
|
}
|