public function testTest()
 {
     $cme = new ClassMetadataExporter();
     $converter = new ConvertDoctrine1Schema(__DIR__ . '/doctrine1schema');
     $exporter = $cme->getExporter('yml', __DIR__ . '/convert');
     $exporter->setMetadatas($converter->getMetadatas());
     $exporter->export();
     $this->assertTrue(file_exists(__DIR__ . '/convert/User.dcm.yml'));
     $this->assertTrue(file_exists(__DIR__ . '/convert/Profile.dcm.yml'));
     $cme->addMappingSource(__DIR__ . '/convert');
     $metadatas = $cme->getMetadatas();
     $this->assertEquals(2, count($metadatas));
     $this->assertEquals('Profile', $metadatas['Profile']->name);
     $this->assertEquals('User', $metadatas['User']->name);
     $this->assertEquals(4, count($metadatas['Profile']->fieldMappings));
     $this->assertEquals(5, count($metadatas['User']->fieldMappings));
     $this->assertEquals('text', $metadatas['User']->fieldMappings['clob']['type']);
     $this->assertEquals('test_alias', $metadatas['User']->fieldMappings['theAlias']['columnName']);
     $this->assertEquals('theAlias', $metadatas['User']->fieldMappings['theAlias']['fieldName']);
     $this->assertEquals('Profile', $metadatas['Profile']->associationMappings['User']->sourceEntityName);
     $this->assertEquals('User', $metadatas['Profile']->associationMappings['User']->targetEntityName);
     $this->assertEquals('username', $metadatas['User']->primaryTable['uniqueConstraints']['username']['columns'][0]);
     unlink(__DIR__ . '/convert/User.dcm.yml');
     unlink(__DIR__ . '/convert/Profile.dcm.yml');
     rmdir(__DIR__ . '/convert');
 }
Ejemplo n.º 2
0
 public function run()
 {
     $arguments = $this->getArguments();
     $cme = new ClassMetadataExporter();
     $cme->setEntityManager($this->getConfiguration()->getAttribute('em'));
     $printer = $this->getPrinter();
     // Get exporter and configure it
     $exporter = $cme->getExporter($arguments['to'], $arguments['dest']);
     if ($arguments['to'] === 'annotation') {
         $entityGenerator = new EntityGenerator();
         $exporter->setEntityGenerator($entityGenerator);
         if (isset($arguments['extend']) && $arguments['extend']) {
             $entityGenerator->setClassToExtend($arguments['extend']);
         }
         if (isset($arguments['num-spaces']) && $arguments['extend']) {
             $entityGenerator->setNumSpaces($arguments['num-spaces']);
         }
     }
     $from = (array) $arguments['from'];
     foreach ($from as $source) {
         $cme->addMappingSource($source);
     }
     $metadatas = $cme->getMetadatas();
     foreach ($metadatas as $metadata) {
         $printer->writeln(sprintf('Processing entity "%s"', $printer->format($metadata->name, 'KEYWORD')));
     }
     $printer->writeln('');
     $printer->writeln(sprintf('Exporting "%s" mapping information to "%s"', $printer->format($arguments['to'], 'KEYWORD'), $printer->format($arguments['dest'], 'KEYWORD')));
     $exporter->setMetadatas($metadatas);
     $exporter->export();
 }
 /**
  * @depends testExportDirectoryAndFilesAreCreated
  */
 public function testExportedMetadataCanBeReadBackIn()
 {
     $type = $this->_getType();
     $cme = new ClassMetadataExporter();
     $cme->addMappingSource(__DIR__ . '/export/' . $type, $type);
     $metadataInstances = $cme->getMetadatas();
     $metadata = current($metadataInstances);
     $this->assertEquals($this->_getTestEntityName(), $metadata->name);
     return $metadata;
 }