From 6f4433dd1c0e2d5b5f094abc785021a6a3422f0b Mon Sep 17 00:00:00 2001 From: Chris Wright Date: Wed, 11 May 2016 18:07:44 +0100 Subject: [PATCH] Add tests for resolve callables --- test/FunctionsTest.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/FunctionsTest.php b/test/FunctionsTest.php index 08316c4d..5a2c61b0 100644 --- a/test/FunctionsTest.php +++ b/test/FunctionsTest.php @@ -742,6 +742,35 @@ public function testCoroutineFauxReturnValue() { $this->assertSame(1, $invoked); } + public function testResolveAcceptsGeneratorCallable() { + \Amp\run(function() { + $result = (yield \Amp\resolve(function () { + yield new CoroutineResult(42); + })); + $this->assertSame(42, $result); + }); + } + + /** + * @expectedException \LogicException + */ + public function testResolveNonGeneratorCallableThrows() { + \Amp\run(function() { + yield \Amp\resolve(function () { + return 42; + }); + }); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testResolveInvalidArgumentThrows() { + \Amp\run(function() { + yield \Amp\resolve(42); + }); + } + public function testResolutionFailuresAreThrownIntoGeneratorCoroutine() { $invoked = 0; \Amp\run(function () use (&$invoked) {