Skip to content

Commit

Permalink
Merge pull request #163 from K-Phoen/port-pr-207
Browse files Browse the repository at this point in the history
Fix: port PR #207 from Propel
  • Loading branch information
willdurand committed Mar 30, 2012
2 parents f94c492 + 09cbb05 commit ea93747
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Propel/Generator/Util/SchemaValidator.php
Expand Up @@ -53,11 +53,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 tests/Propel/Tests/Generator/Util/SchemaValidatorTest.php
Expand Up @@ -74,6 +74,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 SchemaValidator($appData);
$this->assertTrue($validator->validate());
}

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

0 comments on commit ea93747

Please sign in to comment.