From cc29263a1074fb9cf8388637990e4eea311d4a09 Mon Sep 17 00:00:00 2001 From: Toni Uebernickel Date: Wed, 30 Nov 2011 16:10:49 +0100 Subject: [PATCH] add namespace to check for duplicate table phpName --- generator/lib/util/PropelSchemaValidator.php | 13 ++++++++-- .../util/PropelSchemaValidatorTest.php | 24 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/generator/lib/util/PropelSchemaValidator.php b/generator/lib/util/PropelSchemaValidator.php index 41acabe85..c12dfcf09 100644 --- a/generator/lib/util/PropelSchemaValidator.php +++ b/generator/lib/util/PropelSchemaValidator.php @@ -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); } diff --git a/test/testsuite/generator/util/PropelSchemaValidatorTest.php b/test/testsuite/generator/util/PropelSchemaValidatorTest.php index 0b86b13c0..15c2fe9ef 100644 --- a/test/testsuite/generator/util/PropelSchemaValidatorTest.php +++ b/test/testsuite/generator/util/PropelSchemaValidatorTest.php @@ -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'));