diff --git a/generator/lib/model/Inheritance.php b/generator/lib/model/Inheritance.php index 37be5bb00..5ef1976ce 100644 --- a/generator/lib/model/Inheritance.php +++ b/generator/lib/model/Inheritance.php @@ -34,7 +34,8 @@ class Inheritance extends XMLElement */ protected function setupObject() { - $this->key = $this->getAttribute("key"); + // Clean key from special characters not allowed in constant names + $this->key = rtrim(preg_replace('/(\W|_)+/', '_', $this->getAttribute("key")), '_'); $this->className = $this->getAttribute("class"); $this->pkg = $this->getAttribute("package"); $this->ancestor = $this->getAttribute("extends"); diff --git a/test/testsuite/generator/builder/om/GeneratedObjectConstantNameTest.php b/test/testsuite/generator/builder/om/GeneratedObjectConstantNameTest.php new file mode 100644 index 000000000..6de786760 --- /dev/null +++ b/test/testsuite/generator/builder/om/GeneratedObjectConstantNameTest.php @@ -0,0 +1,90 @@ + + * @package generator.builder.om + */ +class GeneratedObjectConstantNameTest extends PHPUnit_Framework_TestCase +{ + /** + * Test normal string as single inheritance key + */ + public function testSingleInheritanceKeyNormalString() + { + $schema = << + + + + + +
+ +XML; + $this->assertEmptyBuilderOutput($schema); + } + + /** + * Test string with dashes as single inheritance key (original cause for this whole test) + */ + + public function testSingleInheritanceKeyStringWithDashes() + { + $schema = << + + + + + +
+ +XML; + $this->assertEmptyBuilderOutput($schema); + } + + /** + * Test string with special characters as single inheritance key + */ + + public function testSingleInheritanceKeyStringWithSpecialChars() + { + $schema = << + + + + + +
+ +XML; + $this->assertEmptyBuilderOutput($schema); + } + + protected function assertEmptyBuilderOutput($schema) + { + $builder = new PropelQuickBuilder(); + $builder->setSchema($schema); + + ob_start(); + $builder->buildClasses(); + $output = preg_replace('/[\r\n]/', '', ob_get_contents()); + ob_end_clean(); + $this->assertEquals('', $output); + } +}