示例#1
0
 /**
  * @test
  */
 public function mergeShouldMergeTwoResults()
 {
     $notice1 = $this->getMockMessage('Notice');
     $notice2 = $this->getMockMessage('Notice');
     $notice3 = $this->getMockMessage('Notice');
     $warning1 = $this->getMockMessage('Warning');
     $warning2 = $this->getMockMessage('Warning');
     $warning3 = $this->getMockMessage('Warning');
     $error1 = $this->getMockMessage('Error');
     $error2 = $this->getMockMessage('Error');
     $error3 = $this->getMockMessage('Error');
     $otherResult = new \TYPO3\FLOW3\Error\Result();
     $otherResult->addNotice($notice1);
     $otherResult->forProperty('foo.bar')->addNotice($notice2);
     $this->result->forProperty('foo')->addNotice($notice3);
     $otherResult->addWarning($warning1);
     $this->result->addWarning($warning2);
     $this->result->addWarning($warning3);
     $otherResult->forProperty('foo')->addError($error1);
     $otherResult->forProperty('foo')->addError($error2);
     $otherResult->addError($error3);
     $this->result->merge($otherResult);
     $this->assertSame(array($notice1), $this->result->getNotices(), 'Notices are not merged correctly without recursion');
     $this->assertSame(array($notice3), $this->result->forProperty('foo')->getNotices(), 'Original sub-notices are overridden.');
     $this->assertSame(array($notice2), $this->result->forProperty('foo')->forProperty('bar')->getNotices(), 'Sub-notices are not copied.');
     $this->assertSame(array($warning2, $warning3, $warning1), $this->result->getWarnings());
     $this->assertSame(array($error3), $this->result->getErrors());
     $this->assertSame(array($error1, $error2), $this->result->forProperty('foo')->getErrors());
 }
示例#2
0
 /**
  * Internal function which actually does the property mapping.
  *
  * @param mixed $source the source data to map. MUST be a simple type, NO object allowed!
  * @param string $targetType The type of the target; can be either a class name or a simple type.
  * @param \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration Configuration for the property mapping.
  * @param array $currentPropertyPath The property path currently being mapped; used for knowing the context in case an exception is thrown.
  * @return mixed an instance of $targetType
  * @throws \TYPO3\FLOW3\Property\Exception\TypeConverterException
  * @throws \TYPO3\FLOW3\Property\Exception\InvalidPropertyMappingConfigurationException
  */
 protected function doMapping($source, $targetType, \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration, &$currentPropertyPath)
 {
     if (is_object($source) && $source instanceof $targetType) {
         return $source;
     }
     if ($source === NULL) {
         $source = '';
     }
     $typeConverter = $this->findTypeConverter($source, $targetType, $configuration);
     if (!is_object($typeConverter) || !$typeConverter instanceof \TYPO3\FLOW3\Property\TypeConverterInterface) {
         throw new Exception\TypeConverterException('Type converter for "' . $source . '" -> "' . $targetType . '" not found.');
     }
     $convertedChildProperties = array();
     foreach ($typeConverter->getSourceChildPropertiesToBeConverted($source) as $sourcePropertyName => $sourcePropertyValue) {
         $targetPropertyName = $configuration->getTargetPropertyName($sourcePropertyName);
         if (!$configuration->shouldMap($targetPropertyName)) {
             throw new Exception\InvalidPropertyMappingConfigurationException('It is not allowed to map property "' . $targetPropertyName . '". You need to use $propertyMappingConfiguration->allowProperties(\'' . $targetPropertyName . '\') to enable mapping of this property.', 1335969887);
         }
         $targetPropertyType = $typeConverter->getTypeOfChildProperty($targetType, $targetPropertyName, $configuration);
         $subConfiguration = $configuration->getConfigurationFor($targetPropertyName);
         $currentPropertyPath[] = $targetPropertyName;
         $targetPropertyValue = $this->doMapping($sourcePropertyValue, $targetPropertyType, $subConfiguration, $currentPropertyPath);
         array_pop($currentPropertyPath);
         if (!$targetPropertyValue instanceof \TYPO3\FLOW3\Error\Error) {
             $convertedChildProperties[$targetPropertyName] = $targetPropertyValue;
         }
     }
     $result = $typeConverter->convertFrom($source, $targetType, $convertedChildProperties, $configuration);
     if ($result instanceof \TYPO3\FLOW3\Error\Error) {
         $this->messages->forProperty(implode('.', $currentPropertyPath))->addError($result);
     }
     return $result;
 }