public function testManger() { $this->assertInstanceOf('\\HelloWordPl\\SimpleEntityGeneratorBundle\\Lib\\Interfaces\\RenderableInterface', $this->propertyManager); $this->assertInstanceOf('\\HelloWordPl\\SimpleEntityGeneratorBundle\\Lib\\Items\\PropertyManager', $this->propertyManager); $this->assertEquals('User new posts', $this->propertyManager->getComment()); $this->assertEquals('new_posts', $this->propertyManager->getName()); $this->assertEquals('newPosts', $this->propertyManager->getPreparedName()); $this->assertEquals('Doctrine\\Common\\Collections\\ArrayCollection<AppBundle\\Entity\\Post>', $this->propertyManager->getType()); $this->assertEquals('Doctrine\\Common\\Collections\\ArrayCollection', $this->propertyManager->getTypeName()); $this->assertEquals(2, count($this->propertyManager->getConstraints())); }
/** * @param string $name * @param string $type * @param string $comment * @param array $constraintsParts * @return PropertyManager */ public static function prepareProperty($name, $type, $comment = "", array $constraintsParts = []) { $propertyManager = new PropertyManager(); $propertyManager->setName($name); $propertyManager->setType($type); $propertyManager->setComment($comment); $constraintCollection = new ArrayCollection(); foreach ($constraintsParts as $constraintPart) { $constraintCollection->add($constraintPart); } $propertyManager->setConstraints($constraintCollection); return $propertyManager; }
/** * @param PropertyManager $property * @return string * @throws RendererException */ protected function renderProperty(PropertyManager $property) { $template = $property->getTemplate(); $tags = $property->getTemplateTags(); $constraintsPart = ''; if ($property->hasConstraints()) { $constraints = $property->getConstraintAnnotationCollection(); $constraintsStringArray = []; foreach ($constraints as $constraint) { $constraintsStringArray[] = sprintf(" * %s", $constraint); } $constraintsPart = $this->addNewLineAfter(Tools::implodeArrayToTemplate($constraintsStringArray)); } $comment = $property->getComment(); if (empty($comment)) { $comment = sprintf("'%s' property", $property->getName()); } $jmsAnnotationStringArray = []; $jmsAnnotationStringArray[] = sprintf(" * %s\\Type(\"%s\")", self::JMS_ANNOTATION_NAMESPACE, $property->getType()); if ($property->hasSerializedName()) { $jmsAnnotationStringArray[] = sprintf(" * %s\\SerializedName(\"%s\")", self::JMS_ANNOTATION_NAMESPACE, $property->getSerializedName()); } else { $jmsAnnotationStringArray[] = sprintf(" * %s\\SerializedName(\"%s\")", self::JMS_ANNOTATION_NAMESPACE, $property->getName()); } $args[RenderableInterface::TAG_COMMENT] = $comment; $args[RenderableInterface::TAG_CONSTRAINTS] = $constraintsPart; $args[RenderableInterface::TAG_JMS_PART] = $this->addNewLineAfter(Tools::implodeArrayToTemplate($jmsAnnotationStringArray)); $args[RenderableInterface::TAG_TYPE] = $property->getType(); $args[RenderableInterface::TAG_NAME] = $property->getPreparedName(); $args[RenderableInterface::TAG_MULTILINE_COMMENT] = $this->prepareMultilineCommentForElement($property); return $this->addNewLineAfter($this->addIndentation($this->replace($tags, $args, $template), self::INDENT_4_SPACES)); }