2016-12-29 14:09:49 -06:00
|
|
|
<?php
|
2016-08-16 16:39:25 -05:00
|
|
|
|
2016-07-12 11:20:06 -05:00
|
|
|
namespace Amp\Test;
|
|
|
|
|
|
|
|
use Amp;
|
|
|
|
use Amp\Failure;
|
2017-03-10 21:31:57 +01:00
|
|
|
use Amp\Loop;
|
2017-03-12 22:09:19 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2017-03-12 23:27:43 -05:00
|
|
|
use function React\Promise\reject;
|
2016-07-12 11:20:06 -05:00
|
|
|
|
2017-03-12 22:09:19 +01:00
|
|
|
class RethrowTest extends TestCase {
|
2017-03-12 23:27:43 -05:00
|
|
|
public function testRethrow() {
|
2016-07-12 11:20:06 -05:00
|
|
|
$exception = new \Exception;
|
|
|
|
|
|
|
|
try {
|
2017-03-10 21:31:57 +01:00
|
|
|
Loop::run(function () use ($exception) {
|
2016-11-14 13:59:21 -06:00
|
|
|
$promise = new Failure($exception);
|
2016-07-12 11:20:06 -05:00
|
|
|
|
2016-11-14 13:59:21 -06:00
|
|
|
Amp\rethrow($promise);
|
2016-07-12 11:20:06 -05:00
|
|
|
});
|
|
|
|
} catch (\Exception $reason) {
|
|
|
|
$this->assertSame($exception, $reason);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-14 13:59:21 -06:00
|
|
|
$this->fail('Failed promise reason should be thrown from loop');
|
2016-07-12 11:20:06 -05:00
|
|
|
}
|
2017-03-12 23:27:43 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testRethrow
|
|
|
|
*/
|
|
|
|
public function testReactPromise() {
|
|
|
|
$exception = new \Exception;
|
|
|
|
|
|
|
|
try {
|
|
|
|
Loop::run(function () use ($exception) {
|
|
|
|
$promise = reject($exception);
|
|
|
|
|
|
|
|
Amp\rethrow($promise);
|
|
|
|
});
|
|
|
|
} catch (\Exception $reason) {
|
|
|
|
$this->assertSame($exception, $reason);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->fail('Failed promise reason should be thrown from loop');
|
|
|
|
}
|
2016-07-12 11:20:06 -05:00
|
|
|
}
|