/** * Convert data from array to Data Object representation if type is Data Object or array of Data Objects. * * @param mixed $value * @param string $type Convert given value to the this type * @return mixed */ protected function _convertValue($value, $type) { $isArrayType = $this->_typeProcessor->isArrayType($type); if ($isArrayType && isset($value['item'])) { $value = $this->_removeSoapItemNode($value); } if ($this->_typeProcessor->isTypeSimple($type) || $this->_typeProcessor->isTypeAny($type)) { $result = $this->_typeProcessor->processSimpleAndAnyType($value, $type); } else { /** Complex type or array of complex types */ if ($isArrayType) { // Initializing the result for array type else it will return null for empty array $result = is_array($value) ? [] : null; $itemType = $this->_typeProcessor->getArrayItemType($type); if (is_array($value)) { foreach ($value as $key => $item) { $result[$key] = $this->_createFromArray($itemType, $item); } } } else { $result = $this->_createFromArray($type, $value); } } return $result; }
/** * @expectedException \Magento\Webapi\Exception * @expectedExceptionMessage Invalid type for value :"1". Expected Type: "int[]". */ public function testProcessSimpleTypeInvalidType() { $value = 1; $type = 'int[]'; $this->_typeProcessor->processSimpleAndAnyType($value, $type); }