/** * @param mixed $data * @return mixed * @throws Exception */ public function conduct($data) { $targetType = $this->getTargetType(); $typeConverter = $this->getTypeConverter(); if (FALSE === $typeConverter->canConvertFrom($data, $targetType)) { throw new Exception('TypeConverter ' . get_class($typeConverter) . ' cannot convert ' . gettype($data) . ' to ' . $targetType, 1386292424); } $output = $this->typeConverter->convertFrom($data, $targetType); if (TRUE === $output instanceof Error) { throw new Exception('Conversion of ' . gettype($data) . ' to ' . $targetType . ' was unsuccessful, Error was: ' . $output->getMessage(), $output->getCode()); } return $output; }
/** * @test */ public function convertFromShouldReturnNullForEmptyString() { $source = ''; $result = $this->converter->convertFrom($source, 'TYPO3\\CMS\\Extbase\\Tests\\Fixture\\ClassWithSettersAndConstructor'); $this->assertNull($result); }
/** * @test */ public function convertFromShouldReturnSourceString() { $this->assertEquals('myString', $this->converter->convertFrom('myString', 'string')); }
/** * @test */ public function convertFromReturnsAnErrorIfSpecifiedStringIsNotNumeric() { $this->assertInstanceOf(\TYPO3\CMS\Extbase\Error\Error::class, $this->converter->convertFrom('not numeric', 'integer')); }
/** * @test */ public function convertFromReturnsAnErrorIfSpecifiedStringIsNotNumeric() { $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Error\\Error', $this->converter->convertFrom('not numeric', 'float')); }