Пример #1
0
 /**
  * Tests whether the table selecter works correctly and if the identifier quoting works.
  *
  * @test
  */
 public function testSelectTables()
 {
     $tableSelector = new TableSelector($this->connection);
     $this->createTestSchema();
     $tables = $tableSelector->findTablesToDump(new SqlDumperConfiguration());
     $this->assertEquals(2, count($tables));
     // Billing depends on Customer, so Customer is selected first
     $customerTable = $tables[0];
     $billingTable = $tables[1];
     // Tables are returned in alphabetical order
     $this->assertEquals('Billing', $billingTable->getName());
     $this->assertEquals('Customer', $customerTable->getName());
     // Ensure names are quoted (because normally they wouldn't be, as the table names are no reserved keywords)
     // MySQL quotes with `
     $this->assertEquals('`Billing`', $billingTable->getQuotedName($this->platform));
     $this->assertEquals('`Customer`', $customerTable->getQuotedName($this->platform));
     // assure correct quotings on Billing table (representative for all other tables)
     $this->assertEquals(4, count($billingTable->getColumns()));
     $this->assertEquals('id', $billingTable->getColumn('id')->getName());
     $this->assertEquals('`id`', $billingTable->getColumn('id')->getQuotedName($this->platform));
     $this->assertEquals(3, count($billingTable->getIndexes()));
     $this->assertEquals('PRIMARY', $billingTable->getIndex('PRIMARY')->getName());
     $this->assertEquals('`PRIMARY`', $billingTable->getIndex('PRIMARY')->getQuotedName($this->platform));
     $this->assertEquals('billing_product', $billingTable->getIndex('billing_product')->getName());
     $this->assertEquals('`billing_product`', $billingTable->getIndex('billing_product')->getQuotedName($this->platform));
     $this->assertEquals(1, count($billingTable->getForeignKeys()));
     $this->assertEquals('customer_id', $billingTable->getForeignKey('customer_id')->getName());
     $this->assertEquals('`customer_id`', $billingTable->getForeignKey('customer_id')->getQuotedName($this->platform));
 }
Пример #2
0
 /**
  * This function starts the dump process.
  *
  * The passed context contains all information that are necessary to create the dump.
  *
  * @param DumperContextInterface|SqlDumperContext $context
  *
  * @return void
  */
 public function dump(DumperContextInterface $context)
 {
     if (!$context instanceof SqlDumperContext) {
         throw new \InvalidArgumentException('The sql dumper requires the context to be instanceof ' . SqlDumperContext::class);
     }
     // Retrieve list of tables
     $tableFinder = new TableSelector($context->getConnectionHandler()->getConnection());
     $tables = $tableFinder->findTablesToDump($context->getConfig());
     $structureDumper = new StructureDumper($context->getConnectionHandler()->getPlatform(), $context->getDumpOutput(), $context->getLogger());
     $this->dumpPreamble($context);
     $structureDumper->dumpTableStructure($tables);
     $this->dumpTables($context, $tables);
     $structureDumper->dumpConstraints($tables);
 }