public function testManger() { $this->assertInstanceOf('\\HelloWordPl\\SimpleEntityGeneratorBundle\\Lib\\Interfaces\\RenderableInterface', $this->testClassManager); $this->assertInstanceOf('\\HelloWordPl\\SimpleEntityGeneratorBundle\\Lib\\Interfaces\\DumpableInterface', $this->testClassManager); $this->assertInstanceOf('\\HelloWordPl\\SimpleEntityGeneratorBundle\\Lib\\Interfaces\\StructureWithMethodsInterface', $this->testClassManager); $this->assertInstanceOf('\\HelloWordPl\\SimpleEntityGeneratorBundle\\Lib\\Items\\TestClassManager', $this->testClassManager); $this->assertEquals('Test for \\AppBundle\\Entity\\User', $this->testClassManager->getComment()); $this->assertEquals('/AppBundle/Tests/Entity', $this->testClassManager->getDirectory()); $this->assertEquals('UserTest', $this->testClassManager->getName()); $this->assertEquals('\\AppBundle\\Tests\\Entity\\UserTest', $this->testClassManager->getNamespace()); $this->assertEquals('\\AppBundle\\Tests\\Entity', $this->testClassManager->getNamespaceWithoutName()); $this->assertEquals('AppBundle\\Tests\\Entity', $this->testClassManager->getNamespaceWithoutNameAndBackslashPrefix()); }
/** * @param TestClassManager $testClass * @return string * @throws RendererException */ protected function renderTestClass(TestClassManager $testClass) { $template = $testClass->getTemplate(); $tags = $testClass->getTemplateTags(); $constructTestMethodBody = ""; $methods = []; foreach ($testClass->getMethods() as $method) { $methods[] = $this->render($method); } $class = $testClass->getClassManager(); $constructTestMethodBody .= $this->addNewLineAfter("\$this->assertNotNull(\$this->object);"); if ($testClass->getClassManager()->hasInterface()) { $interfaceTestAssert = sprintf("\$this->assertInstanceof('%s', \$this->object);", $testClass->getClassManager()->getInterface()->getNamespace()); $constructTestMethodBody .= $this->addNewLineAfter($this->addIndentation($interfaceTestAssert, self::INDENT_8_SPACES)); } $classTestAssert = sprintf("\$this->assertInstanceof('%s', \$this->object);", $class->getNamespace()); $constructTestMethodBody .= $this->addNewLineAfter($this->addIndentation($classTestAssert, self::INDENT_8_SPACES)); if ($testClass->getClassManager()->hasExtends()) { $extendsTestAssert = sprintf("\$this->assertInstanceof('%s', \$this->object);", $testClass->getClassManager()->getExtends()); $constructTestMethodBody .= $this->addNewLineAfter($this->addIndentation($extendsTestAssert, self::INDENT_8_SPACES)); } $testObjectType = $class->getNamespace(); if ($class->hasInterface()) { $testObjectType = $class->getInterface()->getNamespace(); } $args[RenderableInterface::TAG_NAMESPACE] = $testClass->getNamespaceWithoutNameAndBackslashPrefix(); $args[RenderableInterface::TAG_COMMENT] = $testClass->getComment(); $args[RenderableInterface::TAG_NAME] = $testClass->getName(); $args[RenderableInterface::TAG_CLASS] = $class->getNamespace(); $args[RenderableInterface::TAG_METHODS] = Tools::implodeArrayToTemplate($methods); $args[RenderableInterface::TAG_TEST_OBJECT_TYPE] = $testObjectType; $args[RenderableInterface::TAG_METHOD_BODY] = $constructTestMethodBody; return $this->addNewLineAfter($this->replace($tags, $args, $template)); }