From d0249eecfd93e9d5725c77b31c76f31c3f08c6c9 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Fri, 16 Oct 2020 17:25:51 -0500 Subject: [PATCH] MessageValidator fails on hash arrays that dont have 0 element Magento\Framework\MessageQueue\Test\Unit\MessageValidatorTest::testInvalidMessageType with data set #11 (array('object_interface', 'Magento\Customer\Api\Data\Cus...face[]'), array(23, 545), 'Data in topic "topic" must be...e[]". ') PHPUnit\Framework\Exception: Notice: Undefined offset: 0 in /magento/lib/internal/Magento/Framework/MessageQueue/MessageValidator.php:157. --- .../Magento/Framework/MessageQueue/MessageValidator.php | 4 ++-- .../MessageQueue/Test/Unit/MessageValidatorTest.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/MessageQueue/MessageValidator.php b/lib/internal/Magento/Framework/MessageQueue/MessageValidator.php index 45ce351ed97bb..ffa980c882640 100644 --- a/lib/internal/Magento/Framework/MessageQueue/MessageValidator.php +++ b/lib/internal/Magento/Framework/MessageQueue/MessageValidator.php @@ -119,7 +119,7 @@ protected function validatePrimitiveType($message, $messageType, $topic) $realType = $this->getRealType($message); if ($realType == 'array' && count($message) == 0) { return; - } elseif ($realType == 'array' && count($message) > 0) { + } elseif ($realType == 'array' && isset($message[0])) { $realType = $this->getRealType($message[0]); $compareType = preg_replace('/\[\]/', '', $messageType); } @@ -153,7 +153,7 @@ protected function validateClassType($message, $messageType, $topic) $realType = $this->getRealType($message); if ($realType == 'array' && count($message) == 0) { return; - } elseif ($realType == 'array' && count($message) > 0) { + } elseif ($realType == 'array' && isset($message[0])) { $message = $message[0]; $compareType = preg_replace('/\[\]/', '', $messageType); } diff --git a/lib/internal/Magento/Framework/MessageQueue/Test/Unit/MessageValidatorTest.php b/lib/internal/Magento/Framework/MessageQueue/Test/Unit/MessageValidatorTest.php index d324a9dbcfda9..c7d3e35aee3de 100644 --- a/lib/internal/Magento/Framework/MessageQueue/Test/Unit/MessageValidatorTest.php +++ b/lib/internal/Magento/Framework/MessageQueue/Test/Unit/MessageValidatorTest.php @@ -255,6 +255,14 @@ public function getQueueConfigRequestType() $customerMock, 'Data in topic "topic" must be of type "Magento\Customer\Api\Data\CustomerInterface[]". ' ], + [ + [ + CommunicationConfig::TOPIC_REQUEST_TYPE => CommunicationConfig::TOPIC_REQUEST_TYPE_CLASS, + CommunicationConfig::TOPIC_REQUEST => 'Magento\Customer\Api\Data\CustomerInterface[]' + ], + [1=>23, 3=>545], + 'Data in topic "topic" must be of type "Magento\Customer\Api\Data\CustomerInterface[]". ' + ], ]; } }