1
0
mirror of synced 2025-01-10 11:07:10 +03:00

Merge pull request #1049 from deeky666/DDC-3152

[DDC-3152] Fix redeclaration of methods on entity generation update
This commit is contained in:
Marco Pivetta 2014-06-06 03:48:24 +02:00
commit d71159c6c5
2 changed files with 35 additions and 11 deletions

View File

@ -696,9 +696,9 @@ public function __construct()
$inClass = true; $inClass = true;
} elseif ($token[0] == T_FUNCTION) { } elseif ($token[0] == T_FUNCTION) {
if ($tokens[$i+2][0] == T_STRING) { 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) { } 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) { } 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); $this->staticReflection[$lastSeenClass]['properties'][] = substr($tokens[$i+2][1], 1);
@ -761,7 +761,7 @@ public function __construct()
return ( return (
isset($this->staticReflection[$metadata->name]) && 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)) { if ($this->hasMethod($methodName, $metadata)) {
return ''; return '';
} }
$this->staticReflection[$metadata->name]['methods'][] = $methodName; $this->staticReflection[$metadata->name]['methods'][] = strtolower($methodName);
$var = sprintf('%sMethodTemplate', $type); $var = sprintf('%sMethodTemplate', $type);
$template = static::$$var; $template = static::$$var;

View File

@ -169,6 +169,30 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
$this->assertTrue($reflClass->getMethod('getTest')->isPublic(), "Check for public visibility of method 'getTest' failed."); $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 * @group DDC-2121
*/ */