/** * Write a simple model class for a non aggregate root domain obbject * @test */ public function relatedMethodsReflectRenamingARelatedModel() { $modelName = 'Model8'; $this->generateInitialModelClassFile($modelName); // create an "old" domainObject $domainObject = $this->buildDomainObject($modelName); self::assertTrue(is_object($domainObject), 'No domain object'); $relationJsonConfiguration = array('lazyLoading' => 0, 'propertyIsExcludeField' => 1, 'relationDescription' => '', 'relationName' => 'children', 'relationType' => 'manyToMany'); $relation = $this->objectSchemaBuilder->buildRelation($relationJsonConfiguration, $domainObject); $uniqueIdentifier1 = md5(microtime() . 'children'); $relation->setUniqueIdentifier($uniqueIdentifier1); $relation->setForeignModel($this->buildDomainObject('ChildModel')); $domainObject->addProperty($relation); $uniqueIdentifier2 = md5(microtime() . 'Model8'); $domainObject->setUniqueIdentifier($uniqueIdentifier2); $this->roundTripService->_set('previousDomainObjects', array($domainObject->getUniqueIdentifier() => $domainObject)); // create an "old" class object. $modelClassObject = $this->classBuilder->generateModelClassFileObject($domainObject, $this->modelClassTemplatePath, false)->getFirstClass(); self::assertTrue(is_object($modelClassObject), 'No class object'); // Check that the property related methods exist self::assertTrue($modelClassObject->methodExists('setChildren')); self::assertTrue($modelClassObject->methodExists('getChildren')); self::assertTrue($modelClassObject->methodExists('addChild')); self::assertTrue($modelClassObject->methodExists('removeChild')); // set the class object manually, this is usually parsed // from an existing class file $this->roundTripService->_set('classObject', $modelClassObject); // build a new domain object with the same unique identifiers $newDomainObject = $this->buildDomainObject('Model8'); $newRelation = $this->objectSchemaBuilder->buildRelation($relationJsonConfiguration, $domainObject); $newRelation->setUniqueIdentifier($uniqueIdentifier1); $newRelation->setForeignModel($this->buildDomainObject('RenamedModel')); $newRelation->setName('children'); $newDomainObject->addProperty($newRelation); $newDomainObject->setUniqueIdentifier($uniqueIdentifier2); // now the class object should be updated $this->roundTripService->_call('updateModelClassProperties', $domainObject, $newDomainObject); $modifiedModelClassObject = $this->roundTripService->_get('classObject'); $newAddMethod = $modifiedModelClassObject->getMethod('addChild'); $parameters = $newAddMethod->getParameters(); self::assertEquals(count($parameters), 1); $addParameter = current($parameters); self::assertEquals($addParameter->getTypeHint(), '\\EBT\\Dummy\\Domain\\Model\\RenamedModel'); $newRemoveMethod = $modifiedModelClassObject->getMethod('removeChild'); $parameters = $newRemoveMethod->getParameters(); self::assertEquals(count($parameters), 1); $addParameter = current($parameters); self::assertEquals($addParameter->getTypeHint(), '\\EBT\\Dummy\\Domain\\Model\\RenamedModel'); }