/** * If a method startline was found in the current line * @param array $methodMatches (regex matches) * @throws Tx_ExtensionBuilder_Exception_ParseError * @return void */ protected function onMethodFound($methodMatches) { $this->inMethodBody = TRUE; $methodName = $methodMatches['methodName'][0]; try { // the method has to exist in the classReflection $this->currentMethod['reflection'] = $this->classReflection->getMethod($methodName); if ($this->currentMethod['reflection']) { $classMethod = new Tx_ExtensionBuilder_Domain_Model_Class_Method($methodName, $this->currentMethod['reflection']); $precedingBlock = $this->concatLinesFromArray($this->lines, $this->lastMatchedLineNumber, NULL, FALSE); $classMethod->setPrecedingBlock($precedingBlock); $this->currentMethod['methodObject'] = $classMethod; } else { throw new Tx_ExtensionBuilder_Exception_ParseError('Method ' . $methodName . ' does not exist. Parsed from line ' . $this->lineCount . 'in ' . $this->classReflection->getFileName()); } } catch (ReflectionException $e) { // ReflectionClass throws an exception if a method was not found t3lib_div::devlog('Exception: ' . $e->getMessage(), 'extension_builder', 2); } }
/** * Write a simple model class for a non aggregate root domain object with one to one relation * * @depends checkRequirements * @test */ function writeModelClassWithManyToManyRelation() { $modelName = 'ModelCgt5'; $relatedModelName = 'relatedModel'; $propertyName = 'relNames'; $domainObject = $this->buildDomainObject($modelName); $relatedDomainObject = $this->buildDomainObject($relatedModelName); $relation = new Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ManyToManyRelation($propertyName); $relation->setForeignModel($relatedDomainObject); $relation->setInlineEditing(false); $domainObject->addProperty($relation); $classFileContent = $this->codeGenerator->generateDomainObjectCode($domainObject, $this->extension); $modelClassDir = 'Classes/Domain/Model/'; $result = t3lib_div::mkdir_deep($this->extension->getExtensionDir(), $modelClassDir); $absModelClassDir = $this->extension->getExtensionDir() . $modelClassDir; $this->assertTrue(is_dir($absModelClassDir), 'Directory ' . $absModelClassDir . ' was not created'); $modelClassPath = $absModelClassDir . $domainObject->getName() . '.php'; t3lib_div::writeFile($modelClassPath, $classFileContent); $this->assertFileExists($modelClassPath, 'File was not generated: ' . $modelClassPath); $className = $domainObject->getClassName(); include $modelClassPath; $this->assertTrue(class_exists($className), 'Class was not generated:' . $className); $reflection = new Tx_ExtensionBuilder_Reflection_ClassReflection($className); $this->assertTrue($reflection->hasMethod('add' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName))), 'Add method was not generated'); $this->assertTrue($reflection->hasMethod('remove' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName))), 'Remove method was not generated'); $this->assertTrue($reflection->hasMethod('get' . ucfirst($propertyName)), 'Getter was not generated'); $this->assertTrue($reflection->hasMethod('set' . ucfirst($propertyName)), 'Setter was not generated'); $this->assertTrue($reflection->hasMethod('initStorageObjects'), 'initStorageObjects was not generated'); //checking methods $setterMethod = $reflection->getMethod('set' . ucfirst($propertyName)); $this->assertTrue($setterMethod->isTaggedWith('param'), 'No param tag set for setter method'); $paramTagValues = $setterMethod->getTagValues('param'); $this->assertTrue(strpos($paramTagValues[0], 'Tx_Extbase_Persistence_ObjectStorage<' . $relatedDomainObject->getClassName()) === 0, 'Wrong param tag:' . $paramTagValues[0]); $parameters = $setterMethod->getParameters(); $this->assertTrue(count($parameters) == 1, 'Wrong parameter count in setter method'); $parameter = current($parameters); $this->assertTrue($parameter->getName() == $propertyName, 'Wrong parameter name in setter method'); $this->assertTrue($parameter->getTypeHint() == 'Tx_Extbase_Persistence_ObjectStorage', 'Wrong type hint for setter parameter:' . $parameter->getTypeHint()); $addMethod = $reflection->getMethod('add' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName))); $this->assertTrue($addMethod->isTaggedWith('param'), 'No param tag set for setter method'); $paramTagValues = $addMethod->getTagValues('param'); $this->assertTrue(strpos($paramTagValues[0], $relatedDomainObject->getClassName()) === 0, 'Wrong param tag:' . $paramTagValues[0]); $parameters = $addMethod->getParameters(); $this->assertTrue(count($parameters) == 1, 'Wrong parameter count in add method'); $parameter = current($parameters); $this->assertTrue($parameter->getName() == Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName), 'Wrong parameter name in add method'); $this->assertTrue($parameter->getTypeHint() == $relatedDomainObject->getClassName(), 'Wrong type hint for add method parameter:' . $parameter->getTypeHint()); $removeMethod = $reflection->getMethod('remove' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName))); $this->assertTrue($removeMethod->isTaggedWith('param'), 'No param tag set for remove method'); $paramTagValues = $removeMethod->getTagValues('param'); $this->assertTrue(strpos($paramTagValues[0], $relatedDomainObject->getClassName()) === 0, 'Wrong param tag:' . $paramTagValues[0]); $parameters = $removeMethod->getParameters(); $this->assertTrue(count($parameters) == 1, 'Wrong parameter count in remove method'); $parameter = current($parameters); $this->assertTrue($parameter->getName() == Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName) . 'ToRemove', 'Wrong parameter name in remove method'); $this->assertTrue($parameter->getTypeHint() == $relatedDomainObject->getClassName(), 'Wrong type hint for remove method parameter:' . $parameter->getTypeHint()); }