From e53b1ec93bb77383e292f2733bf0c247a637aa87 Mon Sep 17 00:00:00 2001 From: ssgoncalves Date: Mon, 10 Oct 2022 12:07:24 -0300 Subject: [PATCH] fix: add catch to any throwable in consumer manager --- src/Connectors/Consumer/Manager.php | 6 +-- src/TopicHandler/Consumer/AbstractHandler.php | 4 +- src/TopicHandler/Consumer/Handler.php | 4 +- tests/Integration/Dummies/MessageConsumer.php | 6 +-- .../Unit/Connectors/Consumer/ManagerTest.php | 46 +++++++++++++++++++ tests/Unit/Dummies/ConsumerHandlerDummy.php | 4 +- 6 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/Connectors/Consumer/Manager.php b/src/Connectors/Consumer/Manager.php index cc1b0de0..3e7b7d42 100644 --- a/src/Connectors/Consumer/Manager.php +++ b/src/Connectors/Consumer/Manager.php @@ -1,7 +1,6 @@ consumerHandler->warning($exception); return; - } catch (Exception $exception) { - $this->consumerHandler->failed($exception); + } catch (Throwable $throwable) { + $this->consumerHandler->failed($throwable); return; } diff --git a/src/TopicHandler/Consumer/AbstractHandler.php b/src/TopicHandler/Consumer/AbstractHandler.php index 73ad2307..d284b7aa 100644 --- a/src/TopicHandler/Consumer/AbstractHandler.php +++ b/src/TopicHandler/Consumer/AbstractHandler.php @@ -1,9 +1,9 @@ $exception, + 'exception' => $throwable, ]); } } diff --git a/tests/Unit/Connectors/Consumer/ManagerTest.php b/tests/Unit/Connectors/Consumer/ManagerTest.php index 1b740360..3d3f76d9 100644 --- a/tests/Unit/Connectors/Consumer/ManagerTest.php +++ b/tests/Unit/Connectors/Consumer/ManagerTest.php @@ -1,7 +1,9 @@ expects() + ->consume() + ->andThrow($throwable); + + $consumerHandler->expects() + ->failed($throwable); + + // Actions + $runner->handleMessage(); + } + public function testShouldHandleMultiplesMessages(): void { // Set @@ -171,4 +199,22 @@ public function testShouldHandleAsyncCommit(): void $runner->handleMessage(); $runner->handleMessage(); } + + public function getThrowableScenarios(): array + { + return [ + 'Exception' => [ + 'throwable' => new Exception(), + ], + 'Error' => [ + 'throwable' => new Error(), + ], + 'InvalidArgumentException' => [ + 'throwable' => new InvalidArgumentException(), + ], + 'TypeError' => [ + 'throwable' => new TypeError(), + ], + ]; + } } diff --git a/tests/Unit/Dummies/ConsumerHandlerDummy.php b/tests/Unit/Dummies/ConsumerHandlerDummy.php index 08eb14a0..52ffc955 100644 --- a/tests/Unit/Dummies/ConsumerHandlerDummy.php +++ b/tests/Unit/Dummies/ConsumerHandlerDummy.php @@ -1,9 +1,9 @@