/**
  * @test
  */
 public function getTypeOfChildPropertyShouldUseReflectionServiceToDetermineType()
 {
     $this->mockReflectionService->expects($this->any())->method('hasMethod')->with('TheTargetType', 'setThePropertyName')->will($this->returnValue(FALSE));
     $this->mockReflectionService->expects($this->any())->method('getMethodParameters')->with('TheTargetType', '__construct')->will($this->returnValue(array('thePropertyName' => array('type' => 'TheTypeOfSubObject', 'elementType' => NULL))));
     $configuration = new \TYPO3\Flow\Property\PropertyMappingConfiguration();
     $configuration->setTypeConverterOptions(\TYPO3\Flow\Property\TypeConverter\ObjectConverter::class, array());
     $this->assertEquals('TheTypeOfSubObject', $this->converter->getTypeOfChildProperty('TheTargetType', 'thePropertyName', $configuration));
 }
 /**
  * @test
  */
 public function convertFromReturnsNullIfResourcePropertyIsNotConverted()
 {
     $this->mockObjectManager->expects($this->any())->method('getClassNameByObjectName')->will($this->returnCallback(function ($objectType) {
         return $objectType;
     }));
     $configuration = new \TYPO3\Flow\Property\PropertyMappingConfiguration();
     $configuration->setTypeConverterOption('TYPO3\\Media\\TypeConverter\\ImageInterfaceConverter', \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, true);
     $this->assertNull($this->converter->convertFrom(array(), 'TYPO3\\Media\\Domain\\Model\\Image', array(), $configuration));
 }
 /**
  * @test
  */
 public function convertFromProperlyConvertsArrayWithDateAsArray()
 {
     $source = array('day' => '13', 'month' => '10', 'year' => '2010');
     $mappingConfiguration = new \TYPO3\Flow\Property\PropertyMappingConfiguration();
     $mappingConfiguration->setTypeConverterOption(\TYPO3\Flow\Property\TypeConverter\DateTimeConverter::class, \TYPO3\Flow\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT, 'Y-m-d');
     $date = $this->converter->convertFrom($source, 'DateTime', array(), $mappingConfiguration);
     $actualResult = $date->format('Y-m-d');
     $this->assertSame('2010-10-13', $actualResult);
 }
 /**
  * @test
  */
 public function convertSkipsUnknownPropertiesIfConfiguredTo()
 {
     $source = array('firstProperty' => 1, 'secondProperty' => 2);
     $typeConverters = array('array' => array('stdClass' => array(10 => $this->getMockTypeConverter('array2object', TRUE, $source, 'integer'))), 'integer' => array('integer' => array(10 => $this->getMockTypeConverter('integer2integer'))));
     $configuration = new \TYPO3\Flow\Property\PropertyMappingConfiguration();
     $propertyMapper = $this->getAccessibleMock('TYPO3\\Flow\\Property\\PropertyMapper', array('dummy'));
     $propertyMapper->_set('typeConverters', $typeConverters);
     $propertyMapper->convert($source, 'stdClass', $configuration->allowProperties('firstProperty')->skipUnknownProperties());
     // dummy assertion to avoid PHPUnit warning
     $this->assertTrue(TRUE);
 }
 /**
  * @test
  * @expectedException TYPO3\Flow\I18n\Exception\InvalidLocaleIdentifierException
  */
 public function convertFromThrowsExceptionIfLocaleIsInvalid()
 {
     $configuration = new \TYPO3\Flow\Property\PropertyMappingConfiguration();
     $configuration->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\FloatConverter', 'locale', 'some-non-existent-locale-identifier');
     $this->converter->convertFrom('84,42', 'float', array(), $configuration);
 }
 /**
  * Data provider with invalid configuration for target type overrides
  *
  * @return array
  */
 public function invalidTypeConverterConfigurationsForOverridingTargetTypes()
 {
     $configurationWithNoSetting = new \TYPO3\Flow\Property\PropertyMappingConfiguration();
     $configurationWithOverrideOff = new \TYPO3\Flow\Property\PropertyMappingConfiguration();
     $configurationWithOverrideOff->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\ObjectConverter', \TYPO3\Flow\Property\TypeConverter\ObjectConverter::CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED, FALSE);
     return array(array(NULL), array($configurationWithNoSetting), array($configurationWithOverrideOff));
 }
 /**
  * @param array $typeConverterOptions
  * @return \TYPO3\Flow\Property\PropertyMappingConfiguration
  */
 protected function buildConfiguration($typeConverterOptions)
 {
     $configuration = new \TYPO3\Flow\Property\PropertyMappingConfiguration();
     $configuration->setTypeConverterOptions('TYPO3\\Flow\\Property\\TypeConverter\\PersistentObjectConverter', $typeConverterOptions);
     return $configuration;
 }
 /**
  * @test
  */
 public function getTypeOfChildPropertyShouldRemoveLeadingBackslashesForAnnotationParameters()
 {
     $this->mockReflectionService->expects($this->any())->method('getMethodParameters')->with('TheTargetType', '__construct')->will($this->returnValue(array()));
     $this->mockReflectionService->expects($this->any())->method('hasMethod')->with('TheTargetType', 'setThePropertyName')->will($this->returnValue(false));
     $this->mockReflectionService->expects($this->any())->method('getClassPropertyNames')->with('TheTargetType')->will($this->returnValue(array('thePropertyName')));
     $this->mockReflectionService->expects($this->any())->method('getPropertyTagValues')->with('TheTargetType', 'thePropertyName')->will($this->returnValue(array('\\TheTypeOfSubObject')));
     $configuration = new \TYPO3\Flow\Property\PropertyMappingConfiguration();
     $configuration->setTypeConverterOptions(\TYPO3\Flow\Property\TypeConverter\ObjectConverter::class, array());
     $this->assertEquals('TheTypeOfSubObject', $this->converter->getTypeOfChildProperty('TheTargetType', 'thePropertyName', $configuration));
 }
 /**
  * @Given I have a :class with values
  */
 public function iHaveAEntityWithValues($class, TableNode $values)
 {
     $propertyMappingConfiguration = new \TYPO3\Flow\Property\PropertyMappingConfiguration();
     $propertyMappingConfiguration->allowAllProperties();
     $propertyMappingConfiguration->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\PersistentObjectConverter', \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, TRUE);
     /** @var \TYPO3\Flow\Property\PropertyMapper $propertyMapper */
     $propertyMapper = $this->objectManager->get('TYPO3\\Flow\\Property\\PropertyMapper');
     $row = $values->getRowsHash();
     $identifier = '';
     if (isset($row['persistence_object_identifier'])) {
         $identifier = $row['persistence_object_identifier'];
         unset($row['persistence_object_identifier']);
     }
     $entity = $propertyMapper->convert($row, 'T3DD\\Backend\\Domain\\Model\\' . $class, $propertyMappingConfiguration);
     if ($propertyMapper->getMessages()->hasErrors()) {
         throw new \Exception('Error while mapping entity: ' . print_r($propertyMapper->getMessages(), TRUE));
     }
     if ($identifier) {
         \TYPO3\Flow\Reflection\ObjectAccess::setProperty($entity, 'Persistence_Object_Identifier', $identifier, TRUE);
     }
     $this->objectManager->get('T3DD\\Backend\\Domain\\Repository\\' . $class . 'Repository')->add($entity);
     try {
         $this->flowContext->resolvePageUri('Single ' . $class, array(lcfirst($class) => $entity));
     } catch (\InvalidArgumentException $e) {
     }
     $this->flowContext->persistAll();
 }