2016-12-29 21:09:49 +01:00
|
|
|
<?php
|
2016-08-16 23:39:25 +02:00
|
|
|
|
2016-07-12 18:20:06 +02:00
|
|
|
namespace Amp\Test;
|
|
|
|
|
|
|
|
use Amp;
|
|
|
|
use Amp\Failure;
|
2017-03-10 21:31:57 +01:00
|
|
|
use Amp\Loop;
|
2016-07-12 18:20:06 +02:00
|
|
|
|
|
|
|
class RethrowTest extends \PHPUnit_Framework_TestCase {
|
2016-11-14 20:59:21 +01:00
|
|
|
public function testWaitOnPendingPromise() {
|
2016-07-12 18:20:06 +02:00
|
|
|
$exception = new \Exception;
|
|
|
|
|
|
|
|
try {
|
2017-03-10 21:31:57 +01:00
|
|
|
Loop::run(function () use ($exception) {
|
2016-11-14 20:59:21 +01:00
|
|
|
$promise = new Failure($exception);
|
2016-07-12 18:20:06 +02:00
|
|
|
|
2016-11-14 20:59:21 +01:00
|
|
|
Amp\rethrow($promise);
|
2016-07-12 18:20:06 +02:00
|
|
|
});
|
|
|
|
} catch (\Exception $reason) {
|
|
|
|
$this->assertSame($exception, $reason);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-14 20:59:21 +01:00
|
|
|
$this->fail('Failed promise reason should be thrown from loop');
|
2016-07-12 18:20:06 +02:00
|
|
|
}
|
|
|
|
}
|