public function testManger() { $this->assertInstanceOf('\\HelloWordPl\\SimpleEntityGeneratorBundle\\Lib\\Interfaces\\RenderableInterface', $this->classManager); $this->assertInstanceOf('\\HelloWordPl\\SimpleEntityGeneratorBundle\\Lib\\Items\\ClassManager', $this->classManager); $this->assertInstanceOf('\\HelloWordPl\\SimpleEntityGeneratorBundle\\Lib\\Interfaces\\StructureWithMethodsInterface', $this->classManager); $this->assertInstanceOf('\\HelloWordPl\\SimpleEntityGeneratorBundle\\Lib\\Interfaces\\DumpableInterface', $this->classManager); $this->assertEquals("User entity for tests", $this->classManager->getComment()); $this->assertEquals("\\AppBundle\\Entity\\User", $this->classManager->getNamespace()); $this->assertEquals("\\AppBundle\\Entity", $this->classManager->getNamespaceWithoutName()); $this->assertEquals("AppBundle\\Entity", $this->classManager->getNamespaceWithoutNameAndBackslashPrefix()); $this->assertEquals("User", $this->classManager->getName()); $this->assertEquals("/AppBundle/Entity", $this->classManager->getDirectory()); $this->assertTrue($this->classManager->hasInterface()); $this->assertTrue($this->classManager->hasTestClass()); }
/** * @param ClassManager $class * @return string * @throws RendererException */ protected function renderClass(ClassManager $class) { $template = $class->getTemplate(); $tags = $class->getTemplateTags(); $properties = []; $methods = []; $interfacePart = ''; $extendsPart = ''; foreach ($class->getProperties() as $property) { $properties[] = $this->render($property); } foreach ($class->getMethods() as $method) { $methods[] = $this->render($method); } if ($class->hasExtends()) { $extendsPart = sprintf(" extends %s", $class->getExtends()); } if ($class->hasInterface()) { $interfacePart = sprintf(" implements %s", $class->getInterface()->getNamespace()); } $args[RenderableInterface::TAG_NAMESPACE] = $class->getNamespaceWithoutNameAndBackslashPrefix(); $args[RenderableInterface::TAG_COMMENT] = empty($class->getComment()) ? "" : sprintf(" %s", $class->getComment()); $args[RenderableInterface::TAG_NAME] = $class->getName(); $args[RenderableInterface::TAG_EXTENDS] = $extendsPart; $args[RenderableInterface::TAG_INTERFACE] = $interfacePart; $args[RenderableInterface::TAG_CONSTRUCTOR] = $this->render($class->getConstructor()); $args[RenderableInterface::TAG_PROPERTIES] = Tools::implodeArrayToTemplate($properties); $args[RenderableInterface::TAG_METHODS] = Tools::implodeArrayToTemplate($methods); $args[RenderableInterface::TAG_MULTILINE_COMMENT] = $this->prepareMultilineCommentForElement($class); return $this->addNewLineAfter($this->replace($tags, $args, $template)); }
/** * Dump interface to file * * @param OutputInterface $output * @param ClassManager $classManager * @param boolean $onlySimulate * @return */ protected function processInterface(OutputInterface $output, ClassManager $classManager, $onlySimulate = false) { if (false == $classManager->hasInterface()) { return; } $interfaceManager = $classManager->getInterface(); if (false == $onlySimulate) { $filesManager = $this->getFilesManager(); $filesManager->dump($interfaceManager); } $output->writeln('<question>Processed: ' . $interfaceManager->getNamespace() . "</question>"); $this->outputProcessMethods($output, $interfaceManager); $output->writeln(''); }