Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dcf8d6a

Browse files
committed
ignore case when checking for existing methods to avoid redeclaration on update
1 parent 6f622ab commit dcf8d6a

2 files changed

Lines changed: 35 additions & 11 deletions

File tree

lib/Doctrine/ORM/Tools/EntityGenerator.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class EntityGenerator
134134

135135
/**
136136
* Visibility of the field
137-
*
137+
*
138138
* @var string
139139
*/
140140
protected $fieldVisibility = 'private';
@@ -570,7 +570,7 @@ protected function generateEntityNamespace(ClassMetadataInfo $metadata)
570570
return 'namespace ' . $this->getNamespace($metadata) .';';
571571
}
572572
}
573-
573+
574574
protected function generateEntityUse()
575575
{
576576
if ($this->generateAnnotations) {
@@ -696,9 +696,9 @@ protected function parseTokensInEntityFile($src)
696696
$inClass = true;
697697
} elseif ($token[0] == T_FUNCTION) {
698698
if ($tokens[$i+2][0] == T_STRING) {
699-
$this->staticReflection[$lastSeenClass]['methods'][] = $tokens[$i+2][1];
699+
$this->staticReflection[$lastSeenClass]['methods'][] = strtolower($tokens[$i+2][1]);
700700
} elseif ($tokens[$i+2] == "&" && $tokens[$i+3][0] == T_STRING) {
701-
$this->staticReflection[$lastSeenClass]['methods'][] = $tokens[$i+3][1];
701+
$this->staticReflection[$lastSeenClass]['methods'][] = strtolower($tokens[$i+3][1]);
702702
}
703703
} elseif (in_array($token[0], array(T_VAR, T_PUBLIC, T_PRIVATE, T_PROTECTED)) && $tokens[$i+2][0] != T_FUNCTION) {
704704
$this->staticReflection[$lastSeenClass]['properties'][] = substr($tokens[$i+2][1], 1);
@@ -761,7 +761,7 @@ protected function hasMethod($method, ClassMetadataInfo $metadata)
761761

762762
return (
763763
isset($this->staticReflection[$metadata->name]) &&
764-
in_array($method, $this->staticReflection[$metadata->name]['methods'])
764+
in_array(strtolower($method), $this->staticReflection[$metadata->name]['methods'])
765765
);
766766
}
767767

@@ -1156,7 +1156,7 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type,
11561156
if ($this->hasMethod($methodName, $metadata)) {
11571157
return '';
11581158
}
1159-
$this->staticReflection[$metadata->name]['methods'][] = $methodName;
1159+
$this->staticReflection[$metadata->name]['methods'][] = strtolower($methodName);
11601160

11611161
$var = sprintf('%sMethodTemplate', $type);
11621162
$template = static::$$var;
@@ -1445,11 +1445,11 @@ protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, Cla
14451445
if (isset($fieldMapping['nullable'])) {
14461446
$column[] = 'nullable=' . var_export($fieldMapping['nullable'], true);
14471447
}
1448-
1448+
14491449
if (isset($fieldMapping['unsigned']) && $fieldMapping['unsigned']) {
14501450
$column[] = 'options={"unsigned"=true}';
14511451
}
1452-
1452+
14531453
if (isset($fieldMapping['columnDefinition'])) {
14541454
$column[] = 'columnDefinition="' . $fieldMapping['columnDefinition'] . '"';
14551455
}
@@ -1571,15 +1571,15 @@ protected function getIdGeneratorTypeString($type)
15711571
private function exportTableOptions(array $options)
15721572
{
15731573
$optionsStr = array();
1574-
1574+
15751575
foreach($options as $name => $option) {
15761576
if (is_array($option)) {
15771577
$optionsStr[] = '"' . $name . '"={' . $this->exportTableOptions($option) . '}';
15781578
} else {
15791579
$optionsStr[] = '"' . $name . '"="' . (string) $option . '"';
1580-
}
1580+
}
15811581
}
1582-
1582+
15831583
return implode(',', $optionsStr);
15841584
}
15851585
}

tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,30 @@ public function testEntityUpdatingWorks()
169169
$this->assertTrue($reflClass->getMethod('getTest')->isPublic(), "Check for public visibility of method 'getTest' failed.");
170170
}
171171

172+
/**
173+
* @group DDC-3152
174+
*/
175+
public function testDoesNotRegenerateExistingMethodsWithDifferentCase()
176+
{
177+
$metadata = $this->generateBookEntityFixture();
178+
179+
// Workaround to change existing fields case (just to simulate the use case)
180+
$metadata->fieldMappings['status']['fieldName'] = 'STATUS';
181+
182+
// Should not throw a PHP fatal error
183+
$this->_generator->writeEntityClass($metadata, $this->_tmpDir);
184+
185+
$this->assertFileExists($this->_tmpDir . "/" . $this->_namespace . "/EntityGeneratorBook.php~");
186+
187+
$this->newInstance($metadata);
188+
$reflClass = new \ReflectionClass($metadata->name);
189+
190+
$this->assertTrue($reflClass->hasProperty('status'));
191+
$this->assertTrue($reflClass->hasProperty('STATUS'));
192+
$this->assertTrue($reflClass->hasMethod('getStatus'));
193+
$this->assertTrue($reflClass->hasMethod('setStatus'));
194+
}
195+
172196
/**
173197
* @group DDC-2121
174198
*/

0 commit comments

Comments
 (0)