/** * @test * @author Karsten Dambekalns <*****@*****.**> */ public function mapConvertsArraysInSourceToObjectsIfTargetPropertyIsObject() { $this->mockObjectManager->expects($this->once())->method('getObject')->with('F3\\FLOW3\\Property\\MappingResults')->will($this->returnValue($this->mappingResults)); $target = new \F3\FLOW3\Fixtures\ClassWithSetters(); $source = array('property1' => array('foo' => 'bar')); $classSchema = new \F3\FLOW3\Reflection\ClassSchema('F3\\FLOW3\\Fixture\\Validation\\ClassWithSetters'); $classSchema->addProperty('property1', '\\F3\\Foo\\Bar'); $this->mockReflectionService->expects($this->once())->method('getClassSchema')->will($this->returnValue($classSchema)); $mapper = $this->getMock('F3\\FLOW3\\Property\\PropertyMapper', array('transformToObject')); $mapper->expects($this->once())->method('transformToObject')->with($source['property1'], 'F3\\Foo\\Bar', 'property1'); $mapper->injectReflectionService($this->mockReflectionService); $mapper->injectObjectManager($this->mockObjectManager); $mapper->map(array('property1'), $source, $target); }
/** * Builds class schemata from classes annotated as entities or value objects * * @param array $classNames * @return void * @author Robert Lemke <*****@*****.**> * @author Karsten Dambekalns <*****@*****.**> */ protected function buildClassSchemata(array $classNames) { foreach ($classNames as $className) { $classSchema = new \F3\FLOW3\Reflection\ClassSchema($className); if ($this->isClassTaggedWith($className, 'entity')) { $classSchema->setModelType(\F3\FLOW3\Reflection\ClassSchema::MODELTYPE_ENTITY); $possibleRepositoryClassName = str_replace('\\Model\\', '\\Repository\\', $className) . 'Repository'; if ($this->isClassReflected($possibleRepositoryClassName)) { $classSchema->setAggregateRoot(TRUE); } } elseif ($this->isClassTaggedWith($className, 'valueobject')) { $classSchema->setModelType(\F3\FLOW3\Reflection\ClassSchema::MODELTYPE_VALUEOBJECT); } foreach ($this->getClassPropertyNames($className) as $propertyName) { if (!$this->isPropertyTaggedWith($className, $propertyName, 'transient') && $this->isPropertyTaggedWith($className, $propertyName, 'var')) { $classSchema->addProperty($propertyName, implode(' ', $this->getPropertyTagValues($className, $propertyName, 'var')), $this->isPropertyTaggedWith($className, $propertyName, 'lazy')); } if ($this->isPropertyTaggedWith($className, $propertyName, 'uuid')) { $classSchema->setUuidPropertyName($propertyName); } if ($this->isPropertyTaggedWith($className, $propertyName, 'identity')) { $classSchema->markAsIdentityProperty($propertyName); } } $this->classSchemata[$className] = $classSchema; } }
/** * @test * @author Karsten Dambekalns <*****@*****.**> */ public function setModelTypeResetsUuidPropertyNameAndIdentityPropertiesForValueObjects() { $classSchema = new \F3\FLOW3\Reflection\ClassSchema('SomeClass'); $classSchema->setModelType(\F3\FLOW3\Reflection\ClassSchema::MODELTYPE_ENTITY); $classSchema->addProperty('foo', 'string'); $classSchema->addProperty('bar', 'string'); $classSchema->setUuidPropertyName('foo'); $classSchema->markAsIdentityProperty('bar'); $this->assertSame('foo', $classSchema->getUuidPropertyName()); $this->assertSame(array('bar' => 'string'), $classSchema->getIdentityProperties()); $classSchema->setModelType(\F3\FLOW3\Reflection\ClassSchema::MODELTYPE_VALUEOBJECT); $this->assertNull($classSchema->getUuidPropertyName()); $this->assertSame(array(), $classSchema->getIdentityProperties()); }
/** * @test * @author Karsten Dambekalns <*****@*****.**> */ public function mapSplObjectStorageCreatesSplObjectStorage() { $objectData = array(array('value' => array('mappedObject1')), array('value' => array('mappedObject2'))); $classSchema = new \F3\FLOW3\Reflection\ClassSchema('F3\\Post'); $classSchema->addProperty('firstProperty', 'SplObjectStorage'); $dataMapper = $this->getMock($this->buildAccessibleProxy('F3\\FLOW3\\Persistence\\Backend\\GenericPdo\\DataMapper'), array('mapToObject')); $dataMapper->expects($this->at(0))->method('mapToObject')->with($objectData[0]['value'])->will($this->returnValue(new \stdClass())); $dataMapper->expects($this->at(1))->method('mapToObject')->with($objectData[1]['value'])->will($this->returnValue(new \stdClass())); $dataMapper->_call('mapSplObjectStorage', $objectData); }
/** * @test * @author Karsten Dambekalns <*****@*****.**> */ public function removeEntitiesByParentEmitsExpectedSql() { $fooBarClassSchema = new \F3\FLOW3\Reflection\ClassSchema('FooBar'); $fooBarClassSchema->setModelType(\F3\FLOW3\Reflection\ClassSchema::MODELTYPE_ENTITY); $fooBarClassSchema->setAggregateRoot(TRUE); $quuxClassSchema = new \F3\FLOW3\Reflection\ClassSchema('Quux'); $quuxClassSchema->setModelType(\F3\FLOW3\Reflection\ClassSchema::MODELTYPE_ENTITY); $mockStatement = $this->getMock('PDOStatement'); $mockStatement->expects($this->once())->method('execute')->with(array('fakeUuid1')); $mockStatement->expects($this->once())->method('fetchAll')->will($this->onConsecutiveCalls(array(array('type' => 'FooBar', 'identifier' => 'heretostay'), array('type' => 'Quux', 'identifier' => 'goaway')))); $mockPdo = $this->getMock('PdoInterface'); $mockPdo->expects($this->once())->method('prepare')->with('SELECT "identifier", "type" FROM "entities" WHERE "identifier" IN (SELECT DISTINCT "object" FROM "properties_data" WHERE "parent"=?)')->will($this->returnValue($mockStatement)); $object1 = new \stdClass(); $object2 = new \stdClass(); $persistenceSession = new \F3\FLOW3\Persistence\Session(); $persistenceSession->registerObject($object1, 'fakeUuid1'); $persistenceSession->registerObject($object2, 'goaway'); $backend = $this->getMock($this->buildAccessibleProxy('F3\\FLOW3\\Persistence\\Backend\\GenericPdo\\Backend'), array('removeEntity', 'emitRemovedObject')); $backend->injectPersistenceSession($persistenceSession); $backend->expects($this->once())->method('removeEntity')->with($object2); $backend->_set('databaseHandle', $mockPdo); $backend->_set('classSchemata', array('FooBar' => $fooBarClassSchema, 'Quux' => $quuxClassSchema)); $backend->_call('removeEntitiesByParent', $object1); }