public function testTableNamespaceAndDbNamespace()
 {
     $d = new Database('fooDb');
     $d->setNamespace('Baz');
     $t = new Table('fooTable');
     $t->setNamespace('Foo\\Bar');
     $d->addTable($t);
     $builder = new TestableOMBuilder2($t);
     $this->assertEquals('Baz\\Foo\\Bar', $builder->getNamespace(), 'Builder namespace is composed from the database and table namespaces when both are set');
 }
Esempio n. 2
0
$table3->addColumns([$column31, $column32]);
$table4 = new Table('blog_tag');
$table4->setDescription('The list of tags');
$table4->setNamespace('Blog');
$table4->setPackage('Acme.Blog');
$table4->addColumns([$column41, $column42]);
$table5 = new Table('blog_post_tag');
$table5->setNamespace('Blog');
$table5->setPackage('Acme.Blog');
$table5->setCrossRef();
$table5->addColumns([$column51, $column52]);
$table5->addForeignKeys([$fkPostTag, $fkTagPost]);
$table6 = new Table('cms_page');
$table6->setPhpName('Page');
$table6->setNamespace('Cms');
$table6->setBaseClass('Acme\\Model\\PublicationActiveRecord');
$table6->setPackage('Acme.Cms');
$table6->addColumns([$column61, $column62, $column63, $column64]);
$table6->addIndex($pageContentFulltextIdx);
$table6->addVendorInfo(new VendorInfo('mysql', ['Engine' => 'MyISAM']));
/* Database */
$database = new Database('acme_blog', new MysqlPlatform());
$database->setSchema('acme');
$database->setTablePrefix('acme_');
$database->setNamespace('Acme\\Model');
$database->setBaseClass('Acme\\Model\\ActiveRecord');
$database->setPackage('Acme');
$database->setHeavyIndexing();
$database->addVendorInfo(new VendorInfo('mysql', ['Engine' => 'InnoDB', 'Charset' => 'utf8']));
$database->addTables([$table1, $table2, $table3, $table4, $table5, $table6]);
return $database;
Esempio n. 3
0
 public function testAddTable()
 {
     $table = $this->getTableMock('books', ['namespace' => 'Acme\\Model']);
     $database = new Database();
     $database->setPackage('acme');
     $database->setNamespace('Acme\\Model');
     $database->addTable($table);
     $this->assertSame(1, $database->countTables());
     $this->assertCount(1, $database->getTablesForSql());
     $this->assertTrue($database->hasTable('books'));
     $this->assertTrue($database->hasTable('books', true));
     $this->assertFalse($database->hasTable('BOOKS'));
     $this->assertTrue($database->hasTableByPhpName('Books'));
     $this->assertSame($table, $database->getTable('books'));
     $this->assertSame($table, $database->getTableByPhpName('Books'));
 }
Esempio n. 4
0
 public function testAddTableSkipsDatabaseNamespaceWhenTableNamespaceIsAbsolute()
 {
     $db = new Database();
     $db->setNamespace('Foo');
     $t1 = new Table('t1');
     $t1->setNamespace('\\Bar');
     $db->addTable($t1);
     $this->assertEquals('Bar', $t1->getNamespace());
 }
Esempio n. 5
0
 /**
  * Builds the model classes from the database schema.
  *
  * @return Database The built-out Database (with all tables, etc.)
  */
 protected function buildModel()
 {
     $config = $this->getGeneratorConfig();
     $connection = $this->getConnection();
     $databaseName = $config->getConfigProperty('reverse.connection');
     $database = new Database($this->getDatabaseName());
     $database->setPlatform($config->getConfiguredPlatform($connection), $databaseName);
     $database->setDefaultIdMethod(IdMethod::NATIVE);
     $this->getNamespace() && $database->setNamespace($this->getNamespace());
     $buildConnection = $config->getBuildConnection($databaseName);
     $this->log(sprintf('Reading database structure of database `%s` using dsn `%s`', $this->getDatabaseName(), $buildConnection['dsn']));
     $parser = $config->getConfiguredSchemaParser($connection, $databaseName);
     $this->log(sprintf('SchemaParser `%s` chosen', get_class($parser)));
     $nbTables = $parser->parse($database);
     $excludeTables = $config->getConfigProperty('exclude_tables');
     $tables = [];
     foreach ($database->getTables() as $table) {
         /* Was copypasted from DatabaseComparator::isTableExcluded() */
         $skip = false;
         $tablename = $table->getName();
         if (in_array($tablename, $excludeTables)) {
             $skip = true;
         } else {
             foreach ($excludeTables as $exclude_tablename) {
                 if (preg_match('/^' . str_replace('*', '.*', $exclude_tablename) . '$/', $tablename)) {
                     $skip = true;
                 }
             }
         }
         $skip && $database->removeTable($table);
     }
     $this->log(sprintf('Successfully reverse engineered %d tables', $nbTables));
     return $database;
 }