public function testValidManagerWhenInValidClassManager() { $emptyClassManager = new ClassManager(); $this->constructorManager->setClassManager($emptyClassManager); $errors = $this->getValidator()->validate($this->constructorManager); $this->assertEquals(3, $errors->count()); }
/** * @param ClassConstructorManager $classConstructor * @return string * @throws RendererException */ protected function renderClassConstructor(ClassConstructorManager $classConstructor) { $template = $classConstructor->getTemplate(); $tags = $classConstructor->getTemplateTags(); $initProperties = []; foreach ($classConstructor->getInitProperties() as $initProperty) { $initProperties[] = $this->render($initProperty); } $initPropertiesRendered = empty($initProperties) ? "" : $this->addNewLineAfter(Tools::implodeArrayToTemplate($initProperties)); $args[RenderableInterface::TAG_INIT_PROPERTIES] = $initPropertiesRendered; return $this->addNewLineAfter($this->addIndentation($this->replace($tags, $args, $template), self::INDENT_4_SPACES)); }
public function testRenderAndPutConstructorBodyToContent() { $constructorManager = new ClassConstructorManager(new ClassManager()); $initProperties = new ArrayCollection(); $initProperty = new InitPropertyManager(); $initProperty->setProperty(Helper::prepareProperty("collection", "Doctrine\\Common\\Collections\\ArrayCollection", "items collection", ["Valid(message = \"Collection has to be valid!\")"])); $initProperty2 = new InitPropertyManager(); $initProperty2->setProperty(Helper::prepareProperty("collection2", "Doctrine\\Common\\Collections\\ArrayCollection", "items collection 2", ["Valid(message = \"Collection has to be valid!\")"])); $initProperties->add($initProperty2); $initProperties->add($initProperty); $constructorManager->setInitProperties($initProperties); $result = $this->renderer->renderAndPutConstructorBodyToContent($this->postClassExpected, $constructorManager, 43); $this->assertEquals($this->postClassWithUpdatedConstructor, $result); }
/** * Prepare list of init properties for constructor * * @param ClassConstructorManager $classConstructor * @return ClassConstructorManager */ protected function prepareAndFillInitProperties(ClassConstructorManager $classConstructor) { $initProperties = new ArrayCollection(); foreach ($classConstructor->getClassManager()->getProperties() as $property) { if (false == $property->isTypeArrayCollection()) { continue; } $initProperty = new InitPropertyManager(); $initProperty->setProperty($property); $initProperties->add($initProperty); } $classConstructor->setInitProperties($initProperties); return $classConstructor; }