diff --git a/composer.json b/composer.json index 339f2b5..322d3c7 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "require": { "php": "^8.0", "era269/message-processor": "^0.4.0", - "era269/normalizable": "^0.5", + "era269/normalizable": "^0.6.0", "psr/event-dispatcher": "^1.0" }, "require-dev": { diff --git a/example/Application/Port/NotebooksPort.php b/example/Application/Port/NotebooksPort.php index 9bd8b26..3638202 100644 --- a/example/Application/Port/NotebooksPort.php +++ b/example/Application/Port/NotebooksPort.php @@ -11,14 +11,15 @@ use Era269\Microobject\Example\Domain\Message\Notebook\Query\GetNotebookQuery; use Era269\Microobject\Example\Domain\Notebook\NotebookCollectionFactory; use Era269\Microobject\Exception\MicroobjectExceptionInterface; +use Era269\Normalizable\NormalizerInterface; final class NotebooksPort { - private NotebookCollectionFactory $notebookCollectionFactory; - - public function __construct(NotebookCollectionFactory $notebookCollectionFactory) + public function __construct( + private NotebookCollectionFactory $notebookCollectionFactory, + private NormalizerInterface $normalizer + ) { - $this->notebookCollectionFactory = $notebookCollectionFactory; } /** @@ -26,9 +27,7 @@ public function __construct(NotebookCollectionFactory $notebookCollectionFactory * * @param array $request * - * @return array - * - * @throws MicroobjectExceptionInterface + * @return array */ public function addNotebook(array $request): array { @@ -45,9 +44,7 @@ public function addNotebook(array $request): array * * @param array $request * - * @return array - * - * @throws MicroobjectExceptionInterface + * @return array */ public function addPage(array $request): array { @@ -64,9 +61,7 @@ public function addPage(array $request): array * * @param array $request * - * @return array - * - * @throws MicroobjectExceptionInterface + * @return array */ public function addLine(array $request): array { @@ -83,9 +78,7 @@ public function addLine(array $request): array * * @param array $request * - * @return array - * - * @throws MicroobjectExceptionInterface + * @return array */ public function getText(array $request): array { @@ -102,9 +95,7 @@ public function getText(array $request): array * * @param array $request * - * @return array - * - * @throws MicroobjectExceptionInterface + * @return array */ public function getPage(array $request): array { @@ -121,9 +112,7 @@ public function getPage(array $request): array * * @param array $request * - * @return array - * - * @throws MicroobjectExceptionInterface + * @return array */ public function getNotebook(array $request): array { diff --git a/example/Domain/Message/AbstractMessage.php b/example/Domain/Message/AbstractMessage.php index 7ebe758..8dff504 100644 --- a/example/Domain/Message/AbstractMessage.php +++ b/example/Domain/Message/AbstractMessage.php @@ -6,23 +6,15 @@ use Era269\Microobject\MessageInterface; use Era269\Microobject\Traits\MessageTrait; -use ReflectionClass; +use Era269\Normalizable\Traits\NormalizableTrait; abstract class AbstractMessage implements MessageInterface { use MessageTrait; + use NormalizableTrait; public function __construct() { $this->setId(MessageId::generate()); } - - /** - * @inheritDoc - */ - public function getType(): string - { - return (new ReflectionClass(static::class)) - ->getShortName(); - } } diff --git a/example/Domain/Message/Notebook/Command/CreateNotebookCommand.php b/example/Domain/Message/Notebook/Command/CreateNotebookCommand.php index c4b2a93..41de31d 100644 --- a/example/Domain/Message/Notebook/Command/CreateNotebookCommand.php +++ b/example/Domain/Message/Notebook/Command/CreateNotebookCommand.php @@ -8,14 +8,16 @@ use Era269\Microobject\Example\Domain\Notebook\NotebookIdAwareInterface; use Era269\Microobject\Example\Domain\Notebook\Traits\NotebookIdAwareTrait; use Era269\Normalizable\DenormalizableInterface; +use Era269\Normalizable\Traits\NormalizableTrait; final class CreateNotebookCommand extends AbstractNotebookCollectionMessage implements NotebookIdAwareInterface, DenormalizableInterface { use NotebookIdAwareTrait; + use NormalizableTrait; public function __construct( NotebookId $notebookId, - protected string $notebookName + private string $notebookName ) { parent::__construct(); diff --git a/example/Domain/Message/Notebook/Event/NotebookCreatedEvent.php b/example/Domain/Message/Notebook/Event/NotebookCreatedEvent.php index baf4a81..605d57f 100644 --- a/example/Domain/Message/Notebook/Event/NotebookCreatedEvent.php +++ b/example/Domain/Message/Notebook/Event/NotebookCreatedEvent.php @@ -5,6 +5,7 @@ use Era269\Microobject\Example\Domain\Message\Notebook\AbstractNotebookMessage; use Era269\Microobject\Example\Domain\Message\Notebook\Command\CreateNotebookCommand; +use Era269\Normalizable\Traits\NormalizableTrait; use Era269\Microobject\Example\Domain\Message\Traits\OccurredAtAwareTrait; use Era269\Microobject\IdentifierInterface; use Era269\Microobject\Message\EventInterface; @@ -12,8 +13,9 @@ final class NotebookCreatedEvent extends AbstractNotebookMessage implements EventInterface { use OccurredAtAwareTrait; + use NormalizableTrait; - protected string $notebookName; + private string $notebookName; public function __construct(CreateNotebookCommand $command) { diff --git a/example/Domain/Message/Notebook/Page/AbstractPageCollectionMessage.php b/example/Domain/Message/Notebook/Page/AbstractPageCollectionMessage.php index 7a77b9f..135b9ae 100644 --- a/example/Domain/Message/Notebook/Page/AbstractPageCollectionMessage.php +++ b/example/Domain/Message/Notebook/Page/AbstractPageCollectionMessage.php @@ -6,10 +6,12 @@ use Era269\Microobject\Example\Domain\Message\AbstractMessage; use Era269\Microobject\Example\Domain\Notebook\NotebookId; use Era269\Microobject\Example\Domain\Notebook\Traits\NotebookIdAwareTrait; +use Era269\Normalizable\Traits\NormalizableTrait; abstract class AbstractPageCollectionMessage extends AbstractMessage implements PageCollectionMessageInterface { use NotebookIdAwareTrait; + use NormalizableTrait; public function __construct(NotebookId $notebookId) { diff --git a/example/Domain/Message/Notebook/Page/AbstractPageMessage.php b/example/Domain/Message/Notebook/Page/AbstractPageMessage.php index 29c6ce5..2eeaf75 100644 --- a/example/Domain/Message/Notebook/Page/AbstractPageMessage.php +++ b/example/Domain/Message/Notebook/Page/AbstractPageMessage.php @@ -6,10 +6,12 @@ use Era269\Microobject\Example\Domain\Notebook\NotebookId; use Era269\Microobject\Example\Domain\Notebook\Page\PageId; use Era269\Microobject\Example\Domain\Notebook\Page\Traits\PageIdAwareTrait; +use Era269\Normalizable\Traits\NormalizableTrait; abstract class AbstractPageMessage extends AbstractPageCollectionMessage implements PageMessageInterface { use PageIdAwareTrait; + use NormalizableTrait; public function __construct(NotebookId $notebookId, PageId $pageId) { diff --git a/example/Domain/Message/Notebook/Page/Command/AddLineCommand.php b/example/Domain/Message/Notebook/Page/Command/AddLineCommand.php index 08602c8..6cad65b 100644 --- a/example/Domain/Message/Notebook/Page/Command/AddLineCommand.php +++ b/example/Domain/Message/Notebook/Page/Command/AddLineCommand.php @@ -9,13 +9,16 @@ use Era269\Microobject\Example\Domain\Notebook\NotebookId; use Era269\Microobject\Example\Domain\Notebook\Page\PageId; use Era269\Normalizable\DenormalizableInterface; +use Era269\Normalizable\Traits\NormalizableTrait; final class AddLineCommand extends AbstractPageMessage implements CommandInterface, DenormalizableInterface { + use NormalizableTrait; + public function __construct( NotebookId $notebookId, PageId $pageId, - protected string $line, + private string $line, ) { parent::__construct($notebookId, $pageId); diff --git a/example/Domain/Message/Notebook/Page/Command/CreatePageCommand.php b/example/Domain/Message/Notebook/Page/Command/CreatePageCommand.php index 4149ce8..21d841f 100644 --- a/example/Domain/Message/Notebook/Page/Command/CreatePageCommand.php +++ b/example/Domain/Message/Notebook/Page/Command/CreatePageCommand.php @@ -9,15 +9,17 @@ use Era269\Microobject\Example\Domain\Notebook\Page\Text; use Era269\Microobject\Example\Domain\Notebook\Page\Traits\PageIdAwareTrait; use Era269\Normalizable\DenormalizableInterface; +use Era269\Normalizable\Traits\NormalizableTrait; final class CreatePageCommand extends AbstractPageCollectionMessage implements DenormalizableInterface { use PageIdAwareTrait; + use NormalizableTrait; public function __construct( NotebookId $notebookId, PageId $pageId, - protected Text $text, + private Text $text, ) { parent::__construct($notebookId); diff --git a/example/Domain/Message/Notebook/Page/Event/LineAddedEvent.php b/example/Domain/Message/Notebook/Page/Event/LineAddedEvent.php index e304744..5da1345 100644 --- a/example/Domain/Message/Notebook/Page/Event/LineAddedEvent.php +++ b/example/Domain/Message/Notebook/Page/Event/LineAddedEvent.php @@ -5,6 +5,7 @@ use Era269\Microobject\Example\Domain\Message\Notebook\Page\AbstractPageMessage; use Era269\Microobject\Example\Domain\Message\Notebook\Page\Command\AddLineCommand; +use Era269\Normalizable\Traits\NormalizableTrait; use Era269\Microobject\Example\Domain\Message\Traits\OccurredAtAwareTrait; use Era269\Microobject\IdentifierInterface; use Era269\Microobject\Message\EventInterface; @@ -12,8 +13,9 @@ final class LineAddedEvent extends AbstractPageMessage implements EventInterface { use OccurredAtAwareTrait; + use NormalizableTrait; - protected string $line; + private string $line; public function __construct(AddLineCommand $command) { diff --git a/example/Domain/Message/Notebook/Page/Event/PageCreatedEvent.php b/example/Domain/Message/Notebook/Page/Event/PageCreatedEvent.php index 46bb702..fc0eb58 100644 --- a/example/Domain/Message/Notebook/Page/Event/PageCreatedEvent.php +++ b/example/Domain/Message/Notebook/Page/Event/PageCreatedEvent.php @@ -14,7 +14,7 @@ final class PageCreatedEvent extends AbstractPageMessage implements EventInterfa { use OccurredAtAwareTrait; - protected Text $text; + private Text $text; public function __construct( CreatePageCommand $command diff --git a/example/Domain/Message/Notebook/Page/Query/GetPageQuery.php b/example/Domain/Message/Notebook/Page/Query/GetPageQuery.php index e67a13b..b747842 100644 --- a/example/Domain/Message/Notebook/Page/Query/GetPageQuery.php +++ b/example/Domain/Message/Notebook/Page/Query/GetPageQuery.php @@ -4,6 +4,7 @@ namespace Era269\Microobject\Example\Domain\Message\Notebook\Page\Query; use Era269\Microobject\Example\Domain\Message\Notebook\Page\AbstractPageCollectionMessage; +use Era269\Normalizable\Traits\NormalizableTrait; use Era269\Microobject\Example\Domain\Notebook\NotebookId; use Era269\Microobject\Example\Domain\Notebook\Page\PageId; use Era269\Microobject\Example\Domain\Notebook\Page\PageIdAwareInterface; @@ -13,6 +14,7 @@ final class GetPageQuery extends AbstractPageCollectionMessage implements PageIdAwareInterface, DenormalizableInterface { use PageIdAwareTrait; + use NormalizableTrait; public function __construct(NotebookId $notebookId, PageId $pageId) { diff --git a/example/Domain/Message/Notebook/Query/GetNotebookQuery.php b/example/Domain/Message/Notebook/Query/GetNotebookQuery.php index d7f098d..c11ca40 100644 --- a/example/Domain/Message/Notebook/Query/GetNotebookQuery.php +++ b/example/Domain/Message/Notebook/Query/GetNotebookQuery.php @@ -4,6 +4,7 @@ namespace Era269\Microobject\Example\Domain\Message\Notebook\Query; use Era269\Microobject\Example\Domain\Message\Notebook\AbstractNotebookCollectionMessage; +use Era269\Normalizable\Traits\NormalizableTrait; use Era269\Microobject\Example\Domain\Notebook\NotebookId; use Era269\Microobject\Example\Domain\Notebook\NotebookIdAwareInterface; use Era269\Microobject\Example\Domain\Notebook\Traits\NotebookIdAwareTrait; @@ -12,6 +13,7 @@ final class GetNotebookQuery extends AbstractNotebookCollectionMessage implements NotebookIdAwareInterface, DenormalizableInterface { use NotebookIdAwareTrait; + use NormalizableTrait; public function __construct(NotebookId $notebookId) { diff --git a/example/Domain/NormalizableInterface.php b/example/Domain/NormalizableInterface.php new file mode 100644 index 0000000..c8f0768 --- /dev/null +++ b/example/Domain/NormalizableInterface.php @@ -0,0 +1,11 @@ +process($message); } - /** - * @inheritDoc - */ - protected function getNormalized(): array - { - return [ - 'id' => $this->getId()->normalize(), - 'name' => $this->name, - ]; - } - /** * @inheritDoc */ diff --git a/example/Domain/Notebook/Page.php b/example/Domain/Notebook/Page.php index 63fc217..bb8e35c 100644 --- a/example/Domain/Notebook/Page.php +++ b/example/Domain/Notebook/Page.php @@ -15,10 +15,13 @@ use Era269\Microobject\Example\Domain\Notebook\Page\Text; use Era269\Microobject\Message\Event\EventStreamInterface; use Era269\Microobject\Message\EventInterface; +use Era269\Normalizable\Traits\NormalizableTrait; use Psr\EventDispatcher\EventDispatcherInterface; final class Page extends AbstractMicroobject implements PageInterface { + use NormalizableTrait; + private PageId $id; private Text $text; @@ -91,17 +94,6 @@ protected function applyPageCreatedEvent(PageCreatedEvent $event): void $this->text = $event->getText(); } - /** - * @inheritDoc - */ - protected function getNormalized(): array - { - return [ - 'id' => $this->getId()->normalize(), - 'text' => $this->text->normalize(), - ]; - } - public function getId(): PageId { return $this->id; diff --git a/example/Domain/Notebook/Page/Text.php b/example/Domain/Notebook/Page/Text.php index c0613c0..2b2eafe 100644 --- a/example/Domain/Notebook/Page/Text.php +++ b/example/Domain/Notebook/Page/Text.php @@ -4,11 +4,14 @@ namespace Era269\Microobject\Example\Domain\Notebook\Page; -use Era269\Normalizable\Abstraction\AbstractNormalizable; +use Era269\Microobject\Example\Domain\NormalizableInterface; +use Era269\Normalizable\Traits\NormalizableTrait; use Stringable; -final class Text extends AbstractNormalizable implements Stringable +final class Text implements Stringable, NormalizableInterface { + use NormalizableTrait; + /** * @var string[] */ @@ -32,15 +35,8 @@ public function withLine(string $line): self /** * @inheritDoc */ - public function __toString() + public function __toString(): string { return implode("\n", $this->lines); } - - protected function getNormalized(): array - { - return [ - 'lines' => $this->lines, - ]; - } } diff --git a/example/Domain/Notebook/Page/Traits/PageIdAwareTrait.php b/example/Domain/Notebook/Page/Traits/PageIdAwareTrait.php index 04af061..42855f2 100644 --- a/example/Domain/Notebook/Page/Traits/PageIdAwareTrait.php +++ b/example/Domain/Notebook/Page/Traits/PageIdAwareTrait.php @@ -7,7 +7,7 @@ trait PageIdAwareTrait { - protected PageId $pageId; + private PageId $pageId; public function getPageId(): PageId { diff --git a/example/Domain/Notebook/PageCollection.php b/example/Domain/Notebook/PageCollection.php index 5813f42..4a3c951 100644 --- a/example/Domain/Notebook/PageCollection.php +++ b/example/Domain/Notebook/PageCollection.php @@ -55,4 +55,12 @@ public function processPageMessages(PageMessageInterface $message): MessageInter return $this->repository->get($message->getPageId()) ->process($message); } + + /** + * @inheritDoc + */ + public function normalize(): array + { + return []; + } } diff --git a/example/Domain/Notebook/PageCollectionInterface.php b/example/Domain/Notebook/PageCollectionInterface.php index 6947c08..d7fda93 100644 --- a/example/Domain/Notebook/PageCollectionInterface.php +++ b/example/Domain/Notebook/PageCollectionInterface.php @@ -8,8 +8,9 @@ use Era269\Microobject\Example\Domain\Message\Notebook\Page\Query\GetPageQuery; use Era269\Microobject\MessageInterface; use Era269\Microobject\MicroobjectCollectionInterface; +use Era269\Normalizable\NormalizableInterface; -interface PageCollectionInterface extends MicroobjectCollectionInterface +interface PageCollectionInterface extends MicroobjectCollectionInterface, NormalizableInterface { public function getPage(GetPageQuery $query): MessageInterface; diff --git a/example/Domain/Notebook/Traits/NotebookIdAwareTrait.php b/example/Domain/Notebook/Traits/NotebookIdAwareTrait.php index 276cc58..1de161d 100644 --- a/example/Domain/Notebook/Traits/NotebookIdAwareTrait.php +++ b/example/Domain/Notebook/Traits/NotebookIdAwareTrait.php @@ -7,7 +7,7 @@ trait NotebookIdAwareTrait { - protected NotebookId $notebookId; + private NotebookId $notebookId; public function getNotebookId(): NotebookId { diff --git a/example/Tests/NotebookPortTest.php b/example/Tests/NotebookPortTest.php index 2449a82..5eb6563 100644 --- a/example/Tests/NotebookPortTest.php +++ b/example/Tests/NotebookPortTest.php @@ -18,19 +18,37 @@ use Era269\Microobject\Exception\MicroobjectExceptionInterface; use Era269\Microobject\Exception\MicroobjectOutOfBoundsException; use Era269\Microobject\Message\Event\EventStorageInterface; +use Era269\Normalizable\KeyDecorator\AsIsKeyDecorator; +use Era269\Normalizable\KeyDecoratorInterface; +use Era269\Normalizable\Normalizer\ArrayNormalizer; +use Era269\Normalizable\Normalizer\FailNormalizer; +use Era269\Normalizable\Normalizer\ListNormalizableToNormalizableAdapterNormalizer; +use Era269\Normalizable\Normalizer\NormalizableNormalizer; +use Era269\Normalizable\Normalizer\NormalizationFacade; +use Era269\Normalizable\Normalizer\ScalarableNormalizer; +use Era269\Normalizable\Normalizer\ScalarNormalizer; +use Era269\Normalizable\Normalizer\StringableNormalizer; +use Era269\Normalizable\Normalizer\WithTypeNormalizableNormalizerDecorator; use LogicException; use PHPUnit\Framework\TestCase; class NotebookPortTest extends TestCase { - private const UNIQUE_ID_NOTEBOOK = 'notebook-unique-id'; - private const UNIQUE_ID_PAGE = '1'; - private const WRONG_ID_PAGE = '-1'; + private const UNIQUE_ID_NOTEBOOK = 'notebook-unique-id'; + private const UNIQUE_ID_PAGE = '1'; + private const WRONG_ID_PAGE = '-1'; + + private const NORMALIZED_PAYLOAD = 'payload'; + private const NORMALIZED_ID = 'id'; + private const NORMALIZED_VALUE = 'value'; + private const NORMALIZED_OCCURRED_AT = 'occurredAt'; + private const NORMALIZED_NOTEBOOK_ID = 'notebookId'; + private const NORMALIZED_PAGE_ID = 'pageId'; + private const NORMALIZED_LINES = 'lines'; + private const NORMALIZED_LINE = 'line'; + private TestEventDispatcher $eventDispatcher; - /** - * @throws MicroobjectExceptionInterface - */ public function testGetUnExistingNotebook(): void { $this->expectException(MicroobjectOutOfBoundsException::class); @@ -44,7 +62,21 @@ public function testGetUnExistingNotebook(): void private function getAutowiredNotebookPort(EventStorageInterface $eventStorage): NotebooksPort { return new NotebooksPort( - $this->getAutowiredNotebookCollectionFactory($eventStorage) + $this->getAutowiredNotebookCollectionFactory($eventStorage), + new NormalizationFacade( + new AsIsKeyDecorator(), + [ + new ScalarNormalizer(), + new ArrayNormalizer(), + new ListNormalizableToNormalizableAdapterNormalizer(), + new WithTypeNormalizableNormalizerDecorator( + new NormalizableNormalizer() + ), + new ScalarableNormalizer(), + new StringableNormalizer(), + new FailNormalizer(), + ] + ) ); } @@ -74,9 +106,6 @@ private function getAutowiredNotebookCollectionFactory(EventStorageInterface $ev ); } - /** - * @throws MicroobjectExceptionInterface - */ public function testAddNotebook(): EventStorageInterface { $eventStorage = new EventStorage(); @@ -99,8 +128,6 @@ private function assertEventDispatched(string $eventClassName): void /** * @depends testAddNotebook - * - * @throws MicroobjectExceptionInterface */ public function testGetNotebook(EventStorageInterface $eventStorage): EventStorageInterface { @@ -109,16 +136,17 @@ public function testGetNotebook(EventStorageInterface $eventStorage): EventStora 'notebookId' => self::UNIQUE_ID_NOTEBOOK, ]); - self::assertEquals(self::UNIQUE_ID_NOTEBOOK, $normalizedNotebookResponse['payload']['id']['value']); - self::assertEquals(Notebook::class, $normalizedNotebookResponse['payload']['@type']); + self::assertEquals( + self::UNIQUE_ID_NOTEBOOK, + $normalizedNotebookResponse[self::NORMALIZED_PAYLOAD][self::NORMALIZED_ID][self::NORMALIZED_VALUE] + ); + self::assertEquals('Notebook', $normalizedNotebookResponse[self::NORMALIZED_PAYLOAD]['@type']); return $eventStorage; } /** * @depends testGetNotebook - * - * @throws MicroobjectExceptionInterface */ public function testAddPage(EventStorageInterface $eventStorage): EventStorageInterface { @@ -139,8 +167,6 @@ public function testAddPage(EventStorageInterface $eventStorage): EventStorageIn /** * @depends testAddPage - * - * @throws MicroobjectExceptionInterface */ public function testGetPage(EventStorageInterface $eventStorage): EventStorageInterface { @@ -150,15 +176,16 @@ public function testGetPage(EventStorageInterface $eventStorage): EventStorageIn 'pageId' => self::UNIQUE_ID_PAGE, ]); - self::assertEquals(self::UNIQUE_ID_PAGE, $normalizedPageResponse['payload']['id']['value']); + self::assertEquals( + self::UNIQUE_ID_PAGE, + $normalizedPageResponse[self::NORMALIZED_PAYLOAD][self::NORMALIZED_ID][self::NORMALIZED_VALUE] + ); return $eventStorage; } /** * @depends testAddPage - * - * @throws MicroobjectExceptionInterface */ public function testGetPageNotFound(EventStorageInterface $eventStorage): EventStorageInterface { @@ -170,15 +197,16 @@ public function testGetPageNotFound(EventStorageInterface $eventStorage): EventS 'pageId' => self::WRONG_ID_PAGE, ]); - self::assertEquals(self::UNIQUE_ID_PAGE, $normalizedPageResponse['payload']['id']['value']); + self::assertEquals( + self::UNIQUE_ID_PAGE, + $normalizedPageResponse[self::NORMALIZED_PAYLOAD][self::NORMALIZED_ID][self::NORMALIZED_VALUE] + ); return $eventStorage; } /** * @depends testGetPage - * - * @throws MicroobjectExceptionInterface */ public function testAddLine(EventStorageInterface $eventStorage): EventStorageInterface { @@ -192,8 +220,8 @@ public function testAddLine(EventStorageInterface $eventStorage): EventStorageIn $this->assertEventDispatched(LineAddedEvent::class); - self::assertArrayHasKey('id', $result); - self::assertArrayHasKey('occurredAt', $result); + self::assertArrayHasKey(self::NORMALIZED_ID, $result); + self::assertArrayHasKey(self::NORMALIZED_OCCURRED_AT, $result); self::assertEquals( 'LineAddedEvent', @@ -201,15 +229,15 @@ public function testAddLine(EventStorageInterface $eventStorage): EventStorageIn ); self::assertEquals( $line, - $result['line'] + $result[self::NORMALIZED_LINE] ); self::assertEquals( self::UNIQUE_ID_NOTEBOOK, - $result['notebookId']['value'] + $result[self::NORMALIZED_NOTEBOOK_ID][self::NORMALIZED_VALUE] ); self::assertEquals( self::UNIQUE_ID_PAGE, - $result['pageId']['value'] + $result[self::NORMALIZED_PAGE_ID][self::NORMALIZED_VALUE] ); return $eventStorage; @@ -217,8 +245,6 @@ public function testAddLine(EventStorageInterface $eventStorage): EventStorageIn /** * @depends testAddLine - * - * @throws MicroobjectExceptionInterface */ public function testGetText(EventStorageInterface $eventStorage): void { @@ -234,7 +260,10 @@ public function testGetText(EventStorageInterface $eventStorage): void 'third line', ]; - self::assertEquals($expectedText, $normalizedTextResponse['payload']['lines']); + self::assertEquals( + $expectedText, + $normalizedTextResponse[self::NORMALIZED_PAYLOAD][self::NORMALIZED_LINES] + ); } /** diff --git a/src/AbstractMicroobject.php b/src/AbstractMicroobject.php index c9d2791..111b6e0 100644 --- a/src/AbstractMicroobject.php +++ b/src/AbstractMicroobject.php @@ -17,7 +17,6 @@ use Era269\MethodMap\MethodMapCollectionDecorator; use Era269\MethodMap\MethodMapInterface; use Era269\Microobject\Traits\CanProcessMessageTrait; -use Era269\Normalizable\Traits\AbstractNormalizableTrait; use Psr\EventDispatcher\EventDispatcherInterface; use Psr\SimpleCache\CacheInterface; use ReflectionMethod; @@ -28,7 +27,6 @@ abstract class AbstractMicroobject implements MicroobjectInterface use CanApplyEventsTrait; use CanPublishEventsTrait; use CanProcessMessageTrait; - use AbstractNormalizableTrait; public function __construct(EventDispatcherInterface $eventDispatcher, ?MethodMapInterface $processMessageMethodMap = null, ?MethodMapInterface $applyEventMethodMap = null, ?CacheInterface $cache = null) { diff --git a/src/Exception/MicroobjectRuntimeException.php b/src/Exception/MicroobjectRuntimeException.php index de03bc4..e55bb91 100644 --- a/src/Exception/MicroobjectRuntimeException.php +++ b/src/Exception/MicroobjectRuntimeException.php @@ -5,9 +5,10 @@ namespace Era269\Microobject\Exception; use Era269\Microobject\Traits\NormalizableExceptionTrait; +use Era269\Normalizable\Traits\NormalizableTrait; use RuntimeException; class MicroobjectRuntimeException extends RuntimeException implements MicroobjectExceptionInterface { - use NormalizableExceptionTrait; + use NormalizableTrait; } diff --git a/src/Message/NullMessage.php b/src/Message/NullMessage.php index e9fa2f6..5732038 100644 --- a/src/Message/NullMessage.php +++ b/src/Message/NullMessage.php @@ -7,10 +7,12 @@ use Era269\Microobject\Identifier\StringId; use Era269\Microobject\MessageInterface; use Era269\Microobject\Traits\MessageTrait; +use Era269\Normalizable\Traits\NormalizableTrait; final class NullMessage implements MessageInterface { use MessageTrait; + use NormalizableTrait; public function __construct() { diff --git a/src/MessageInterface.php b/src/MessageInterface.php index 536caaf..a889c18 100644 --- a/src/MessageInterface.php +++ b/src/MessageInterface.php @@ -4,7 +4,7 @@ namespace Era269\Microobject; -use Era269\Normalizable\NormalizableInterface; +use Era269\Microobject\Example\Domain\NormalizableInterface; interface MessageInterface extends NormalizableInterface, diff --git a/src/MicroobjectInterface.php b/src/MicroobjectInterface.php index 9c50b19..eb04927 100644 --- a/src/MicroobjectInterface.php +++ b/src/MicroobjectInterface.php @@ -4,7 +4,7 @@ namespace Era269\Microobject; -use Era269\Normalizable\NormalizableInterface; +use Era269\Microobject\Example\Domain\NormalizableInterface; interface MicroobjectInterface extends NormalizableInterface, diff --git a/src/Traits/MessageTrait.php b/src/Traits/MessageTrait.php index 9198e15..52df522 100644 --- a/src/Traits/MessageTrait.php +++ b/src/Traits/MessageTrait.php @@ -5,13 +5,10 @@ namespace Era269\Microobject\Traits; use Era269\Microobject\IdentifierInterface; -use Era269\Normalizable\Traits\SimpleNormalizableTrait; trait MessageTrait { - use SimpleNormalizableTrait; - - protected IdentifierInterface $id; + private IdentifierInterface $id; public function getId(): IdentifierInterface { diff --git a/src/Traits/NormalizableExceptionTrait.php b/src/Traits/NormalizableExceptionTrait.php deleted file mode 100644 index 811c4d1..0000000 --- a/src/Traits/NormalizableExceptionTrait.php +++ /dev/null @@ -1,21 +0,0 @@ -normalize(); - } - - public function getType(): string - { - return $this::class; - } -} diff --git a/tests/Traits/MessageTraitTest.php b/tests/Traits/MessageTraitTest.php index f450bc2..eeb0e9f 100644 --- a/tests/Traits/MessageTraitTest.php +++ b/tests/Traits/MessageTraitTest.php @@ -28,13 +28,6 @@ public function __construct(IdentifierInterface $id) } }; - self::assertEquals( - [ - '@type' => $message::class, - 'id' => $normalizedId - ], - $message->normalize() - ); self::assertSame( $id, $message->getId() diff --git a/tests/Traits/NormalizableExceptionTraitTest.php b/tests/Traits/NormalizableExceptionTraitTest.php deleted file mode 100644 index 2bfa0ac..0000000 --- a/tests/Traits/NormalizableExceptionTraitTest.php +++ /dev/null @@ -1,35 +0,0 @@ -exception::class, - $this->exception->getType() - ); - self::assertEquals( - $this->exception::class, - $this->exception->normalize()['@type'] - ); - } - - protected function setUp(): void - { - parent::setUp(); - $this->exception = new class extends Exception implements NormalizableInterface { - use NormalizableExceptionTrait; - }; - } -}