The return value can be one of three types:
- an arbitrary object, or a simple type (which has been created while mapping).
This is the normal case.
- NULL, indicating that this object should *not* be mapped (i.e. a "File Upload" Converter could return NULL if no file has been uploaded, and a silent failure should occur.
- An instance of \Neos\Error\Messages\Error -- This will be a user-visible error message later on.
Furthermore, it should throw an Exception if an unexpected failure (like a security error) occurred or a configuration issue happened.
public convertFrom ( mixed $source, string $targetType, array $convertedChildProperties = [], Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration = null ) : mixed | Neos\Error\Messages\Error | ||
$source | mixed | |
$targetType | string | |
$convertedChildProperties | array | |
$configuration | Neos\Flow\Property\PropertyMappingConfigurationInterface | |
return | mixed | Neos\Error\Messages\Error | the target type, or an error object if a user-error occurred |
/** * @test * @dataProvider arrayToStringDataProvider */ public function canConvertFromStringToArray($source, $expectedResult, $mappingConfiguration) { // Create a map of arguments to return values. $configurationValueMap = []; foreach ($mappingConfiguration as $setting => $value) { $configurationValueMap[] = [StringConverter::class, $setting, $value]; } $propertyMappingConfiguration = $this->createMock(PropertyMappingConfiguration::class); $propertyMappingConfiguration->expects($this->any())->method('getConfigurationValue')->will($this->returnValueMap($configurationValueMap)); $this->assertEquals($expectedResult, $this->converter->convertFrom($source, 'array', [], $propertyMappingConfiguration)); }
/** * @test */ public function convertFromShouldReturnLocale() { $this->assertInstanceOf(I18n\Locale::class, $this->converter->convertFrom('de', 'irrelevant')); }
/** * @test */ public function convertFromShouldReturnNullForEmptyString() { $source = ''; $result = $this->converter->convertFrom($source, ClassWithSettersAndConstructor::class); $this->assertNull($result); }
/** * @test */ public function convertFromReturnsAnErrorIfSpecifiedStringIsNotNumeric() { $this->assertInstanceOf(FlowError\Error::class, $this->converter->convertFrom('not numeric', 'integer')); }