From 5589b4c28a1da85212602fa4500a0fe0f8a5c1d1 Mon Sep 17 00:00:00 2001 From: Cristiano Pacheco Date: Fri, 2 Feb 2024 11:10:17 -0300 Subject: [PATCH] [#35] - Renames the message table and make the necessary changes to the classes that manipulates it. --- composer.json | 1 + ...ace.php => QueueErrorMessageInterface.php} | 4 ++-- .../MessageBodyDownloadFileNameBuilder.php | 4 ++-- src/Controller/Adminhtml/Index/Index.php | 2 +- src/Controller/Adminhtml/Message/Download.php | 8 +++---- .../Adminhtml/Message/MassDelete.php | 17 ++++++++------ .../Adminhtml/Message/MassRequeue.php | 13 ++++++----- ... QueueErrorMessageToRawResponseMapper.php} | 6 ++--- .../{Message.php => QueueErrorMessage.php} | 12 +++++----- .../Message/MessageCollection.php | 17 -------------- src/Model/ResourceModel/MessageResource.php | 16 -------------- .../QueueErrorMessageCollection.php | 17 ++++++++++++++ .../QueueErrorMessageResource.php | 16 ++++++++++++++ .../Command/CreateMessageCommand.php | 6 ++--- .../Command/DeleteMessageByIdCommand.php | 2 +- .../Command/DeleteMessageCommand.php | 6 ++--- src/Repository/Query/FindMessageByIdQuery.php | 8 +++---- ...ry.php => QueueErrorMessageRepository.php} | 10 ++++----- src/Service/PublishMessageToQueueService.php | 8 +++---- src/Service/SaveFailedMessageService.php | 8 +++---- ...MessageBodyDownloadFileNameBuilderTest.php | 4 ++-- .../Controller/Adminhtml/Index/IndexTest.php | 2 +- .../Adminhtml/Message/DownloadTest.php | 16 +++++++------- .../Adminhtml/Message/MassDeleteTest.php | 22 +++++++++---------- .../Adminhtml/Message/MassRequeueTest.php | 16 +++++++------- .../Adminhtml/Message/RequeueTest.php | 1 + ...ueErrorMessageToRawResponseMapperTest.php} | 14 ++++++------ src/Test/Unit/Model/MessageTest.php | 6 ++--- .../Command/CreateMessageCommandTest.php | 8 +++---- .../Command/DeleteMessageByIdCommandTest.php | 6 ++--- .../Command/DeleteMessageCommandTest.php | 8 +++---- .../Query/FindMessageByIdQueryTest.php | 10 ++++----- ...hp => QueueErrorMessageRepositoryTest.php} | 14 ++++++------ .../PublishMessageToQueueServiceTest.php | 12 +++++----- .../Service/SaveFailedMessageServiceTest.php | 12 +++++----- src/etc/adminhtml/menu.xml | 2 +- src/etc/db_schema.xml | 5 +++-- src/etc/db_schema_whitelist.json | 18 ++++++++++++++- src/etc/di.xml | 8 +++---- src/i18n/en_US.csv | 1 + 40 files changed, 196 insertions(+), 170 deletions(-) rename src/Api/Data/{MessageInterface.php => QueueErrorMessageInterface.php} (91%) rename src/Mapper/{MessageToRawResponseMapper.php => QueueErrorMessageToRawResponseMapper.php} (87%) rename src/Model/{Message.php => QueueErrorMessage.php} (77%) delete mode 100644 src/Model/ResourceModel/Message/MessageCollection.php delete mode 100644 src/Model/ResourceModel/MessageResource.php create mode 100644 src/Model/ResourceModel/QueueErrorMessage/QueueErrorMessageCollection.php create mode 100644 src/Model/ResourceModel/QueueErrorMessageResource.php rename src/Repository/{MessageRepository.php => QueueErrorMessageRepository.php} (83%) rename src/Test/Unit/Mapper/{MessageToRawResponseMapperTest.php => QueueErrorMessageToRawResponseMapperTest.php} (80%) rename src/Test/Unit/Repository/{MessageRepositoryTest.php => QueueErrorMessageRepositoryTest.php} (83%) diff --git a/composer.json b/composer.json index b78cce0..2664dc1 100644 --- a/composer.json +++ b/composer.json @@ -62,6 +62,7 @@ "sniffer": "vendor/bin/phpcs --colors -p ./src --standard=phpcs-ruleset.xml", "fix-style": "vendor/bin/phpcbf --colors -p ./src --standard=phpcs-ruleset.xml", "sniffer:php8.1": "vendor/bin/phpcs -p ./src --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.1", + "sniffer:php8.2": "vendor/bin/phpcs -p ./src --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.2", "mess-detector": "vendor/bin/phpmd src html phpmd-ruleset.xml --exclude \"Test\" --strict --reportfile reports/phpmd/phpmd.html" } } diff --git a/src/Api/Data/MessageInterface.php b/src/Api/Data/QueueErrorMessageInterface.php similarity index 91% rename from src/Api/Data/MessageInterface.php rename to src/Api/Data/QueueErrorMessageInterface.php index fa0cd59..1aa1032 100644 --- a/src/Api/Data/MessageInterface.php +++ b/src/Api/Data/QueueErrorMessageInterface.php @@ -4,9 +4,9 @@ namespace RunAsRoot\MessageQueueRetry\Api\Data; -interface MessageInterface +interface QueueErrorMessageInterface { - public const TABLE_NAME = 'run_as_root_message'; + public const TABLE_NAME = 'run_as_root_queue_error_message'; public const ENTITY_ID = 'entity_id'; public const TOPIC_NAME = 'topic_name'; public const MESSAGE_BODY = 'message_body'; diff --git a/src/Builder/MessageBodyDownloadFileNameBuilder.php b/src/Builder/MessageBodyDownloadFileNameBuilder.php index d152b6a..47e303c 100644 --- a/src/Builder/MessageBodyDownloadFileNameBuilder.php +++ b/src/Builder/MessageBodyDownloadFileNameBuilder.php @@ -4,11 +4,11 @@ namespace RunAsRoot\MessageQueueRetry\Builder; -use RunAsRoot\MessageQueueRetry\Model\Message; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; class MessageBodyDownloadFileNameBuilder { - public function build(Message $message): string + public function build(QueueErrorMessage $message): string { return $message->getTopicName() . '_' . $message->getId() . '.json'; } diff --git a/src/Controller/Adminhtml/Index/Index.php b/src/Controller/Adminhtml/Index/Index.php index daac323..9edaccb 100644 --- a/src/Controller/Adminhtml/Index/Index.php +++ b/src/Controller/Adminhtml/Index/Index.php @@ -24,7 +24,7 @@ public function execute(): Page { /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); - $resultPage->getConfig()->getTitle()->prepend(__('Messages')->render()); + $resultPage->getConfig()->getTitle()->prepend(__('Queue Error Messages')->render()); $resultPage->setActiveMenu('RunAsRoot_MessageQueueRetry::message_queue_retry'); return $resultPage; diff --git a/src/Controller/Adminhtml/Message/Download.php b/src/Controller/Adminhtml/Message/Download.php index 24d2941..af54274 100644 --- a/src/Controller/Adminhtml/Message/Download.php +++ b/src/Controller/Adminhtml/Message/Download.php @@ -10,8 +10,8 @@ use Magento\Framework\Controller\Result\RawFactory; use RunAsRoot\MessageQueueRetry\Exception\EmptyQueueMessageBodyException; use RunAsRoot\MessageQueueRetry\Exception\MessageNotFoundException; -use RunAsRoot\MessageQueueRetry\Mapper\MessageToRawResponseMapper; -use RunAsRoot\MessageQueueRetry\Repository\MessageRepository; +use RunAsRoot\MessageQueueRetry\Mapper\QueueErrorMessageToRawResponseMapper; +use RunAsRoot\MessageQueueRetry\Repository\QueueErrorMessageRepository; class Download extends Action { @@ -19,9 +19,9 @@ class Download extends Action public function __construct( Context $context, - private MessageRepository $messageRepository, + private QueueErrorMessageRepository $messageRepository, private RawFactory $rawFactory, - private MessageToRawResponseMapper $messageToRawResponseMapper + private QueueErrorMessageToRawResponseMapper $messageToRawResponseMapper ) { parent::__construct($context); } diff --git a/src/Controller/Adminhtml/Message/MassDelete.php b/src/Controller/Adminhtml/Message/MassDelete.php index 6428f9a..1d1bfcc 100644 --- a/src/Controller/Adminhtml/Message/MassDelete.php +++ b/src/Controller/Adminhtml/Message/MassDelete.php @@ -8,10 +8,11 @@ use Magento\Backend\App\Action\Context; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\Data\Collection\AbstractDb; use Magento\Ui\Component\MassAction\Filter; -use RunAsRoot\MessageQueueRetry\Model\Message; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\Message\MessageCollectionFactory; -use RunAsRoot\MessageQueueRetry\Repository\MessageRepository; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessage\QueueErrorMessageCollectionFactory; +use RunAsRoot\MessageQueueRetry\Repository\QueueErrorMessageRepository; class MassDelete extends Action { @@ -19,9 +20,9 @@ class MassDelete extends Action public function __construct( Context $context, - private MessageRepository $messageRepository, + private QueueErrorMessageRepository $messageRepository, private RedirectFactory $redirectFactory, - private MessageCollectionFactory $collectionFactory, + private QueueErrorMessageCollectionFactory $collectionFactory, private Filter $filter ) { parent::__construct($context); @@ -32,10 +33,12 @@ public function execute(): Redirect $redirect = $this->redirectFactory->create(); try { - $collection = $this->filter->getCollection($this->collectionFactory->create()); + /** @var AbstractDb $messageCollection */ + $messageCollection = $this->collectionFactory->create(); + $collection = $this->filter->getCollection($messageCollection); foreach ($collection->getItems() as $message) { - if (!$message instanceof Message) { + if (!$message instanceof QueueErrorMessage) { continue; } diff --git a/src/Controller/Adminhtml/Message/MassRequeue.php b/src/Controller/Adminhtml/Message/MassRequeue.php index fe47589..17d7fa2 100644 --- a/src/Controller/Adminhtml/Message/MassRequeue.php +++ b/src/Controller/Adminhtml/Message/MassRequeue.php @@ -8,9 +8,10 @@ use Magento\Backend\App\Action\Context; use Magento\Framework\Controller\Result\Redirect; use Magento\Framework\Controller\Result\RedirectFactory; +use Magento\Framework\Data\Collection\AbstractDb; use Magento\Ui\Component\MassAction\Filter; -use RunAsRoot\MessageQueueRetry\Model\Message; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\Message\MessageCollectionFactory; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessage\QueueErrorMessageCollectionFactory; use RunAsRoot\MessageQueueRetry\Service\PublishMessageToQueueService; class MassRequeue extends Action @@ -21,7 +22,7 @@ public function __construct( Context $context, private PublishMessageToQueueService $publishMessageToQueueService, private RedirectFactory $redirectFactory, - private MessageCollectionFactory $collectionFactory, + private QueueErrorMessageCollectionFactory $collectionFactory, private Filter $filter ) { parent::__construct($context); @@ -32,10 +33,12 @@ public function execute(): Redirect $redirect = $this->redirectFactory->create(); try { - $collection = $this->filter->getCollection($this->collectionFactory->create()); + /** @var AbstractDb $messageCollection */ + $messageCollection = $this->collectionFactory->create(); + $collection = $this->filter->getCollection($messageCollection); foreach ($collection->getItems() as $message) { - if (!$message instanceof Message) { + if (!$message instanceof QueueErrorMessage) { continue; } diff --git a/src/Mapper/MessageToRawResponseMapper.php b/src/Mapper/QueueErrorMessageToRawResponseMapper.php similarity index 87% rename from src/Mapper/MessageToRawResponseMapper.php rename to src/Mapper/QueueErrorMessageToRawResponseMapper.php index a9508b2..382fb92 100644 --- a/src/Mapper/MessageToRawResponseMapper.php +++ b/src/Mapper/QueueErrorMessageToRawResponseMapper.php @@ -7,9 +7,9 @@ use Magento\Framework\Controller\Result\Raw as RawResponse; use RunAsRoot\MessageQueueRetry\Builder\MessageBodyDownloadFileNameBuilder; use RunAsRoot\MessageQueueRetry\Exception\EmptyQueueMessageBodyException; -use RunAsRoot\MessageQueueRetry\Model\Message; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; -class MessageToRawResponseMapper +class QueueErrorMessageToRawResponseMapper { public function __construct( private MessageBodyDownloadFileNameBuilder $messageBodyDownloadFileNameBuilder @@ -19,7 +19,7 @@ public function __construct( /** * @throws EmptyQueueMessageBodyException */ - public function map(Message $message, RawResponse $rawResponse): RawResponse + public function map(QueueErrorMessage $message, RawResponse $rawResponse): RawResponse { $messageBody = $message->getMessageBody(); diff --git a/src/Model/Message.php b/src/Model/QueueErrorMessage.php similarity index 77% rename from src/Model/Message.php rename to src/Model/QueueErrorMessage.php index a5091b4..e57da71 100644 --- a/src/Model/Message.php +++ b/src/Model/QueueErrorMessage.php @@ -5,11 +5,11 @@ namespace RunAsRoot\MessageQueueRetry\Model; use Magento\Framework\Model\AbstractModel; -use RunAsRoot\MessageQueueRetry\Api\Data\MessageInterface; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\Message\MessageCollection; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource; +use RunAsRoot\MessageQueueRetry\Api\Data\QueueErrorMessageInterface; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessage\QueueErrorMessageCollection; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource; -class Message extends AbstractModel implements MessageInterface +class QueueErrorMessage extends AbstractModel implements QueueErrorMessageInterface { public function getTopicName(): string { @@ -73,7 +73,7 @@ public function setCreatedAt(string $value): void protected function _construct(): void { - $this->_init(MessageResource::class); - $this->_collectionName = MessageCollection::class; + $this->_init(QueueErrorMessageResource::class); + $this->_collectionName = QueueErrorMessageCollection::class; } } diff --git a/src/Model/ResourceModel/Message/MessageCollection.php b/src/Model/ResourceModel/Message/MessageCollection.php deleted file mode 100644 index c2d72dd..0000000 --- a/src/Model/ResourceModel/Message/MessageCollection.php +++ /dev/null @@ -1,17 +0,0 @@ -_init(Model::class, ResourceModel::class); - } -} diff --git a/src/Model/ResourceModel/MessageResource.php b/src/Model/ResourceModel/MessageResource.php deleted file mode 100644 index b827309..0000000 --- a/src/Model/ResourceModel/MessageResource.php +++ /dev/null @@ -1,16 +0,0 @@ -_init(MessageInterface::TABLE_NAME, MessageInterface::ENTITY_ID); - } -} diff --git a/src/Model/ResourceModel/QueueErrorMessage/QueueErrorMessageCollection.php b/src/Model/ResourceModel/QueueErrorMessage/QueueErrorMessageCollection.php new file mode 100644 index 0000000..8542bdf --- /dev/null +++ b/src/Model/ResourceModel/QueueErrorMessage/QueueErrorMessageCollection.php @@ -0,0 +1,17 @@ +_init(Model::class, ResourceModel::class); + } +} diff --git a/src/Model/ResourceModel/QueueErrorMessageResource.php b/src/Model/ResourceModel/QueueErrorMessageResource.php new file mode 100644 index 0000000..4ddd559 --- /dev/null +++ b/src/Model/ResourceModel/QueueErrorMessageResource.php @@ -0,0 +1,16 @@ +_init(QueueErrorMessageInterface::TABLE_NAME, QueueErrorMessageInterface::ENTITY_ID); + } +} diff --git a/src/Repository/Command/CreateMessageCommand.php b/src/Repository/Command/CreateMessageCommand.php index 930a7d6..21501f1 100644 --- a/src/Repository/Command/CreateMessageCommand.php +++ b/src/Repository/Command/CreateMessageCommand.php @@ -5,8 +5,8 @@ namespace RunAsRoot\MessageQueueRetry\Repository\Command; use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeCreatedException; -use RunAsRoot\MessageQueueRetry\Model\Message; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource as ResourceModel; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource as ResourceModel; class CreateMessageCommand { @@ -17,7 +17,7 @@ public function __construct(private ResourceModel $resourceModel) /** * @throws MessageCouldNotBeCreatedException */ - public function execute(Message $message): Message + public function execute(QueueErrorMessage $message): QueueErrorMessage { try { $this->resourceModel->save($message); diff --git a/src/Repository/Command/DeleteMessageByIdCommand.php b/src/Repository/Command/DeleteMessageByIdCommand.php index cf1a650..f544eef 100644 --- a/src/Repository/Command/DeleteMessageByIdCommand.php +++ b/src/Repository/Command/DeleteMessageByIdCommand.php @@ -5,7 +5,7 @@ namespace RunAsRoot\MessageQueueRetry\Repository\Command; use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeDeletedException; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource as ResourceModel; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource as ResourceModel; use RunAsRoot\MessageQueueRetry\Repository\Query\FindMessageByIdQuery; class DeleteMessageByIdCommand diff --git a/src/Repository/Command/DeleteMessageCommand.php b/src/Repository/Command/DeleteMessageCommand.php index d9ed13a..72274d0 100644 --- a/src/Repository/Command/DeleteMessageCommand.php +++ b/src/Repository/Command/DeleteMessageCommand.php @@ -5,8 +5,8 @@ namespace RunAsRoot\MessageQueueRetry\Repository\Command; use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeDeletedException; -use RunAsRoot\MessageQueueRetry\Model\Message; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource as ResourceModel; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource as ResourceModel; class DeleteMessageCommand { @@ -17,7 +17,7 @@ public function __construct(private ResourceModel $resourceModel) /** * @throws MessageCouldNotBeDeletedException */ - public function execute(Message $message): void + public function execute(QueueErrorMessage $message): void { try { $this->resourceModel->delete($message); diff --git a/src/Repository/Query/FindMessageByIdQuery.php b/src/Repository/Query/FindMessageByIdQuery.php index 8469248..2495d16 100644 --- a/src/Repository/Query/FindMessageByIdQuery.php +++ b/src/Repository/Query/FindMessageByIdQuery.php @@ -5,9 +5,9 @@ namespace RunAsRoot\MessageQueueRetry\Repository\Query; use RunAsRoot\MessageQueueRetry\Exception\MessageNotFoundException; -use RunAsRoot\MessageQueueRetry\Model\Message; -use RunAsRoot\MessageQueueRetry\Model\MessageFactory as ModelFactory; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource as ResourceModel; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessageFactory as ModelFactory; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource as ResourceModel; class FindMessageByIdQuery { @@ -20,7 +20,7 @@ public function __construct( /** * @throws MessageNotFoundException */ - public function execute(int $entityId): Message + public function execute(int $entityId): QueueErrorMessage { $model = $this->modelFactory->create(); $this->resourceModel->load($model, $entityId); diff --git a/src/Repository/MessageRepository.php b/src/Repository/QueueErrorMessageRepository.php similarity index 83% rename from src/Repository/MessageRepository.php rename to src/Repository/QueueErrorMessageRepository.php index 176b65b..aad3272 100644 --- a/src/Repository/MessageRepository.php +++ b/src/Repository/QueueErrorMessageRepository.php @@ -7,13 +7,13 @@ use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeCreatedException; use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeDeletedException; use RunAsRoot\MessageQueueRetry\Exception\MessageNotFoundException; -use RunAsRoot\MessageQueueRetry\Model\Message; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; use RunAsRoot\MessageQueueRetry\Repository\Command\CreateMessageCommand; use RunAsRoot\MessageQueueRetry\Repository\Command\DeleteMessageByIdCommand; use RunAsRoot\MessageQueueRetry\Repository\Command\DeleteMessageCommand; use RunAsRoot\MessageQueueRetry\Repository\Query\FindMessageByIdQuery; -class MessageRepository +class QueueErrorMessageRepository { public function __construct( private CreateMessageCommand $createMessageCommand, @@ -26,7 +26,7 @@ public function __construct( /** * @throws MessageNotFoundException */ - public function findById(int $id): Message + public function findById(int $id): QueueErrorMessage { return $this->findMessageByIdQuery->execute($id); } @@ -34,7 +34,7 @@ public function findById(int $id): Message /** * @throws MessageCouldNotBeCreatedException */ - public function create(Message $message): Message + public function create(QueueErrorMessage $message): QueueErrorMessage { return $this->createMessageCommand->execute($message); } @@ -50,7 +50,7 @@ public function deleteById(int $id): void /** * @throws MessageCouldNotBeDeletedException */ - public function delete(Message $message): void + public function delete(QueueErrorMessage $message): void { $this->deleteMessageCommand->execute($message); } diff --git a/src/Service/PublishMessageToQueueService.php b/src/Service/PublishMessageToQueueService.php index 876947f..f2c6877 100644 --- a/src/Service/PublishMessageToQueueService.php +++ b/src/Service/PublishMessageToQueueService.php @@ -8,15 +8,15 @@ use RunAsRoot\MessageQueueRetry\Exception\InvalidQueueConnectionTypeException; use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeDeletedException; use RunAsRoot\MessageQueueRetry\Exception\MessageNotFoundException; -use RunAsRoot\MessageQueueRetry\Model\Message; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; use RunAsRoot\MessageQueueRetry\Queue\Publisher; -use RunAsRoot\MessageQueueRetry\Repository\MessageRepository; +use RunAsRoot\MessageQueueRetry\Repository\QueueErrorMessageRepository; class PublishMessageToQueueService { public function __construct( private Publisher $publisher, - private MessageRepository $messageRepository + private QueueErrorMessageRepository $messageRepository ) { } @@ -39,7 +39,7 @@ public function executeById(int $messageId): void * @throws InvalidQueueConnectionTypeException * @throws InvalidPublisherConfigurationException */ - public function executeByMessage(Message $message): void + public function executeByMessage(QueueErrorMessage $message): void { $this->publisher->publish($message->getTopicName(), $message->getMessageBody()); $this->messageRepository->delete($message); diff --git a/src/Service/SaveFailedMessageService.php b/src/Service/SaveFailedMessageService.php index be310e6..202c3a6 100644 --- a/src/Service/SaveFailedMessageService.php +++ b/src/Service/SaveFailedMessageService.php @@ -6,14 +6,14 @@ use Magento\Framework\MessageQueue\EnvelopeInterface; use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeCreatedException; -use RunAsRoot\MessageQueueRetry\Model\MessageFactory; -use RunAsRoot\MessageQueueRetry\Repository\MessageRepository; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessageFactory; +use RunAsRoot\MessageQueueRetry\Repository\QueueErrorMessageRepository; class SaveFailedMessageService { public function __construct( - private MessageFactory $messageFactory, - private MessageRepository $messageRepository, + private QueueErrorMessageFactory $messageFactory, + private QueueErrorMessageRepository $messageRepository, private GetMessageRetriesCountService $getMessageRetriesCountService ) { } diff --git a/src/Test/Unit/Builder/MessageBodyDownloadFileNameBuilderTest.php b/src/Test/Unit/Builder/MessageBodyDownloadFileNameBuilderTest.php index 85d8594..0712f71 100644 --- a/src/Test/Unit/Builder/MessageBodyDownloadFileNameBuilderTest.php +++ b/src/Test/Unit/Builder/MessageBodyDownloadFileNameBuilderTest.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; use RunAsRoot\MessageQueueRetry\Builder\MessageBodyDownloadFileNameBuilder; -use RunAsRoot\MessageQueueRetry\Model\Message; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; final class MessageBodyDownloadFileNameBuilderTest extends TestCase { @@ -19,7 +19,7 @@ protected function setUp(): void public function testBuild(): void { - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $messageMock->expects($this->once())->method('getTopicName')->willReturn('topic_name'); $messageMock->expects($this->once())->method('getId')->willReturn('message_id'); diff --git a/src/Test/Unit/Controller/Adminhtml/Index/IndexTest.php b/src/Test/Unit/Controller/Adminhtml/Index/IndexTest.php index e23ab7c..7472107 100644 --- a/src/Test/Unit/Controller/Adminhtml/Index/IndexTest.php +++ b/src/Test/Unit/Controller/Adminhtml/Index/IndexTest.php @@ -39,7 +39,7 @@ public function testExecute(): void $pageMock->expects($this->once())->method('getConfig')->willReturn($pageConfigMock); $pageTitleMock = $this->createMock(Title::class); $pageConfigMock->expects($this->once())->method('getTitle')->willReturn($pageTitleMock); - $pageTitleMock->expects($this->once())->method('prepend')->with(__('Messages')); + $pageTitleMock->expects($this->once())->method('prepend')->with(__('Queue Error Messages')); $pageMock->expects($this->once())->method('setActiveMenu') ->with('RunAsRoot_MessageQueueRetry::message_queue_retry'); diff --git a/src/Test/Unit/Controller/Adminhtml/Message/DownloadTest.php b/src/Test/Unit/Controller/Adminhtml/Message/DownloadTest.php index b3a7568..d085f31 100644 --- a/src/Test/Unit/Controller/Adminhtml/Message/DownloadTest.php +++ b/src/Test/Unit/Controller/Adminhtml/Message/DownloadTest.php @@ -11,16 +11,16 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RunAsRoot\MessageQueueRetry\Controller\Adminhtml\Message\Download; -use RunAsRoot\MessageQueueRetry\Mapper\MessageToRawResponseMapper; -use RunAsRoot\MessageQueueRetry\Model\Message; -use RunAsRoot\MessageQueueRetry\Repository\MessageRepository; +use RunAsRoot\MessageQueueRetry\Mapper\QueueErrorMessageToRawResponseMapper; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; +use RunAsRoot\MessageQueueRetry\Repository\QueueErrorMessageRepository; final class DownloadTest extends TestCase { private Download $sut; private RawFactory|MockObject $rawFactoryMock; - private MessageRepository|MockObject $messageRepositoryMock; - private MessageToRawResponseMapper|MockObject $messageToRawResponseMapperMock; + private QueueErrorMessageRepository|MockObject $messageRepositoryMock; + private QueueErrorMessageToRawResponseMapper|MockObject $messageToRawResponseMapperMock; private RequestInterface|MockObject $requestMock; protected function setUp(): void @@ -30,8 +30,8 @@ protected function setUp(): void $contextMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock); $this->rawFactoryMock = $this->createMock(RawFactory::class); - $this->messageRepositoryMock = $this->createMock(MessageRepository::class); - $this->messageToRawResponseMapperMock = $this->createMock(MessageToRawResponseMapper::class); + $this->messageRepositoryMock = $this->createMock(QueueErrorMessageRepository::class); + $this->messageToRawResponseMapperMock = $this->createMock(QueueErrorMessageToRawResponseMapper::class); $this->sut = new Download( $contextMock, $this->messageRepositoryMock, @@ -44,7 +44,7 @@ public function testExecute(): void { $this->requestMock->expects($this->once())->method('getParam')->with('message_id')->willReturn('10'); - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $this->messageRepositoryMock->expects($this->once())->method('findById')->with(10)->willReturn($messageMock); $rawMock = $this->createMock(Raw::class); diff --git a/src/Test/Unit/Controller/Adminhtml/Message/MassDeleteTest.php b/src/Test/Unit/Controller/Adminhtml/Message/MassDeleteTest.php index 97be75f..f3882d0 100644 --- a/src/Test/Unit/Controller/Adminhtml/Message/MassDeleteTest.php +++ b/src/Test/Unit/Controller/Adminhtml/Message/MassDeleteTest.php @@ -12,17 +12,17 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RunAsRoot\MessageQueueRetry\Controller\Adminhtml\Message\MassDelete; -use RunAsRoot\MessageQueueRetry\Model\Message; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\Message\MessageCollection; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\Message\MessageCollectionFactory; -use RunAsRoot\MessageQueueRetry\Repository\MessageRepository; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessage\QueueErrorMessageCollection; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessage\QueueErrorMessageCollectionFactory; +use RunAsRoot\MessageQueueRetry\Repository\QueueErrorMessageRepository; final class MassDeleteTest extends TestCase { private MassDelete $sut; private RedirectFactory|MockObject $redirectFactoryMock; - private MessageRepository|MockObject $messageRepositoryMock; - private MessageCollectionFactory|MockObject $collectionFactoryMock; + private QueueErrorMessageRepository|MockObject $messageRepositoryMock; + private QueueErrorMessageCollectionFactory|MockObject $collectionFactoryMock; private Filter|MockObject $filterMock; private MessageManagerInterface|MockObject $messageManagerMock; @@ -32,8 +32,8 @@ protected function setUp(): void $this->messageManagerMock = $this->createMock(MessageManagerInterface::class); $contextMock->expects($this->once())->method('getMessageManager')->willReturn($this->messageManagerMock); $this->redirectFactoryMock = $this->createMock(RedirectFactory::class); - $this->messageRepositoryMock = $this->createMock(MessageRepository::class); - $this->collectionFactoryMock = $this->createMock(MessageCollectionFactory::class); + $this->messageRepositoryMock = $this->createMock(QueueErrorMessageRepository::class); + $this->collectionFactoryMock = $this->createMock(QueueErrorMessageCollectionFactory::class); $this->filterMock = $this->createMock(Filter::class); $this->sut = new MassDelete( @@ -50,9 +50,9 @@ public function testExecute(): void $redirectMock = $this->createMock(Redirect::class); $this->redirectFactoryMock->expects($this->once())->method('create')->willReturn($redirectMock); - $messageOneMock = $this->createMock(Message::class); - $messageTwoMock = $this->createMock(Message::class); - $collectionMock = $this->createMock(MessageCollection::class); + $messageOneMock = $this->createMock(QueueErrorMessage::class); + $messageTwoMock = $this->createMock(QueueErrorMessage::class); + $collectionMock = $this->createMock(QueueErrorMessageCollection::class); $collectionMock->expects($this->once())->method('getItems')->willReturn([$messageOneMock, $messageTwoMock]); $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock); diff --git a/src/Test/Unit/Controller/Adminhtml/Message/MassRequeueTest.php b/src/Test/Unit/Controller/Adminhtml/Message/MassRequeueTest.php index 1d4f5d0..461dc6e 100644 --- a/src/Test/Unit/Controller/Adminhtml/Message/MassRequeueTest.php +++ b/src/Test/Unit/Controller/Adminhtml/Message/MassRequeueTest.php @@ -12,9 +12,9 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RunAsRoot\MessageQueueRetry\Controller\Adminhtml\Message\MassRequeue; -use RunAsRoot\MessageQueueRetry\Model\Message; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\Message\MessageCollection; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\Message\MessageCollectionFactory; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessage\QueueErrorMessageCollection; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessage\QueueErrorMessageCollectionFactory; use RunAsRoot\MessageQueueRetry\Service\PublishMessageToQueueService; final class MassRequeueTest extends TestCase @@ -22,7 +22,7 @@ final class MassRequeueTest extends TestCase private MassRequeue $sut; private RedirectFactory|MockObject $redirectFactoryMock; private PublishMessageToQueueService|MockObject $publishMessageToQueueServiceMock; - private MessageCollectionFactory|MockObject $collectionFactoryMock; + private QueueErrorMessageCollectionFactory|MockObject $collectionFactoryMock; private Filter|MockObject $filterMock; private MessageManagerInterface|MockObject $messageManagerMock; @@ -33,7 +33,7 @@ protected function setUp(): void $contextMock->expects($this->once())->method('getMessageManager')->willReturn($this->messageManagerMock); $this->redirectFactoryMock = $this->createMock(RedirectFactory::class); $this->publishMessageToQueueServiceMock = $this->createMock(PublishMessageToQueueService::class); - $this->collectionFactoryMock = $this->createMock(MessageCollectionFactory::class); + $this->collectionFactoryMock = $this->createMock(QueueErrorMessageCollectionFactory::class); $this->filterMock = $this->createMock(Filter::class); $this->sut = new MassRequeue( @@ -50,9 +50,9 @@ public function testExecute(): void $redirectMock = $this->createMock(Redirect::class); $this->redirectFactoryMock->expects($this->once())->method('create')->willReturn($redirectMock); - $messageOneMock = $this->createMock(Message::class); - $messageTwoMock = $this->createMock(Message::class); - $collectionMock = $this->createMock(MessageCollection::class); + $messageOneMock = $this->createMock(QueueErrorMessage::class); + $messageTwoMock = $this->createMock(QueueErrorMessage::class); + $collectionMock = $this->createMock(QueueErrorMessageCollection::class); $collectionMock->expects($this->once())->method('getItems')->willReturn([$messageOneMock, $messageTwoMock]); $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock); diff --git a/src/Test/Unit/Controller/Adminhtml/Message/RequeueTest.php b/src/Test/Unit/Controller/Adminhtml/Message/RequeueTest.php index 0370569..b596de4 100644 --- a/src/Test/Unit/Controller/Adminhtml/Message/RequeueTest.php +++ b/src/Test/Unit/Controller/Adminhtml/Message/RequeueTest.php @@ -20,6 +20,7 @@ final class RequeueTest extends TestCase private RedirectFactory|MockObject $redirectFactoryMock; private PublishMessageToQueueService|MockObject $publishMessageToQueueServiceMock; private MessageManagerInterface|MockObject $messageManagerMock; + private RequestInterface|MockObject $requestMock; protected function setUp(): void { diff --git a/src/Test/Unit/Mapper/MessageToRawResponseMapperTest.php b/src/Test/Unit/Mapper/QueueErrorMessageToRawResponseMapperTest.php similarity index 80% rename from src/Test/Unit/Mapper/MessageToRawResponseMapperTest.php rename to src/Test/Unit/Mapper/QueueErrorMessageToRawResponseMapperTest.php index 142af48..4c4befa 100644 --- a/src/Test/Unit/Mapper/MessageToRawResponseMapperTest.php +++ b/src/Test/Unit/Mapper/QueueErrorMessageToRawResponseMapperTest.php @@ -6,21 +6,21 @@ use PHPUnit\Framework\TestCase; use RunAsRoot\MessageQueueRetry\Builder\MessageBodyDownloadFileNameBuilder; use RunAsRoot\MessageQueueRetry\Exception\EmptyQueueMessageBodyException; -use RunAsRoot\MessageQueueRetry\Mapper\MessageToRawResponseMapper; -use RunAsRoot\MessageQueueRetry\Model\Message; +use RunAsRoot\MessageQueueRetry\Mapper\QueueErrorMessageToRawResponseMapper; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; -final class MessageToRawResponseMapperTest extends TestCase +final class QueueErrorMessageToRawResponseMapperTest extends TestCase { - private MessageToRawResponseMapper $sut; + private QueueErrorMessageToRawResponseMapper $sut; protected function setUp(): void { - $this->sut = new MessageToRawResponseMapper(new MessageBodyDownloadFileNameBuilder()); + $this->sut = new QueueErrorMessageToRawResponseMapper(new MessageBodyDownloadFileNameBuilder()); } public function testMap(): void { - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $rawResponseMock = $this->createMock(RawResponse::class); $messageBody = '{"test": "test"}'; @@ -47,7 +47,7 @@ public function testMap(): void public function testItShouldThrowAnExceptionWhenMessageBodyIsEmpty(): void { - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $rawResponseMock = $this->createMock(RawResponse::class); $messageMock->expects($this->once())->method('getMessageBody')->willReturn(''); diff --git a/src/Test/Unit/Model/MessageTest.php b/src/Test/Unit/Model/MessageTest.php index ee0e685..50f3a00 100644 --- a/src/Test/Unit/Model/MessageTest.php +++ b/src/Test/Unit/Model/MessageTest.php @@ -9,11 +9,11 @@ use Magento\Framework\Model\ResourceModel\AbstractResource; use Magento\Framework\Registry; use PHPUnit\Framework\TestCase; -use RunAsRoot\MessageQueueRetry\Model\Message; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; final class MessageTest extends TestCase { - private Message $sut; + private QueueErrorMessage $sut; protected function setUp(): void { @@ -26,7 +26,7 @@ protected function setUp(): void ->getMock(); $resourceMock->expects($this->any())->method('getIdFieldName')->willReturn('id'); $resourceCollectionMock = $this->createMock(AbstractDb::class); - $this->sut = new Message( + $this->sut = new QueueErrorMessage( $contextMock, $registryMock, $resourceMock, diff --git a/src/Test/Unit/Repository/Command/CreateMessageCommandTest.php b/src/Test/Unit/Repository/Command/CreateMessageCommandTest.php index f96512a..1848d94 100644 --- a/src/Test/Unit/Repository/Command/CreateMessageCommandTest.php +++ b/src/Test/Unit/Repository/Command/CreateMessageCommandTest.php @@ -7,9 +7,9 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeCreatedException; -use RunAsRoot\MessageQueueRetry\Model\Message; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; use RunAsRoot\MessageQueueRetry\Repository\Command\CreateMessageCommand; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource as ResourceModel; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource as ResourceModel; class CreateMessageCommandTest extends TestCase { @@ -24,7 +24,7 @@ protected function setUp(): void public function testExecute(): void { - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $this->resourceModelMock->expects($this->once())->method('save')->with($messageMock); $result = $this->sut->execute($messageMock); $this->assertEquals($messageMock, $result); @@ -33,7 +33,7 @@ public function testExecute(): void public function testExecuteWithException(): void { $this->expectException(MessageCouldNotBeCreatedException::class); - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $this->resourceModelMock->expects($this->once())->method('save')->with($messageMock) ->willThrowException(new \Exception('test')); $this->sut->execute($messageMock); diff --git a/src/Test/Unit/Repository/Command/DeleteMessageByIdCommandTest.php b/src/Test/Unit/Repository/Command/DeleteMessageByIdCommandTest.php index 875ffdf..6dc32a2 100644 --- a/src/Test/Unit/Repository/Command/DeleteMessageByIdCommandTest.php +++ b/src/Test/Unit/Repository/Command/DeleteMessageByIdCommandTest.php @@ -7,8 +7,8 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeDeletedException; -use RunAsRoot\MessageQueueRetry\Model\Message; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource as ResourceModel; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource as ResourceModel; use RunAsRoot\MessageQueueRetry\Repository\Command\DeleteMessageByIdCommand; use RunAsRoot\MessageQueueRetry\Repository\Query\FindMessageByIdQuery; @@ -28,7 +28,7 @@ protected function setUp(): void public function testExecute(): void { $entityId = 10; - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $this->findMessageByIdQueryMock->expects($this->once())->method('execute')->with($entityId) ->willReturn($messageMock); $this->resourceModelMock->expects($this->once())->method('delete')->with($messageMock); diff --git a/src/Test/Unit/Repository/Command/DeleteMessageCommandTest.php b/src/Test/Unit/Repository/Command/DeleteMessageCommandTest.php index c11be0f..fe78802 100644 --- a/src/Test/Unit/Repository/Command/DeleteMessageCommandTest.php +++ b/src/Test/Unit/Repository/Command/DeleteMessageCommandTest.php @@ -7,8 +7,8 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeDeletedException; -use RunAsRoot\MessageQueueRetry\Model\Message; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource as ResourceModel; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource as ResourceModel; use RunAsRoot\MessageQueueRetry\Repository\Command\DeleteMessageCommand; class DeleteMessageCommandTest extends TestCase @@ -24,7 +24,7 @@ protected function setUp(): void public function testExecute(): void { - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $this->resourceModelMock->expects($this->once())->method('delete')->with($messageMock); $this->sut->execute($messageMock); } @@ -32,7 +32,7 @@ public function testExecute(): void public function testExecuteWithException(): void { $this->expectException(MessageCouldNotBeDeletedException::class); - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $this->resourceModelMock->expects($this->once())->method('delete')->with($messageMock) ->willThrowException(new \Exception('test')); $this->sut->execute($messageMock); diff --git a/src/Test/Unit/Repository/Query/FindMessageByIdQueryTest.php b/src/Test/Unit/Repository/Query/FindMessageByIdQueryTest.php index a0f4fd2..246165a 100644 --- a/src/Test/Unit/Repository/Query/FindMessageByIdQueryTest.php +++ b/src/Test/Unit/Repository/Query/FindMessageByIdQueryTest.php @@ -7,9 +7,9 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RunAsRoot\MessageQueueRetry\Exception\MessageNotFoundException; -use RunAsRoot\MessageQueueRetry\Model\Message; -use RunAsRoot\MessageQueueRetry\Model\MessageFactory as ModelFactory; -use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource as ResourceModel; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessageFactory as ModelFactory; +use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource as ResourceModel; use RunAsRoot\MessageQueueRetry\Repository\Query\FindMessageByIdQuery; class FindMessageByIdQueryTest extends TestCase @@ -28,7 +28,7 @@ protected function setUp(): void public function testExecute(): void { $entityId = 1; - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $this->modelFactoryMock->expects($this->once())->method('create')->willReturn($messageMock); $this->resourceModelMock->expects($this->once())->method('load')->with($messageMock, $entityId); $messageMock->expects($this->once())->method('getId')->willReturn($entityId); @@ -41,7 +41,7 @@ public function testExecute(): void public function testExecuteWithException(): void { $entityId = 1; - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $this->modelFactoryMock->expects($this->once())->method('create')->willReturn($messageMock); $this->resourceModelMock->expects($this->once())->method('load')->with($messageMock, $entityId); $messageMock->expects($this->once())->method('getId')->willReturn(null); diff --git a/src/Test/Unit/Repository/MessageRepositoryTest.php b/src/Test/Unit/Repository/QueueErrorMessageRepositoryTest.php similarity index 83% rename from src/Test/Unit/Repository/MessageRepositoryTest.php rename to src/Test/Unit/Repository/QueueErrorMessageRepositoryTest.php index af476eb..a0864ac 100644 --- a/src/Test/Unit/Repository/MessageRepositoryTest.php +++ b/src/Test/Unit/Repository/QueueErrorMessageRepositoryTest.php @@ -6,16 +6,16 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use RunAsRoot\MessageQueueRetry\Model\Message; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; use RunAsRoot\MessageQueueRetry\Repository\Command\CreateMessageCommand; use RunAsRoot\MessageQueueRetry\Repository\Command\DeleteMessageByIdCommand; use RunAsRoot\MessageQueueRetry\Repository\Command\DeleteMessageCommand; -use RunAsRoot\MessageQueueRetry\Repository\MessageRepository; +use RunAsRoot\MessageQueueRetry\Repository\QueueErrorMessageRepository; use RunAsRoot\MessageQueueRetry\Repository\Query\FindMessageByIdQuery; -class MessageRepositoryTest extends TestCase +class QueueErrorMessageRepositoryTest extends TestCase { - private MessageRepository $sut; + private QueueErrorMessageRepository $sut; private CreateMessageCommand|MockObject $createMessageCommandMock; private DeleteMessageCommand|MockObject $deleteMessageCommandMock; private DeleteMessageByIdCommand|MockObject $deleteMessageByIdCommandMock; @@ -27,7 +27,7 @@ protected function setUp(): void $this->deleteMessageCommandMock = $this->createMock(DeleteMessageCommand::class); $this->deleteMessageByIdCommandMock = $this->createMock(DeleteMessageByIdCommand::class); $this->findMessageByIdQueryMock = $this->createMock(FindMessageByIdQuery::class); - $this->sut = new MessageRepository( + $this->sut = new QueueErrorMessageRepository( $this->createMessageCommandMock, $this->deleteMessageCommandMock, $this->deleteMessageByIdCommandMock, @@ -44,7 +44,7 @@ public function testFindById(): void public function testCreate(): void { - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $this->createMessageCommandMock->expects($this->once())->method('execute')->with($messageMock); $this->sut->create($messageMock); } @@ -58,7 +58,7 @@ public function testDeleteById(): void public function testDelete(): void { - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $this->deleteMessageCommandMock->expects($this->once())->method('execute')->with($messageMock); $this->sut->delete($messageMock); } diff --git a/src/Test/Unit/Service/PublishMessageToQueueServiceTest.php b/src/Test/Unit/Service/PublishMessageToQueueServiceTest.php index 2a15a1c..04925dc 100644 --- a/src/Test/Unit/Service/PublishMessageToQueueServiceTest.php +++ b/src/Test/Unit/Service/PublishMessageToQueueServiceTest.php @@ -4,28 +4,28 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use RunAsRoot\MessageQueueRetry\Model\Message; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; use RunAsRoot\MessageQueueRetry\Queue\Publisher; -use RunAsRoot\MessageQueueRetry\Repository\MessageRepository; +use RunAsRoot\MessageQueueRetry\Repository\QueueErrorMessageRepository; use RunAsRoot\MessageQueueRetry\Service\PublishMessageToQueueService; final class PublishMessageToQueueServiceTest extends TestCase { private PublishMessageToQueueService $sut; private Publisher|MockObject $publisherMock; - private MessageRepository|MockObject $messageRepositoryMock; + private QueueErrorMessageRepository|MockObject $messageRepositoryMock; protected function setUp(): void { $this->publisherMock = $this->createMock(Publisher::class); - $this->messageRepositoryMock = $this->createMock(MessageRepository::class); + $this->messageRepositoryMock = $this->createMock(QueueErrorMessageRepository::class); $this->sut = new PublishMessageToQueueService($this->publisherMock, $this->messageRepositoryMock); } public function testExecuteById(): void { $messageId = 1; - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $this->messageRepositoryMock->expects($this->once())->method('findById')->with($messageId) ->willReturn($messageMock); $topicName = 'topic.name'; @@ -40,7 +40,7 @@ public function testExecuteById(): void public function testExecuteByMessage(): void { - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $topicName = 'topic.name'; $messageBody = 'message body'; $messageMock->expects($this->once())->method('getTopicName')->willReturn($topicName); diff --git a/src/Test/Unit/Service/SaveFailedMessageServiceTest.php b/src/Test/Unit/Service/SaveFailedMessageServiceTest.php index 8de0ad7..fe614de 100644 --- a/src/Test/Unit/Service/SaveFailedMessageServiceTest.php +++ b/src/Test/Unit/Service/SaveFailedMessageServiceTest.php @@ -6,9 +6,9 @@ use Magento\Framework\MessageQueue\Envelope; use PHPUnit\Framework\TestCase; -use RunAsRoot\MessageQueueRetry\Model\Message; -use RunAsRoot\MessageQueueRetry\Model\MessageFactory; -use RunAsRoot\MessageQueueRetry\Repository\MessageRepository; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage; +use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessageFactory; +use RunAsRoot\MessageQueueRetry\Repository\QueueErrorMessageRepository; use RunAsRoot\MessageQueueRetry\Service\GetMessageRetriesCountService; use RunAsRoot\MessageQueueRetry\Service\SaveFailedMessageService; @@ -16,10 +16,10 @@ final class SaveFailedMessageServiceTest extends TestCase { public function testItSavesFailedMessage(): void { - $messageFactoryMock = $this->createMock(MessageFactory::class); - $messageRepoMock = $this->createMock(MessageRepository::class); + $messageFactoryMock = $this->createMock(QueueErrorMessageFactory::class); + $messageRepoMock = $this->createMock(QueueErrorMessageRepository::class); $getMessageRetriesCountServiceMock = $this->createMock(GetMessageRetriesCountService::class); - $messageMock = $this->createMock(Message::class); + $messageMock = $this->createMock(QueueErrorMessage::class); $testRetriesCount = 3; $testExceptionMessage = 'some exception message'; diff --git a/src/etc/adminhtml/menu.xml b/src/etc/adminhtml/menu.xml index 335dd5f..70c6679 100644 --- a/src/etc/adminhtml/menu.xml +++ b/src/etc/adminhtml/menu.xml @@ -8,7 +8,7 @@ resource="RunAsRoot_MessageQueueRetry::message_queue_retry" /> - +
@@ -11,7 +12,7 @@ - +
diff --git a/src/etc/db_schema_whitelist.json b/src/etc/db_schema_whitelist.json index 729bb89..a50490e 100644 --- a/src/etc/db_schema_whitelist.json +++ b/src/etc/db_schema_whitelist.json @@ -17,5 +17,21 @@ "constraint": { "PRIMARY": true } + }, + "run_as_root_queue_error_message": { + "column": { + "entity_id": true, + "topic_name": true, + "message_body": true, + "failure_description": true, + "total_retries": true, + "created_at": true + }, + "index": { + "RUN_AS_ROOT_QUEUE_ERROR_MESSAGE_TOPIC_NAME": true + }, + "constraint": { + "PRIMARY": true + } } -} +} \ No newline at end of file diff --git a/src/etc/di.xml b/src/etc/di.xml index 471cd64..8cd739d 100644 --- a/src/etc/di.xml +++ b/src/etc/di.xml @@ -9,19 +9,19 @@ - RunAsRoot\MessageQueueRetry\Model\ResourceModel\Message\Grid\Collection + RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessage\Grid\Collection - - RunAsRoot\MessageQueueRetry\Api\Data\MessageInterface::TABLE_NAME + RunAsRoot\MessageQueueRetry\Api\Data\QueueErrorMessageInterface::TABLE_NAME - RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource + RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource diff --git a/src/i18n/en_US.csv b/src/i18n/en_US.csv index f7ca3b1..9313f4d 100644 --- a/src/i18n/en_US.csv +++ b/src/i18n/en_US.csv @@ -42,3 +42,4 @@ ID,ID "Message Body","Message Body" "Created At","Created At" "Invalid message id provided in the request params","Invalid message id provided in the request params" +"Queue Error Messages","Queue Error Messages"