From 574c695334992b044b947adbcf41096e8dce3caf Mon Sep 17 00:00:00 2001 From: Ken Ngo Date: Mon, 5 Sep 2022 14:03:00 +1000 Subject: [PATCH] refactor: rename ConsumerException to ProcessorException --- README.md | 2 +- samples/TaskService/TaskApp.php | 2 +- ...erException.php => ProcessorException.php} | 2 +- src/Processor.php | 22 ++++----- src/ProcessorInterface.php | 4 +- tests/ConsumerTest.php | 48 +++++++++---------- 6 files changed, 40 insertions(+), 40 deletions(-) rename src/Exceptions/{ConsumerException.php => ProcessorException.php} (89%) diff --git a/README.md b/README.md index 0530ab9..235b2d3 100644 --- a/README.md +++ b/README.md @@ -291,7 +291,7 @@ class TaskApp } /** - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException diff --git a/samples/TaskService/TaskApp.php b/samples/TaskService/TaskApp.php index f423e40..cea09f7 100644 --- a/samples/TaskService/TaskApp.php +++ b/samples/TaskService/TaskApp.php @@ -33,7 +33,7 @@ public function __construct(Broker $broker = null) } /** - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException diff --git a/src/Exceptions/ConsumerException.php b/src/Exceptions/ProcessorException.php similarity index 89% rename from src/Exceptions/ConsumerException.php rename to src/Exceptions/ProcessorException.php index 321b2c0..3dc4f8c 100644 --- a/src/Exceptions/ConsumerException.php +++ b/src/Exceptions/ProcessorException.php @@ -2,7 +2,7 @@ namespace Micronative\EventSchema\Exceptions; -class ConsumerException extends ServiceSchemaException +class ProcessorException extends ServiceSchemaException { const FAILED_TO_CREATE_MESSAGE = "Failed to create message from json string: "; const EMPTY_EVENT_NAME = "Event name is empty."; diff --git a/src/Processor.php b/src/Processor.php index 8eb5cb9..a93ed6a 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -9,7 +9,7 @@ use Micronative\EventSchema\Config\Consumer\ServiceConfigRegister; use Micronative\EventSchema\Event\AbstractEvent; use Micronative\EventSchema\Event\EventValidator; -use Micronative\EventSchema\Exceptions\ConsumerException; +use Micronative\EventSchema\Exceptions\ProcessorException; use Micronative\EventSchema\Json\JsonReader; use Micronative\EventSchema\Service\RollbackInterface; use Micronative\EventSchema\Service\ServiceFactory; @@ -54,7 +54,7 @@ public function __construct( * @param \Micronative\EventSchema\Event\AbstractEvent|null $event * @param array|null $filteredEvents * @return bool - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException @@ -83,7 +83,7 @@ public function process(?AbstractEvent $event = null, ?array $filteredEvents = n * @param \Micronative\EventSchema\Event\AbstractEvent $event * @param array|null $filteredEvents * @return bool - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException @@ -122,32 +122,32 @@ private function loadConfigs() /** * @param \Micronative\EventSchema\Event\AbstractEvent $event * @param array|null $filteredEvents - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException */ private function checkFilteredEvents(AbstractEvent $event, ?array $filteredEvents = null) { if(empty($event->getName())){ - throw new ConsumerException(ConsumerException::EMPTY_EVENT_NAME); + throw new ProcessorException(ProcessorException::EMPTY_EVENT_NAME); } if (!empty($filteredEvents) && !in_array($event->getName(), $filteredEvents)) { - throw new ConsumerException(ConsumerException::FILTERED_EVENT_ONLY . JsonReader::encode($filteredEvents)); + throw new ProcessorException(ProcessorException::FILTERED_EVENT_ONLY . JsonReader::encode($filteredEvents)); } } /** * @param \Micronative\EventSchema\Event\AbstractEvent $event * @return string[] - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException */ private function retrieveServiceClasses(AbstractEvent $event) { /** @var \Micronative\EventSchema\Config\Consumer\EventConfig $eventConfig */ $eventConfig = $this->eventConfigRegister->retrieveEventConfig($event->getName(), $event->getVersion()); if (empty($eventConfig)) { - throw new ConsumerException( - sprintf(ConsumerException::NO_REGISTER_EVENTS, $event->getName(), $event->getVersion()) + throw new ProcessorException( + sprintf(ProcessorException::NO_REGISTER_EVENTS, $event->getName(), $event->getVersion()) ); } @@ -156,8 +156,8 @@ private function retrieveServiceClasses(AbstractEvent $event) */ $event->setSchemaFile($eventConfig->getSchemaFile()); if (empty($serviceClasses = $eventConfig->getServiceClasses())) { - throw new ConsumerException( - sprintf(ConsumerException::NO_REGISTER_SERVICES, $event->getName(), $event->getVersion()) + throw new ProcessorException( + sprintf(ProcessorException::NO_REGISTER_SERVICES, $event->getName(), $event->getVersion()) ); } diff --git a/src/ProcessorInterface.php b/src/ProcessorInterface.php index 8401cbf..ba4294e 100644 --- a/src/ProcessorInterface.php +++ b/src/ProcessorInterface.php @@ -12,7 +12,7 @@ interface ProcessorInterface * @return bool * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException */ public function process(AbstractEvent $event, array $filteredEvents = null); @@ -21,7 +21,7 @@ public function process(AbstractEvent $event, array $filteredEvents = null); * @param array|null $filteredEvents * @return bool * @throws \Micronative\EventSchema\Exceptions\JsonException - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException */ public function rollback(AbstractEvent $event, array $filteredEvents = null); } diff --git a/tests/ConsumerTest.php b/tests/ConsumerTest.php index c064e59..c042b34 100644 --- a/tests/ConsumerTest.php +++ b/tests/ConsumerTest.php @@ -7,7 +7,7 @@ use Micronative\EventSchema\Processor; use Micronative\EventSchema\Event\AbstractEvent; use Micronative\EventSchema\Event\EventValidator; -use Micronative\EventSchema\Exceptions\ConsumerException; +use Micronative\EventSchema\Exceptions\ProcessorException; use Micronative\EventSchema\Exceptions\ValidatorException; use Micronative\EventSchema\Json\JsonReader; use Micronative\EventSchema\Service\ServiceFactory; @@ -36,7 +36,7 @@ public function setUp(): void } /** - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException @@ -54,7 +54,7 @@ public function testProcess() /** * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\JsonException - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException */ public function testProcessFailed() { @@ -68,7 +68,7 @@ public function testProcessFailed() } /** - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException @@ -79,13 +79,13 @@ public function testProcessWithFilteredEvent() JsonReader::read($this->testDir . "/assets/events/Users.Created.event.json") ); $event = new SampleEvent($data->name, null, $data->id, (array)$data->payload); - $this->expectException(ConsumerException::class); - $this->expectExceptionMessageMatches('%' . ConsumerException::FILTERED_EVENT_ONLY . '%'); + $this->expectException(ProcessorException::class); + $this->expectExceptionMessageMatches('%' . ProcessorException::FILTERED_EVENT_ONLY . '%'); $this->consumer->process($event, ['EventOne', 'EventTwo']); } /** - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException @@ -94,15 +94,15 @@ public function testProcessWithNoneRegisteredEvent() { $data = JsonReader::decode(JsonReader::read($this->testDir . "/assets/events/None.Registered.Event.json")); $event = new SampleEvent($data->name, null, $data->id ?? null, (array)$data->payload); - $this->expectException(ConsumerException::class); + $this->expectException(ProcessorException::class); $this->expectExceptionMessage( - sprintf(ConsumerException::NO_REGISTER_EVENTS, $event->getName(), $event->getVersion()) + sprintf(ProcessorException::NO_REGISTER_EVENTS, $event->getName(), $event->getVersion()) ); $this->consumer->process($event); } /** - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException @@ -111,15 +111,15 @@ public function testProcessWithEmptyServiceEvent() { $data = JsonReader::decode(JsonReader::read($this->testDir . "/assets/events/Empty.Service.Event.json")); $event = new SampleEvent('Empty.Service.Event', null, $data->id ?? null, (array)$data->payload); - $this->expectException(ConsumerException::class); + $this->expectException(ProcessorException::class); $this->expectExceptionMessage( - sprintf(ConsumerException::NO_REGISTER_SERVICES, $event->getName(), $event->getVersion()) + sprintf(ProcessorException::NO_REGISTER_SERVICES, $event->getName(), $event->getVersion()) ); $this->consumer->process($event); } /** - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException @@ -134,7 +134,7 @@ public function testProcessWithNoneExistingServiceEvent() } /** - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException @@ -149,7 +149,7 @@ public function testProcessWithInvalidServiceClass() } /** - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException @@ -167,7 +167,7 @@ public function testRollback() /** * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\JsonException - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException */ public function testRollbackWithInvalidValidation() { @@ -181,7 +181,7 @@ public function testRollbackWithInvalidValidation() } /** - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException @@ -196,7 +196,7 @@ public function testRollbackWithInvalidServiceClass() } /** - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException @@ -211,7 +211,7 @@ public function testRollbackWithNoneExistingServiceEvent() } /** - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException @@ -220,15 +220,15 @@ public function testRollbackWithEmptyServiceEvent() { $data = JsonReader::decode(JsonReader::read($this->testDir . "/assets/events/Empty.Service.Event.json")); $event = new SampleEvent($data->name, null, $data->id ?? null, (array)$data->payload); - $this->expectException(ConsumerException::class); + $this->expectException(ProcessorException::class); $this->expectExceptionMessage( - sprintf(ConsumerException::NO_REGISTER_SERVICES, $event->getName(), $event->getVersion()) + sprintf(ProcessorException::NO_REGISTER_SERVICES, $event->getName(), $event->getVersion()) ); $this->consumer->rollback($event); } /** - * @throws \Micronative\EventSchema\Exceptions\ConsumerException + * @throws \Micronative\EventSchema\Exceptions\ProcessorException * @throws \Micronative\EventSchema\Exceptions\JsonException * @throws \Micronative\EventSchema\Exceptions\ServiceException * @throws \Micronative\EventSchema\Exceptions\ValidatorException @@ -237,9 +237,9 @@ public function testRollbackWithNoneRegisteredEvent() { $data = JsonReader::decode(JsonReader::read($this->testDir . "/assets/events/None.Registered.Event.json")); $event = new SampleEvent($data->name, null, $data->id, (array)$data->payload); - $this->expectException(ConsumerException::class); + $this->expectException(ProcessorException::class); $this->expectExceptionMessage( - sprintf(ConsumerException::NO_REGISTER_EVENTS, $event->getName(), $event->getVersion()) + sprintf(ProcessorException::NO_REGISTER_EVENTS, $event->getName(), $event->getVersion()) ); $this->consumer->rollback($event); }