dropSchema() public method

In any way when an exception is thrown it is supressed since drop was issued for all classes of the schema and some probably just don't exist.
public dropSchema ( array $classes ) : void
$classes array
return void
Ejemplo n.º 1
0
 public function createSchema($table)
 {
     foreach (self::$classes as $meta) {
         if ($table === $meta->getTableName() || ".{$table}" === substr($meta->getTableName(), -strlen(".{$table}"))) {
             self::$tool->dropSchema([$meta]);
             self::$tool->createSchema([$meta]);
         }
     }
 }
 public static function setUpBeforeClass()
 {
     $em = self::getEntityManager();
     $metaData = $em->getMetadataFactory()->getAllMetadata();
     self::$schemaTool = new SchemaTool($em);
     self::$schemaTool->dropSchema($metaData);
     self::$schemaTool->createSchema($metaData);
     static::prepareTestData($em);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public static function doSetUpBeforeClass()
 {
     static::$schemaTool = new SchemaTool(static::$em);
     static::$schemaTool->dropSchema(static::getTablesMetadata());
     static::$schemaTool->createSchema(static::getTablesMetadata());
     static::$encoder = static::$container->get('security.encoder_factory');
     static::$user = new User();
     static::$user->setEmail('*****@*****.**');
     static::$user->setPassword(static::$encoder->getEncoder(static::$user)->encodePassword('1234', static::$user->getSalt()));
     static::$user->setUsername('testUser');
     $entityPermissionCategory = new PermissionCategory();
     $entityPermissionCategory->setName('backend_user');
     $entityPermissionCategory->setTechnicalName('backend_user');
     static::$em->persist($entityPermissionCategory);
     $entityPermission = new Permission();
     $entityPermission->setRoleName('IS_AUTHENTICATED_FULLY');
     $entityPermission->setDescription('IS_AUTHENTICATED_FULLY');
     $entityPermission->setName('IS_AUTHENTICATED_FULLY');
     $entityPermission->setCategory($entityPermissionCategory);
     $entityPermission2 = new Permission();
     $entityPermission2->setRoleName('ROLE_MANAGE_PERMISSIONS');
     $entityPermission2->setDescription('ROLE_MANAGE_PERMISSIONS');
     $entityPermission2->setName('ROLE_MANAGE_PERMISSIONS');
     $entityPermission2->setCategory($entityPermissionCategory);
     $entityPermission3 = new Permission();
     $entityPermission3->setRoleName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
     $entityPermission3->setDescription('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
     $entityPermission3->setName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
     $entityPermission3->setCategory($entityPermissionCategory);
     $entityPermission4 = new Permission();
     $entityPermission4->setRoleName('ROLE_MANAGE_USER_PROFILES');
     $entityPermission4->setDescription('ROLE_MANAGE_USER_PROFILES');
     $entityPermission4->setName('ROLE_MANAGE_USER_PROFILES');
     $entityPermission4->setCategory($entityPermissionCategory);
     static::$em->persist($entityPermission);
     static::$em->persist($entityPermission2);
     static::$em->persist($entityPermission3);
     static::$em->persist($entityPermission4);
     static::$em->flush();
     $group = new Group();
     $group->setRefName('BACKEND-USER');
     $group->setName('backend-user');
     $group->addPermission($entityPermission);
     $group->addPermission($entityPermission2);
     $group->addPermission($entityPermission3);
     $group->addPermission($entityPermission4);
     static::$user->addToGroup($group);
     static::$em->persist($group);
     static::$em->persist(static::$user);
     static::$em->flush();
 }
Ejemplo n.º 4
0
 /**
  * @inheritdoc
  */
 protected function setUp()
 {
     parent::setUp();
     $this->client = $this->createClient(['debug' => false]);
     $container = static::$kernel->getContainer();
     /** @var EntityManagerInterface[] $managers */
     $managers = $container->get('doctrine')->getManagers();
     foreach ($managers as $manager) {
         $metadata = $manager->getMetadataFactory()->getAllMetadata();
         if (!empty($metadata)) {
             $tool = new SchemaTool($manager);
             $tool->dropSchema($metadata);
             $tool->createSchema($metadata);
         }
     }
     $class = $container->getParameter('tree_house.keystone.model.user.class');
     $salt = uniqid();
     /** @var UserInterface $user */
     $user = new $class();
     $user->setEnabled(true);
     $user->setUsername('test');
     $user->addRole('ROLE_USER');
     $user->setSalt($salt);
     /** @var EncoderFactoryInterface $encoder */
     $encoder = $container->get('security.encoder_factory');
     $password = $encoder->getEncoder($class)->encodePassword(static::$password, $user->getSalt());
     $user->setPassword($password);
     /** @var ManagerRegistry $doctrine */
     $doctrine = static::$kernel->getContainer()->get('doctrine');
     $manager = $doctrine->getManagerForClass($class);
     $manager->persist($user);
     $manager->flush($user);
     $manager->refresh($user);
     $this->user = $user;
 }
Ejemplo n.º 5
0
 public static function clean(EntityManager $entityManager)
 {
     $metadatas = $entityManager->getMetadataFactory()->getAllMetadata();
     $database = new SchemaTool($entityManager);
     $database->dropSchema($metadatas);
     $database->createSchema($metadatas);
 }
 public function adminRefreshDatabaseAction(Request $request, Application $app)
 {
     $conn = $app['db'];
     $em = $app['doctrine.orm.entity_manager'];
     $params = $conn->getParams();
     $name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
     try {
         $conn->getSchemaManager()->dropDatabase($name);
         $conn->getSchemaManager()->createDatabase($name);
         $conn->close();
     } catch (\Exception $e) {
         return 1;
     }
     $classes = [];
     foreach ($app['authbucket_oauth2.model'] as $class) {
         $classes[] = $em->getClassMetadata($class);
     }
     PersistentObject::setObjectManager($em);
     $tool = new SchemaTool($em);
     $tool->dropSchema($classes);
     $tool->createSchema($classes);
     $purger = new ORMPurger();
     $executor = new ORMExecutor($em, $purger);
     $loader = new Loader();
     $loader->loadFromDirectory(__DIR__ . '/../DataFixtures/ORM');
     $executor->execute($loader->getFixtures());
     return $app->redirect($app['url_generator']->generate('index'));
 }
Ejemplo n.º 7
0
 protected function setUp()
 {
     if (!class_exists('Symfony\\Component\\Form\\Form')) {
         $this->markTestSkipped('The "Form" component is not available');
     }
     if (!class_exists('Doctrine\\DBAL\\Platforms\\MySqlPlatform')) {
         $this->markTestSkipped('Doctrine DBAL is not available.');
     }
     if (!class_exists('Doctrine\\Common\\Version')) {
         $this->markTestSkipped('Doctrine Common is not available.');
     }
     if (!class_exists('Doctrine\\ORM\\EntityManager')) {
         $this->markTestSkipped('Doctrine ORM is not available.');
     }
     $this->em = DoctrineOrmTestCase::createTestEntityManager();
     parent::setUp();
     $schemaTool = new SchemaTool($this->em);
     $classes = array($this->em->getClassMetadata(self::ENTITY_CLASS));
     try {
         $schemaTool->dropSchema($classes);
     } catch (\Exception $e) {
     }
     try {
         $schemaTool->createSchema($classes);
     } catch (\Exception $e) {
     }
     $ids = range(1, 300);
     foreach ($ids as $id) {
         $name = 65 + chr($id % 57);
         $this->em->persist(new SingleIdentEntity($id, $name));
     }
     $this->em->flush();
 }
 private function createDatabaseSchema(EntityManager $em)
 {
     $tool = new SchemaTool($em);
     $allMetadata = $em->getMetadataFactory()->getAllMetadata();
     $tool->dropSchema($allMetadata);
     $tool->createSchema($allMetadata);
 }
Ejemplo n.º 9
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $sql = $this->tool->getDropSchemaSQL($this->metadata->getAllMetadata());
     if (empty($sql)) {
         $this->info('Current models do not exist in schema.');
         return;
     }
     if ($this->option('sql')) {
         $this->info('Outputting drop query:');
         $this->info(implode(';' . PHP_EOL, $sql));
     } else {
         $this->info('Dropping database schema....');
         $this->tool->dropSchema($this->metadata->getAllMetadata());
         $this->info('Schema has been dropped!');
     }
 }
Ejemplo n.º 10
0
 /**
  * Test setup
  */
 protected function setUp()
 {
     // setup entity aliases
     $this->em = DoctrineTestHelper::createTestEntityManager();
     $entityManagerNamespaces = $this->em->getConfiguration()->getEntityNamespaces();
     $entityManagerNamespaces['WebtownPhpBannerBundle'] = 'WebtownPhp\\BannerBundle\\Entity';
     $this->em->getConfiguration()->setEntityNamespaces($entityManagerNamespaces);
     // setup schema
     $schemaTool = new SchemaTool($this->em);
     $classes = [];
     foreach ($this->getEntities() as $entityClass) {
         $classes[] = $this->em->getClassMetadata($entityClass);
     }
     try {
         $schemaTool->dropSchema($classes);
     } catch (\Exception $e) {
     }
     try {
         $schemaTool->createSchema($classes);
     } catch (\Exception $e) {
     }
     $registry = \Mockery::mock('Doctrine\\Bundle\\DoctrineBundle\\Registry');
     $registry->shouldReceive('getManager')->andReturn($this->em);
     $this->bm = new ORMManager($registry, new EventDispatcher());
 }
Ejemplo n.º 11
0
 /**
  * Initializes the database (once).
  *
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Doctrine\ORM\ORMException
  * @throws \Doctrine\ORM\Tools\ToolsException
  */
 protected function setUp()
 {
     if (null === static::$_conn) {
         $dbPath = __DIR__ . '/../../../db.sqlite';
         if (file_exists($dbPath)) {
             unlink($dbPath);
         }
         $params = ['driver' => 'pdo_sqlite', 'path' => $dbPath];
         static::$_conn = DriverManager::getConnection($params);
         static::$_conn->getConfiguration()->setSQLLogger(null);
     }
     if (null === static::$_em) {
         $paths = [__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/ORM/Resources/mapping'];
         $isDevMode = true;
         $config = Setup::createXMLMetadataConfiguration($paths, $isDevMode);
         $em = EntityManager::create(static::$_conn, $config);
         $classes = [];
         foreach (static::$_classes as $class) {
             array_push($classes, $em->getClassMetadata($class));
         }
         $schemaTool = new SchemaTool($em);
         $schemaTool->dropSchema($classes);
         $schemaTool->createSchema($classes);
         // Load fixtures
         $loader = new Loader();
         $loader->loadFromDirectory(__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/Fixtures');
         $purger = new ORMPurger();
         $executor = new ORMExecutor($em, $purger);
         $executor->execute($loader->getFixtures());
         static::$_em = $em;
     }
 }
 function testCreateSchema()
 {
     /* @var $em \Doctrine\ORM\EntityManager */
     $em = $this->app["orm.em"];
     $tool = new SchemaTool($em);
     //@note @doctrine générer les fichiers de classe à partir de métadonnées
     /* generate entity classes */
     $dmf = new DisconnectedClassMetadataFactory();
     $dmf->setEntityManager($em);
     $metadatas = $dmf->getAllMetadata();
     //print_r($metadatas);
     $generator = new EntityGenerator();
     $generator->setGenerateAnnotations(TRUE);
     $generator->setGenerateStubMethods(TRUE);
     $generator->setRegenerateEntityIfExists(TRUE);
     $generator->setUpdateEntityIfExists(TRUE);
     $generator->generate($metadatas, ROOT_TEST_DIR);
     $generator->setNumSpaces(4);
     $this->assertFileExists(ROOT_TEST_DIR . "/Entity/Post.php");
     /* @note @doctrine générer la base de donnée à partir des métadonnées */
     /* @see Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand */
     /* generate database */
     $tool->dropSchema($metadatas);
     $tool->createSchema($metadatas);
     $post = new \Entity\Post();
     $post->setTitle("the title");
     $em->persist($post);
     $em->flush();
     $this->assertInternalType("int", $post->getId());
 }
Ejemplo n.º 13
0
 protected function initOrm(EntityManagerInterface $entityManager)
 {
     $schemaTool = new SchemaTool($entityManager);
     $metadatas = $entityManager->getMetadataFactory()->getAllMetadata();
     $schemaTool->dropSchema($metadatas);
     $schemaTool->createSchema($metadatas);
 }
Ejemplo n.º 14
0
 protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
 {
     $isFullDatabaseDrop = $input->getOption('full-database');
     if ($input->getOption('dump-sql') === true) {
         if ($isFullDatabaseDrop) {
             $sqls = $schemaTool->getDropDatabaseSQL();
         } else {
             $sqls = $schemaTool->getDropSchemaSQL($metadatas);
         }
         $output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL);
     } else {
         if ($input->getOption('force') === true) {
             $output->write('Dropping database schema...' . PHP_EOL);
             if ($isFullDatabaseDrop) {
                 $schemaTool->dropDatabase();
             } else {
                 $schemaTool->dropSchema($metadatas);
             }
             $output->write('Database schema dropped successfully!' . PHP_EOL);
         } else {
             $output->write('ATTENTION: This operation should not be executed in a production environment.' . PHP_EOL . PHP_EOL);
             if ($isFullDatabaseDrop) {
                 $sqls = $schemaTool->getDropDatabaseSQL();
             } else {
                 $sqls = $schemaTool->getDropSchemaSQL($metadatas);
             }
             if (count($sqls)) {
                 $output->write('Schema-Tool would execute ' . count($sqls) . ' queries to drop the database.' . PHP_EOL);
                 $output->write('Please run the operation with --force to execute these queries or use --dump-sql to see them.' . PHP_EOL);
             } else {
                 $output->write('Nothing to drop. The database is empty!' . PHP_EOL);
             }
         }
     }
 }
Ejemplo n.º 15
0
 protected function setUp()
 {
     if (!class_exists('Symfony\\Component\\Form\\Form')) {
         $this->markTestSkipped('The "Form" component is not available');
     }
     if (!class_exists('Doctrine\\DBAL\\Platforms\\MySqlPlatform')) {
         $this->markTestSkipped('Doctrine DBAL is not available.');
     }
     if (!class_exists('Doctrine\\Common\\Version')) {
         $this->markTestSkipped('Doctrine Common is not available.');
     }
     if (!class_exists('Doctrine\\ORM\\EntityManager')) {
         $this->markTestSkipped('Doctrine ORM is not available.');
     }
     $this->em = DoctrineOrmTestCase::createTestEntityManager();
     $this->emRegistry = $this->createRegistryMock('default', $this->em);
     parent::setUp();
     $schemaTool = new SchemaTool($this->em);
     $classes = array($this->em->getClassMetadata(self::ITEM_GROUP_CLASS), $this->em->getClassMetadata(self::SINGLE_IDENT_CLASS), $this->em->getClassMetadata(self::SINGLE_STRING_IDENT_CLASS), $this->em->getClassMetadata(self::COMPOSITE_IDENT_CLASS), $this->em->getClassMetadata(self::COMPOSITE_STRING_IDENT_CLASS));
     try {
         $schemaTool->dropSchema($classes);
     } catch (\Exception $e) {
     }
     try {
         $schemaTool->createSchema($classes);
     } catch (\Exception $e) {
     }
 }
 protected function setUp()
 {
     parent::setUp();
     if (!class_exists('Symfony\\Component\\Form\\Form')) {
         $this->markTestSkipped('The "Form" component is not available');
     }
     if (!class_exists('Doctrine\\DBAL\\Platforms\\MySqlPlatform')) {
         $this->markTestSkipped('Doctrine DBAL is not available.');
     }
     if (!class_exists('Doctrine\\Common\\Version')) {
         $this->markTestSkipped('Doctrine Common is not available.');
     }
     if (!class_exists('Doctrine\\ORM\\EntityManager')) {
         $this->markTestSkipped('Doctrine ORM is not available.');
     }
     $this->em = DoctrineTestHelper::createTestEntityManager();
     $this->emRegistry = $this->createRegistryMock('default', $this->em);
     $this->items = array();
     $schemaTool = new SchemaTool($this->em);
     $classes = array($this->em->getClassMetadata(self::SINGLE_INT_ID_CLASS));
     try {
         $schemaTool->dropSchema($classes);
     } catch (\Exception $e) {
     }
     try {
         $schemaTool->createSchema($classes);
     } catch (\Exception $e) {
     }
     $this->createEntities();
     $this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new ChoiceSelect2TypeExtension($this->dispatcher, $this->requestStack, $this->router, $this->getExtensionTypeName(), 10))->addType(new EntityType($this->emRegistry))->addTypeExtension(new EntitySelect2TypeExtension())->getFormFactory();
     $this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory);
 }
Ejemplo n.º 17
0
 /**
  * do the thing here.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $driver = new DoctrineAdapter();
     $driver->init();
     $em = $driver->getManager();
     $schema = new SchemaTool($em);
     $models = [];
     $model_name = $input->getArgument('model_name');
     $full_name = Config::getInstance()->get('root-namespace') . '\\Models' . '\\' . $model_name . 'Model';
     $schemaManager = $em->getConnection()->getSchemaManager();
     try {
         $metadata = $em->getClassMetadata($full_name);
         $table_name = $metadata->getTableName();
         if ($schemaManager->tablesExist([$table_name]) == true) {
             $models[] = $metadata;
         }
         if (count($models) > 0) {
             $schema->dropSchema($models);
         } else {
             $output->writeln('O model ' . $full_name . ' nao esta registrado no banco de dados.');
         }
     } catch (\Doctrine\ORM\Mapping\MappingException $e) {
         $output->writeln('Erro encontrado:');
         $output->writeln($e->getMessage());
         return;
     }
     $output->writeln('Tabela ' . $table_name . ' removida com sucesso.');
 }
Ejemplo n.º 18
0
 /**
  * do the thing here.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $driver = new DoctrineAdapter();
     $driver->init();
     $em = $driver->getManager();
     $classes = loadAppModels();
     $schema = new SchemaTool($em);
     $models = [];
     try {
         $schemaManager = $em->getConnection()->getSchemaManager();
         foreach ($classes as $class) {
             $metadata = $em->getClassMetadata($class);
             $table_name = $metadata->getTableName();
             if ($schemaManager->tablesExist([$table_name]) == true) {
                 array_push($models, $metadata);
             }
         }
         if (count($models) > 0) {
             $schema->dropSchema($models);
         } else {
             $output->writeln('Nao ha models exportados para o banco de dados');
         }
     } catch (\Doctrine\ORM\Mapping\MappingException $e) {
         $output->writeln('Erro encontrado:');
         $output->writeln($e->getMessage());
         return;
     }
     $output->writeln('Tabelas removidas com sucesso.');
 }
Ejemplo n.º 19
0
 public function rebuildSchema()
 {
     $metadatas = $this->em->getMetadataFactory()->getAllMetadata();
     $tool = new SchemaTool($this->em);
     $tool->dropSchema($metadatas);
     $tool->updateSchema($metadatas, false);
 }
 private function dropAndCreateSchema()
 {
     $schemaTool = new SchemaTool($this->getEntityManager());
     $metadata = $this->getEntityManager()->getMetadataFactory()->getAllMetadata();
     $schemaTool->dropSchema($metadata);
     $schemaTool->createSchema($metadata);
 }
 /**
  * Creates schema for doctrine entities
  *
  * @throws \Doctrine\ORM\Tools\ToolsException
  */
 protected function createDoctrineSchema()
 {
     $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
     $tool = new SchemaTool($this->entityManager);
     $tool->dropSchema($metadata);
     $tool->createSchema($metadata);
 }
 public function testReferenceReconstruction()
 {
     $em = $this->getMockSqliteEntityManager();
     $referenceRepository = new ProxyReferenceRepository($em);
     $listener = new ORMReferenceListener($referenceRepository);
     $em->getEventManager()->addEventSubscriber($listener);
     $schemaTool = new SchemaTool($em);
     $schemaTool->dropSchema(array());
     $schemaTool->createSchema(array($em->getClassMetadata(self::TEST_ENTITY_ROLE)));
     $roleFixture = new TestFixtures\RoleFixture();
     $roleFixture->setReferenceRepository($referenceRepository);
     $roleFixture->load($em);
     // first test against managed state
     $ref = $referenceRepository->getReference('admin-role');
     $this->assertNotInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $ref);
     // test reference reconstruction from serialized data (was managed)
     $serializedData = $referenceRepository->serialize();
     $proxyReferenceRepository = new ProxyReferenceRepository($em);
     $proxyReferenceRepository->unserialize($serializedData);
     $ref = $proxyReferenceRepository->getReference('admin-role');
     $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $ref);
     // now test reference reconstruction from identity
     $em->clear();
     $ref = $referenceRepository->getReference('admin-role');
     $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $ref);
     // test reference reconstruction from serialized data (was identity)
     $serializedData = $referenceRepository->serialize();
     $proxyReferenceRepository = new ProxyReferenceRepository($em);
     $proxyReferenceRepository->unserialize($serializedData);
     $ref = $proxyReferenceRepository->getReference('admin-role');
     $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $ref);
 }
Ejemplo n.º 23
0
    protected function setUp()
    {
        if (!class_exists('Doctrine\\Common\\Version')) {
            $this->markTestSkipped('Doctrine is not available.');
        }

        $this->em = DoctrineOrmTestCase::createTestEntityManager();

        parent::setUp();

        $schemaTool = new SchemaTool($this->em);
        $classes = array(
            $this->em->getClassMetadata(self::SINGLE_IDENT_CLASS),
            $this->em->getClassMetadata(self::SINGLE_STRING_IDENT_CLASS),
            $this->em->getClassMetadata(self::COMPOSITE_IDENT_CLASS),
            $this->em->getClassMetadata(self::COMPOSITE_STRING_IDENT_CLASS),
        );

        try {
            $schemaTool->dropSchema($classes);
        } catch(\Exception $e) {
        }

        try {
            $schemaTool->createSchema($classes);
        } catch(\Exception $e) {
        }
    }
Ejemplo n.º 24
0
 public static function initDatabase()
 {
     $classes = self::getEntityManager()->getMetadataFactory()->getAllMetadata();
     $schemaTool = new SchemaTool(self::getEntityManager());
     $schemaTool->dropSchema($classes);
     $schemaTool->createSchema($classes);
 }
Ejemplo n.º 25
0
 public function dropDb()
 {
     $em = $this->getEntityManager();
     $tool = new SchemaTool($em);
     $tool->dropSchema($em->getMetadataFactory()->getAllMetadata());
     $em->clear();
     self::$hasDb = false;
 }
Ejemplo n.º 26
0
 protected function rebuildDatabase()
 {
     $em = $this->getEntityManager();
     $metadata = $em->getMetadataFactory()->getAllMetadata();
     $schemaTool = new SchemaTool($em);
     $schemaTool->dropSchema($metadata);
     $schemaTool->createSchema($metadata);
 }
 public function tearDown()
 {
     /**
      * @desc Despite throwing an exception in {@link self::setUp()}, PHPUnit
      *       will still end up in this function.
      */
     if ($this->em !== null) {
         if (false === $this->isTravis) {
             $this->em->getConnection()->close();
             unset($this->em);
             return;
         }
         $this->tool->dropSchema($this->classes);
         $this->em->getConnection()->close();
         unset($this->em);
     }
 }
 protected function setUp()
 {
     $this->em = $this->getEntityManager();
     $schemaTool = new SchemaTool($this->em);
     $classes = $this->em->getMetaDataFactory()->getAllMetadata();
     $schemaTool->dropSchema($classes);
     $schemaTool->createSchema($classes);
 }
 /**
  * @param string|null $managerName
  *
  * @throws \Doctrine\ORM\Tools\ToolsException
  */
 public function resetDoctrineSchema($managerName = null)
 {
     $manager = $this->doctrine->getManager($managerName);
     $metadata = $manager->getMetadataFactory()->getAllMetadata();
     $schemaTool = new SchemaTool($manager);
     $schemaTool->dropSchema($metadata);
     $schemaTool->createSchema($metadata);
 }
 protected function setUp()
 {
     if (!class_exists('Symfony\\Component\\Form\\Form')) {
         $this->markTestSkipped('The "Form" component is not available');
     }
     if (!class_exists('Doctrine\\DBAL\\Platforms\\MySqlPlatform')) {
         $this->markTestSkipped('Doctrine DBAL is not available.');
     }
     if (!class_exists('Doctrine\\Common\\Version')) {
         $this->markTestSkipped('Doctrine Common is not available.');
     }
     if (!class_exists('Doctrine\\ORM\\EntityManager')) {
         $this->markTestSkipped('Doctrine ORM is not available.');
     }
     $this->em = DoctrineTestHelper::createTestEntityManager();
     $schemaTool = new SchemaTool($this->em);
     $classes = array($this->em->getClassMetadata($this->getEntityClass()));
     try {
         $schemaTool->dropSchema($classes);
     } catch (\Exception $e) {
     }
     try {
         $schemaTool->createSchema($classes);
     } catch (\Exception $e) {
     }
     list($this->obj1, $this->obj2, $this->obj3, $this->obj4) = $this->createObjects();
     $this->em->persist($this->obj1);
     $this->em->persist($this->obj2);
     $this->em->persist($this->obj3);
     $this->em->persist($this->obj4);
     $this->em->flush();
     parent::setUp();
 }