diff --git a/src/Propel/Generator/Util/SchemaValidator.php b/src/Propel/Generator/Util/SchemaValidator.php index b76c6b6f8f..7a80892df6 100644 --- a/src/Propel/Generator/Util/SchemaValidator.php +++ b/src/Propel/Generator/Util/SchemaValidator.php @@ -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); } diff --git a/tests/Propel/Tests/Generator/Util/SchemaValidatorTest.php b/tests/Propel/Tests/Generator/Util/SchemaValidatorTest.php index 188c31c23f..3fe76e95d4 100644 --- a/tests/Propel/Tests/Generator/Util/SchemaValidatorTest.php +++ b/tests/Propel/Tests/Generator/Util/SchemaValidatorTest.php @@ -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'));