Skip to content

Commit

Permalink
ignore case when checking for existing methods to avoid redeclaration…
Browse files Browse the repository at this point in the history
… on update
  • Loading branch information
deeky666 committed Jun 5, 2014
1 parent 6f622ab commit dcf8d6a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/Doctrine/ORM/Tools/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class EntityGenerator

/**
* Visibility of the field
*
*
* @var string
*/
protected $fieldVisibility = 'private';
Expand Down Expand Up @@ -570,7 +570,7 @@ protected function generateEntityNamespace(ClassMetadataInfo $metadata)
return 'namespace ' . $this->getNamespace($metadata) .';';
}
}

protected function generateEntityUse()
{
if ($this->generateAnnotations) {
Expand Down Expand Up @@ -696,9 +696,9 @@ protected function parseTokensInEntityFile($src)
$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);
Expand Down Expand Up @@ -761,7 +761,7 @@ protected function hasMethod($method, ClassMetadataInfo $metadata)

return (
isset($this->staticReflection[$metadata->name]) &&
in_array($method, $this->staticReflection[$metadata->name]['methods'])
in_array(strtolower($method), $this->staticReflection[$metadata->name]['methods'])
);
}

Expand Down Expand Up @@ -1156,7 +1156,7 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type,
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;
Expand Down Expand Up @@ -1445,11 +1445,11 @@ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, Cla
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'] . '"';
}
Expand Down Expand Up @@ -1571,15 +1571,15 @@ protected function getIdGeneratorTypeString($type)
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);
}
}
24 changes: 24 additions & 0 deletions tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,30 @@ public function testEntityUpdatingWorks()
$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
*/
Expand Down

0 comments on commit dcf8d6a

Please sign in to comment.