From aeb5de16d98f9338831abc16d8ad141137b23203 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Thu, 14 Mar 2019 22:31:27 +0100 Subject: [PATCH] Add failing Coroutine test --- test/CoroutineTest.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/CoroutineTest.php b/test/CoroutineTest.php index 4ca1401..ec11c40 100644 --- a/test/CoroutineTest.php +++ b/test/CoroutineTest.php @@ -13,6 +13,7 @@ use Amp\Success; use PHPUnit\Framework\TestCase; use React\Promise\FulfilledPromise as FulfilledReactPromise; use React\Promise\Promise as ReactPromise; +use function Amp\call; class CoroutineTest extends TestCase { @@ -476,6 +477,37 @@ class CoroutineTest extends TestCase $this->assertSame($exception, $reason); } + /** + * @depends testGeneratorThrowingExceptionWithFinallyFailsCoroutine + */ + public function testGeneratorThrowingExceptionWithFinallyBlockAndReturnThrowing() + { + $exception = new \Exception; + + $generator = function () use ($exception) { + yield new Success; + + return call(function () use ($exception) { + return new class($exception) + { + private $exception; + + public function __construct(\Throwable $exception) + { + $this->exception = $exception; + } + + public function __destruct() + { + throw $this->exception; + } + }; + }); + }; + + new Coroutine($generator()); + } + /** * @depends testYieldSuccessfulPromise */