/**
  * @test
  */
 public function domainObjectHasExpectedRelations()
 {
     $name = 'MyDomainObject';
     $description = 'My long domain object description';
     $className = '\\TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser';
     $input = array('name' => $name, 'objectsettings' => array('description' => $description, 'aggregateRoot' => true, 'type' => 'Entity'), 'relationGroup' => array('relations' => array(0 => array('relationName' => 'relation 1', 'relationType' => 'manyToMany', 'propertyIsExcludeField' => false, 'foreignRelationClass' => $className), 1 => array('relationName' => 'relation 2', 'relationType' => 'manyToMany', 'propertyIsExcludeField' => false, 'foreignRelationClass' => $className))));
     $expected = new \EBT\ExtensionBuilder\Domain\Model\DomainObject();
     $expected->setName($name);
     $expected->setDescription($description);
     $expected->setEntity(true);
     $expected->setAggregateRoot(true);
     $relation1 = new \EBT\ExtensionBuilder\Domain\Model\DomainObject\Relation\ManyToManyRelation('relation 1');
     $relation1->setForeignClassName($className);
     $relation1->setRelatedToExternalModel(true);
     $relation1->setExcludeField(false);
     $relation1->setForeignDatabaseTableName('fe_users');
     $relation2 = new \EBT\ExtensionBuilder\Domain\Model\DomainObject\Relation\ManyToManyRelation('relation 2');
     $relation2->setForeignClassName($className);
     $relation2->setRelatedToExternalModel(true);
     $relation2->setExcludeField(false);
     $relation2->setForeignDatabaseTableName('fe_users');
     $expected->addProperty($relation1);
     $expected->addProperty($relation2);
     $extbaseConfiguration = array('tableName' => 'fe_users');
     $this->configurationManager->expects($this->atLeastOnce())->method('getExtbaseClassConfiguration')->with($className)->will($this->returnValue($extbaseConfiguration));
     $actual = $this->objectSchemaBuilder->build($input);
     $this->assertEquals($actual, $expected, 'Domain Object not built correctly.');
 }
 /**
  * @test
  */
 public function classBuilderGeneratesMethodsForRelationProperty()
 {
     $modelName2 = 'Model2';
     $propertyName = 'relNames';
     $domainObject1 = $this->buildDomainObject($this->modelName, true, true);
     $relatedDomainObject = $this->buildDomainObject($modelName2);
     $relationProperty = new \EBT\ExtensionBuilder\Domain\Model\DomainObject\Relation\ManyToManyRelation($propertyName);
     $relationProperty->setForeignModel($relatedDomainObject);
     $domainObject1->addProperty($relationProperty);
     $modelClassObject = $this->classBuilder->generateModelClassFileObject($domainObject1, $this->modelClassTemplatePath, FALSE)->getFirstClass();
     $this->assertTrue($modelClassObject->methodExists('add' . ucfirst(Inflector::singularize($propertyName))), 'Add method was not generated');
     $this->assertTrue($modelClassObject->methodExists('remove' . ucfirst(Inflector::singularize($propertyName))), 'Remove method was not generated');
     $this->assertTrue($modelClassObject->methodExists('set' . ucfirst($propertyName)), 'Setter was not generated');
     $this->assertTrue($modelClassObject->methodExists('set' . ucfirst($propertyName)), 'Setter was not generated');
     $addMethod = $modelClassObject->getMethod('add' . ucfirst(Inflector::singularize($propertyName)));
     $this->assertTrue($addMethod->isTaggedWith('param'), 'No param tag set for setter method');
     $paramTagValues = $addMethod->getTagValues('param');
     $this->assertTrue(strpos($paramTagValues, $relatedDomainObject->getFullQualifiedClassName()) === 0, 'Wrong param tag:' . $paramTagValues);
     $parameters = $addMethod->getParameters();
     $this->assertTrue(count($parameters) == 1, 'Wrong parameter count in add method');
     $parameter = current($parameters);
     $this->assertTrue($parameter->getName() == Inflector::singularize($propertyName), 'Wrong parameter name in add method');
     $this->assertTrue($parameter->getTypeHint() == $relatedDomainObject->getFullQualifiedClassName(), 'Wrong type hint for add method parameter:' . $parameter->getTypeHint());
 }