public function testSimpleGenerator() { $generator = new DoctrineFormGenerator(dirname(dirname(__DIR__)) . '/Resources/skeleton/form'); $generator->generate($this->getTestBundle(), $this->documentName, $this->metadata); $this->assertFileExists($file = $this->getTestBundle()->getPath() . '/Form/' . $this->documentName . 'Type.php'); $content = file_get_contents($file); $this->assertContains('->add(\'name\')', $content); $this->assertContains('->add(\'description\')', $content); $this->assertContains('class ' . $this->documentName . 'Type extends AbstractType', $content); $this->assertContains("'data_class' => 'Foo\\BarBundle\\Document\\{$this->documentName}'", $content); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $document = Validators::validateDocumentName($input->getArgument('document')); list($bundle, $document) = $this->parseShortcutNotation($document); /** @var $application \Symfony\Bundle\FrameworkBundle\Console\Application */ $application = $this->getApplication(); /* @var $bundle \Symfony\Component\HttpKernel\Bundle\BundleInterface */ $bundle = $application->getKernel()->getBundle($bundle); $documentClass = $bundle->getNamespace() . '\\Document\\' . $document; $metadata = $this->getDocumentMetadata($documentClass); $generator = new DoctrineFormGenerator($this->getSkeletonPath() . '/form'); $generator->generate($bundle, $document, $metadata); $output->writeln(sprintf('The new %s.php class file has been created under %s.', $generator->getClassName(), $generator->getClassPath())); }