1
0
mirror of https://github.com/danog/amp.git synced 2024-12-11 17:09:40 +01:00
amp/test/RethrowTest.php

57 lines
1.2 KiB
PHP
Raw Normal View History

<?php
2016-07-12 18:20:06 +02:00
namespace Amp\Test;
use Amp\Failure;
use Amp\Loop;
use Amp\Promise;
use function React\Promise\reject;
2016-07-12 18:20:06 +02:00
class RethrowTest extends BaseTest
2018-06-18 20:00:01 +02:00
{
public function testRethrow()
{
2016-07-12 18:20:06 +02:00
$exception = new \Exception;
try {
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
Promise\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
}
/**
* @depends testRethrow
*/
2018-06-18 20:00:01 +02:00
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');
}
2017-03-14 22:15:36 +01:00
2018-06-18 20:00:01 +02:00
public function testNonPromise()
{
2017-04-23 19:08:40 +02:00
$this->expectException(\TypeError::class);
Promise\rethrow(42);
2017-03-14 22:15:36 +01:00
}
2016-07-12 18:20:06 +02:00
}