/** * Add separate flow for annotated data objects, all other objects are processed by original code. * * @param \Magento\Framework\Webapi\ServiceInputProcessor $subject * @param \Closure $proceed * @param $data * @param $type * @return mixed */ public function aroundConvertValue(\Magento\Framework\Webapi\ServiceInputProcessor $subject, \Closure $proceed, $data, $type) { $result = null; if (is_subclass_of($type, \Flancer32\Lib\DataObject::class)) { if ($this->_typeProcessor->isTypeSimple($type) || $this->_typeProcessor->isTypeAny($type)) { $result = $this->_typeProcessor->processSimpleAndAnyType($data, $type); } else { /** Complex type or array of complex types */ $isArrayType = $this->_typeProcessor->isArrayType($type); if ($isArrayType) { // Initializing the result for array type else it will return null for empty array $itemType = $this->_typeProcessor->getArrayItemType($type); if (is_array($data)) { $result = []; foreach ($data as $key => $item) { $result[$key] = $this->_parser->parseArrayData($itemType, $item); } } } else { if (is_null($data)) { // do nothing, result is null } else { $result = $this->_parser->parseArrayData($type, $data); } } } } else { $result = $proceed($data, $type); } return $result; }
public function test_parseArrayData_notDataObject() { /** === Test Data === */ $TYPE = '\\Exception'; $TYPE_NORM = 'Exception'; $DATA = 'data'; /** === Setup Mocks === */ // $isArray = $this->_toolType->isArray($type); $this->mToolType->shouldReceive('isArray')->once()->andReturn(false); // $typeNorm = $this->_toolType->normalizeType($type); $this->mToolType->shouldReceive('normalizeType')->once()->andReturn($TYPE_NORM); /** === Call and asserts === */ $res = $this->obj->parseArrayData($TYPE, $DATA); $this->assertEquals($DATA, $res); }