public function testExecuteMigrationQueryDryRunEmptyDescription()
 {
     $queryDescription = null;
     $query = $this->getMock('Oro\\Bundle\\MigrationBundle\\Migration\\MigrationQuery');
     $query->expects($this->once())->method('getDescription')->will($this->returnValue($queryDescription));
     $this->logger->expects($this->never())->method('info');
     $query->expects($this->never())->method('execute');
     $this->executor->execute($query, true);
 }
 protected function setUp()
 {
     $this->connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
     $platform = new MySqlPlatform();
     $sm = $this->getMockBuilder('Doctrine\\DBAL\\Schema\\AbstractSchemaManager')->disableOriginalConstructor()->setMethods(['listTables', 'createSchemaConfig'])->getMockForAbstractClass();
     $sm->expects($this->once())->method('listTables')->will($this->returnValue($this->getTables()));
     $sm->expects($this->once())->method('createSchemaConfig')->will($this->returnValue(null));
     $this->connection->expects($this->atLeastOnce())->method('getSchemaManager')->will($this->returnValue($sm));
     $this->connection->expects($this->once())->method('getDatabasePlatform')->will($this->returnValue($platform));
     $this->logger = new ArrayLogger();
     $this->queryExecutor = new MigrationQueryExecutor($this->connection);
     $this->queryExecutor->setLogger($this->logger);
 }
 /**
  * Executes UP method for the given migrations
  *
  * @param Migration[]     $migrations
  * @param bool            $dryRun
  * @throws InvalidNameException if invalid table or column name is detected
  */
 public function executeUp(array $migrations, $dryRun = false)
 {
     $platform = $this->queryExecutor->getConnection()->getDatabasePlatform();
     $sm = $this->queryExecutor->getConnection()->getSchemaManager();
     $fromSchema = $this->createSchemaObject($sm->listTables(), $platform->supportsSequences() ? $sm->listSequences() : [], $sm->createSchemaConfig());
     $queryBag = new QueryBag();
     foreach ($migrations as $migration) {
         $this->logger->notice(sprintf('> %s', get_class($migration)));
         $toSchema = clone $fromSchema;
         $this->setExtensions($migration);
         $migration->up($toSchema, $queryBag);
         $comparator = new Comparator();
         $schemaDiff = $comparator->compare($fromSchema, $toSchema);
         $this->checkTables($schemaDiff, $migration);
         $this->checkIndexes($schemaDiff, $migration);
         $queries = array_merge($queryBag->getPreQueries(), $schemaDiff->toSql($platform), $queryBag->getPostQueries());
         $fromSchema = $toSchema;
         $queryBag->clear();
         foreach ($queries as $query) {
             $this->queryExecutor->execute($query, $dryRun);
         }
     }
 }
 /**
  * @param Schema           $schema
  * @param AbstractPlatform $platform
  * @param Migration        $migration
  * @param bool             $dryRun
  *
  * @return bool
  */
 public function executeUpMigration(Schema &$schema, AbstractPlatform $platform, Migration $migration, $dryRun = false)
 {
     $result = true;
     $this->logger->notice(sprintf('> %s', get_class($migration)));
     $toSchema = clone $schema;
     $this->setExtensions($migration);
     try {
         $queryBag = new QueryBag();
         $migration->up($toSchema, $queryBag);
         $comparator = new Comparator();
         $schemaDiff = $comparator->compare($schema, $toSchema);
         $this->checkTables($schemaDiff, $migration);
         $this->checkIndexes($schemaDiff, $migration);
         $queries = array_merge($queryBag->getPreQueries(), $schemaDiff->toSql($platform), $queryBag->getPostQueries());
         $schema = $toSchema;
         foreach ($queries as $query) {
             $this->queryExecutor->execute($query, $dryRun);
         }
     } catch (\Exception $ex) {
         $result = false;
         $this->logger->error(sprintf('  ERROR: %s', $ex->getMessage()));
     }
     return $result;
 }