/**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $entity = Validators::validateEntityName($input->getArgument('entity'));
     list($bundle, $entity) = $this->parseShortcutNotation($entity);
     $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity;
     $metadata = $this->getEntityMetadata($entityClass);
     $bundle = $this->getApplication()->getKernel()->getBundle($bundle);
     $generator = new DoctrineFormGenerator($this->getContainer()->get('filesystem'));
     $generator->setSkeletonDirs($this->getSkeletonDirs($bundle));
     $generator->generate($bundle, $entity, $metadata[0]);
     $output->writeln(sprintf('The new %s.php class file has been created under %s.', $generator->getClassName(), $generator->getClassPath()));
 }
 private function generateSubNamespacedEntityForm($overwrite)
 {
     $generator = new DoctrineFormGenerator($this->filesystem);
     $generator->setSkeletonDirs(__DIR__ . '/../../Resources/skeleton');
     $bundle = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface')->getMock();
     $bundle->expects($this->any())->method('getPath')->will($this->returnValue($this->tmpDir));
     $bundle->expects($this->any())->method('getNamespace')->will($this->returnValue('Foo\\BarBundle'));
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadataInfo')->disableOriginalConstructor()->getMock();
     $metadata->identifier = array('id');
     $metadata->fieldMappings = array('title' => array('type' => 'string'), 'createdAt' => array('type' => 'date'), 'publishedAt' => array('type' => 'time'), 'updatedAt' => array('type' => 'datetime'));
     $metadata->associationMappings = $metadata->fieldMappings;
     $generator->generate($bundle, 'Blog\\Post', $metadata, $overwrite);
 }
 public function testGenerate()
 {
     $generator = new DoctrineFormGenerator($this->filesystem);
     $generator->setSkeletonDirs(array(__DIR__ . '/../../Resources/skeleton'));
     $bundle = $this->getMock('Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface');
     $bundle->expects($this->any())->method('getPath')->will($this->returnValue($this->tmpDir));
     $bundle->expects($this->any())->method('getNamespace')->will($this->returnValue('Foo\\BarBundle'));
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadataInfo')->disableOriginalConstructor()->getMock();
     $metadata->identifier = array('id');
     $metadata->associationMappings = array('title' => array('type' => 'string'));
     $generator->generate($bundle, 'Post', $metadata);
     $this->assertTrue(file_exists($this->tmpDir . '/Form/PostType.php'));
     $content = file_get_contents($this->tmpDir . '/Form/PostType.php');
     $this->assertContains('->add(\'title\')', $content);
     $this->assertContains('class PostType extends AbstractType', $content);
     $this->assertContains("'data_class' => 'Foo\\BarBundle\\Entity\\Post'", $content);
     $this->assertContains("'foo_barbundle_post'", $content);
 }