From dfab1d885f5d8284e45bc9c26ccd8a2d667af0d7 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Tue, 14 Mar 2017 22:32:14 +0100 Subject: [PATCH] Add missing coroutine tests --- test/CoroutineTest.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/CoroutineTest.php b/test/CoroutineTest.php index 52fe59b..78aacf0 100644 --- a/test/CoroutineTest.php +++ b/test/CoroutineTest.php @@ -96,6 +96,40 @@ class CoroutineTest extends TestCase { }); } + public function testYieldPromiseArrayAfterPendingPromise() { + Loop::run(function () { + $value = 1; + + $generator = function () use (&$yielded, $value) { + yield new Pause(10); + list($yielded) = yield [ + new Success($value) + ]; + }; + + yield new Coroutine($generator()); + + $this->assertSame($value, $yielded); + }); + } + + public function testYieldNonPromiseArrayAfterPendingPromise() { + $this->expectException(InvalidYieldError::class); + + Loop::run(function () { + $value = 1; + + $generator = function () use (&$yielded, $value) { + yield new Pause(10); + list($yielded) = yield [ + $value + ]; + }; + + yield new Coroutine($generator()); + }); + } + /** * @depends testYieldFailedPromise */