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); }
/** * @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; }