Пример #1
0
 public function testDumpDataWithFullConfiguration()
 {
     $outputBuffer = new BufferedOutput();
     $dumper = new Dumper($outputBuffer);
     $pdoMock = $this->getMock('\\stdClass', array('setAttribute'));
     $this->dbMock->expects($this->any())->method('getWrappedConnection')->willReturn($pdoMock);
     $this->dbMock->expects($this->any())->method('fetchColumn')->willReturn(2);
     $this->dbMock->expects($this->any())->method('fetchAll')->willReturnCallback(function ($query) {
         if (strpos($query, 'SHOW COLUMNS') !== false) {
             return array(array('Field' => 'col1', 'Type' => 'varchar'), array('Field' => 'col2', 'Type' => 'blob'));
         }
         throw new \RuntimeException('Unexpected fetchAll-call: ' . $query);
     });
     $this->dbMock->expects($this->any())->method('quote')->willReturnCallback(function ($value) {
         return $value;
     });
     $this->dbMock->expects($this->any())->method('query')->willReturn(array(array('col1' => 'value1.1', 'col2' => 'value1.2'), array('col1' => 'value2.1', 'col2' => 'value2.2')));
     $table = new Table(new \SimpleXMLElement('<table name="test" dump="full" />'));
     $dumper->dumpData('test', $table, $this->dbMock);
     $output = $outputBuffer->fetch();
     $this->assertContains('INSERT INTO', $output);
 }
Пример #2
0
 /**
  * @param Config $config
  * @param Connection $db
  * @param OutputInterface $output
  * @throws \Doctrine\DBAL\DBALException
  */
 public function dump(Config $config, Connection $db, OutputInterface $output)
 {
     $dumper = new Dumper($output);
     $dumper->exportAsUTF8();
     $dumper->disableForeignKeys();
     $platform = $db->getDatabasePlatform();
     $fetchTablesResult = $db->query($platform->getListTablesSQL());
     while ($tableName = $fetchTablesResult->fetchColumn(0)) {
         $tableConfig = $config->findTable($tableName);
         if (null === $tableConfig) {
             continue;
         }
         if ($tableConfig->isSchemaDumpRequired()) {
             $dumper->dumpSchema($tableName, $db, $tableConfig->keepAutoIncrement());
             if ($tableConfig->isDataDumpRequired()) {
                 $dumper->dumpData($tableName, $tableConfig, $db);
             }
         }
     }
     $dumper->enableForeignKeys();
 }