Skip to content

Commit d0249ee

Browse files
committed
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.
1 parent dd862cd commit d0249ee

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/internal/Magento/Framework/MessageQueue/MessageValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ protected function validatePrimitiveType($message, $messageType, $topic)
119119
$realType = $this->getRealType($message);
120120
if ($realType == 'array' && count($message) == 0) {
121121
return;
122-
} elseif ($realType == 'array' && count($message) > 0) {
122+
} elseif ($realType == 'array' && isset($message[0])) {
123123
$realType = $this->getRealType($message[0]);
124124
$compareType = preg_replace('/\[\]/', '', $messageType);
125125
}
@@ -153,7 +153,7 @@ protected function validateClassType($message, $messageType, $topic)
153153
$realType = $this->getRealType($message);
154154
if ($realType == 'array' && count($message) == 0) {
155155
return;
156-
} elseif ($realType == 'array' && count($message) > 0) {
156+
} elseif ($realType == 'array' && isset($message[0])) {
157157
$message = $message[0];
158158
$compareType = preg_replace('/\[\]/', '', $messageType);
159159
}

lib/internal/Magento/Framework/MessageQueue/Test/Unit/MessageValidatorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ public function getQueueConfigRequestType()
255255
$customerMock,
256256
'Data in topic "topic" must be of type "Magento\Customer\Api\Data\CustomerInterface[]". '
257257
],
258+
[
259+
[
260+
CommunicationConfig::TOPIC_REQUEST_TYPE => CommunicationConfig::TOPIC_REQUEST_TYPE_CLASS,
261+
CommunicationConfig::TOPIC_REQUEST => 'Magento\Customer\Api\Data\CustomerInterface[]'
262+
],
263+
[1=>23, 3=>545],
264+
'Data in topic "topic" must be of type "Magento\Customer\Api\Data\CustomerInterface[]". '
265+
],
258266
];
259267
}
260268
}

0 commit comments

Comments
 (0)