Skip to content

Commit

Permalink
add namespace to check for duplicate table phpName
Browse files Browse the repository at this point in the history
  • Loading branch information
havvg committed Nov 30, 2011
1 parent a54ac77 commit cc29263
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
13 changes: 11 additions & 2 deletions generator/lib/util/PropelSchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ public function validate()
protected function validateDatabaseTables(Database $database)
{
$phpNames = array();
$namespaces = array();
foreach ($database->getTables() as $table) {
if (in_array($table->getPhpName(), $phpNames)) {
$list = &$phpNames;
if ($table->getNamespace()) {
if (!isset($namespaces[$table->getNamespace()])) {
$namespaces[$table->getNamespace()] = array();
}

$list = &$namespaces[$table->getNamespace()];
}
if (in_array($table->getPhpName(), $list)) {
$this->errors[] = sprintf('Table "%s" declares a phpName already used in another table', $table->getName());
}
$phpNames[]= $table->getPhpName();
$list[]= $table->getPhpName();
$this->validateTableAttributes($table);
$this->validateTableColumns($table);
}
Expand Down
24 changes: 24 additions & 0 deletions test/testsuite/generator/util/PropelSchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ public function testValidateReturnsFalseWhenTwoTablesHaveSamePhpName()
$this->assertContains('Table "bar" declares a phpName already used in another table', $validator->getErrors());
}

public function testValidateReturnsTrueWhenTwoTablesHaveSamePhpNameInDifferentNamespaces()
{
$column1 = new Column('id');
$column1->setPrimaryKey(true);
$table1 = new Table('foo');
$table1->addColumn($column1);
$table1->setNamespace('Foo');

$column2 = new Column('id');
$column2->setPrimaryKey(true);
$table2 = new Table('bar');
$table2->addColumn($column2);
$table2->setPhpName('Foo');
$table2->setNamespace('Bar');

$database = new Database();
$database->addTable($table1);
$database->addTable($table2);
$appData = new AppData();
$appData->addDatabase($database);
$validator = new PropelSchemaValidator($appData);
$this->assertTrue($validator->validate());
}

public function testValidateReturnsFalseWhenTableHasNoPk()
{
$appData = $this->getAppDataForTable(new Table('foo'));
Expand Down

0 comments on commit cc29263

Please sign in to comment.