From 4cdf5f23f9775c26ec9c2b516e7c65fd5857720c Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sat, 4 Sep 2021 19:12:18 -0700 Subject: [PATCH] Let LambdaRuntime::processNextEvent() return boolean --- src/Runtime/LambdaRuntime.php | 7 ++++++- tests/Runtime/LambdaRuntimeTest.php | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Runtime/LambdaRuntime.php b/src/Runtime/LambdaRuntime.php index a295e449d..0ad42b564 100755 --- a/src/Runtime/LambdaRuntime.php +++ b/src/Runtime/LambdaRuntime.php @@ -89,9 +89,10 @@ private function closeReturnHandler(): void * $lambdaRuntime->processNextEvent(function ($event, Context $context) { * return 'Hello ' . $event['name'] . '. We have ' . $context->getRemainingTimeInMillis()/1000 . ' seconds left'; * }); + * @return bool true if event was successfully handled * @throws Exception */ - public function processNextEvent($handler): void + public function processNextEvent($handler): bool { [$event, $context] = $this->waitNextInvocation(); \assert($context instanceof Context); @@ -104,7 +105,11 @@ public function processNextEvent($handler): void $this->sendResponse($context->getAwsRequestId(), $result); } catch (\Throwable $e) { $this->signalFailure($context->getAwsRequestId(), $e); + + return false; } + + return true; } /** diff --git a/tests/Runtime/LambdaRuntimeTest.php b/tests/Runtime/LambdaRuntimeTest.php index f72f0a56d..f91fd63c4 100644 --- a/tests/Runtime/LambdaRuntimeTest.php +++ b/tests/Runtime/LambdaRuntimeTest.php @@ -48,10 +48,11 @@ public function test basic behavior() { $this->givenAnEvent(['Hello' => 'world!']); - $this->runtime->processNextEvent(function () { + $output = $this->runtime->processNextEvent(function () { return ['hello' => 'world']; }); + $this->assertTrue($output); $this->assertInvocationResult(['hello' => 'world']); } @@ -73,10 +74,11 @@ public function test exceptions in the handler result in an invocation  { $this->givenAnEvent(['Hello' => 'world!']); - $this->runtime->processNextEvent(function () { + $output = $this->runtime->processNextEvent(function () { throw new \RuntimeException('This is an exception'); }); + $this->assertFalse($output); $this->assertInvocationErrorResult('RuntimeException', 'This is an exception'); $this->assertErrorInLogs('RuntimeException', 'This is an exception'); }