From dcf8d6a86e36882335d392e6462ac3c0382219d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Thu, 5 Jun 2014 15:58:54 +0200 Subject: [PATCH] ignore case when checking for existing methods to avoid redeclaration on update --- lib/Doctrine/ORM/Tools/EntityGenerator.php | 22 ++++++++--------- .../Tests/ORM/Tools/EntityGeneratorTest.php | 24 +++++++++++++++++++ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index 80e67a7b1..83b738666 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -134,7 +134,7 @@ class EntityGenerator /** * Visibility of the field - * + * * @var string */ protected $fieldVisibility = 'private'; @@ -570,7 +570,7 @@ public function __construct() return 'namespace ' . $this->getNamespace($metadata) .';'; } } - + protected function generateEntityUse() { if ($this->generateAnnotations) { @@ -696,9 +696,9 @@ public function __construct() $inClass = true; } elseif ($token[0] == T_FUNCTION) { if ($tokens[$i+2][0] == T_STRING) { - $this->staticReflection[$lastSeenClass]['methods'][] = $tokens[$i+2][1]; + $this->staticReflection[$lastSeenClass]['methods'][] = strtolower($tokens[$i+2][1]); } elseif ($tokens[$i+2] == "&" && $tokens[$i+3][0] == T_STRING) { - $this->staticReflection[$lastSeenClass]['methods'][] = $tokens[$i+3][1]; + $this->staticReflection[$lastSeenClass]['methods'][] = strtolower($tokens[$i+3][1]); } } elseif (in_array($token[0], array(T_VAR, T_PUBLIC, T_PRIVATE, T_PROTECTED)) && $tokens[$i+2][0] != T_FUNCTION) { $this->staticReflection[$lastSeenClass]['properties'][] = substr($tokens[$i+2][1], 1); @@ -761,7 +761,7 @@ public function __construct() return ( isset($this->staticReflection[$metadata->name]) && - in_array($method, $this->staticReflection[$metadata->name]['methods']) + in_array(strtolower($method), $this->staticReflection[$metadata->name]['methods']) ); } @@ -1156,7 +1156,7 @@ public function __construct() if ($this->hasMethod($methodName, $metadata)) { return ''; } - $this->staticReflection[$metadata->name]['methods'][] = $methodName; + $this->staticReflection[$metadata->name]['methods'][] = strtolower($methodName); $var = sprintf('%sMethodTemplate', $type); $template = static::$$var; @@ -1445,11 +1445,11 @@ public function __construct() if (isset($fieldMapping['nullable'])) { $column[] = 'nullable=' . var_export($fieldMapping['nullable'], true); } - + if (isset($fieldMapping['unsigned']) && $fieldMapping['unsigned']) { $column[] = 'options={"unsigned"=true}'; } - + if (isset($fieldMapping['columnDefinition'])) { $column[] = 'columnDefinition="' . $fieldMapping['columnDefinition'] . '"'; } @@ -1571,15 +1571,15 @@ public function __construct() private function exportTableOptions(array $options) { $optionsStr = array(); - + foreach($options as $name => $option) { if (is_array($option)) { $optionsStr[] = '"' . $name . '"={' . $this->exportTableOptions($option) . '}'; } else { $optionsStr[] = '"' . $name . '"="' . (string) $option . '"'; - } + } } - + return implode(',', $optionsStr); } } diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index fb6c0652f..143de62da 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -169,6 +169,30 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue($reflClass->getMethod('getTest')->isPublic(), "Check for public visibility of method 'getTest' failed."); } + /** + * @group DDC-3152 + */ + public function testDoesNotRegenerateExistingMethodsWithDifferentCase() + { + $metadata = $this->generateBookEntityFixture(); + + // Workaround to change existing fields case (just to simulate the use case) + $metadata->fieldMappings['status']['fieldName'] = 'STATUS'; + + // Should not throw a PHP fatal error + $this->_generator->writeEntityClass($metadata, $this->_tmpDir); + + $this->assertFileExists($this->_tmpDir . "/" . $this->_namespace . "/EntityGeneratorBook.php~"); + + $this->newInstance($metadata); + $reflClass = new \ReflectionClass($metadata->name); + + $this->assertTrue($reflClass->hasProperty('status')); + $this->assertTrue($reflClass->hasProperty('STATUS')); + $this->assertTrue($reflClass->hasMethod('getStatus')); + $this->assertTrue($reflClass->hasMethod('setStatus')); + } + /** * @group DDC-2121 */