Merge branch 'hotfix/#1352-entity-generator-new-class-metadata-hotfix-2.4' into 2.4
Close #1352
This commit is contained in:
commit
0cf7e0e628
@ -701,7 +701,7 @@ public function __construct()
|
||||
*/
|
||||
protected function hasProperty($property, ClassMetadataInfo $metadata)
|
||||
{
|
||||
if ($this->extendsClass() || class_exists($metadata->name)) {
|
||||
if ($this->extendsClass() || (!$this->isNew && class_exists($metadata->name))) {
|
||||
// don't generate property if its already on the base class.
|
||||
$reflClass = new \ReflectionClass($this->getClassToExtend() ?: $metadata->name);
|
||||
if ($reflClass->hasProperty($property)) {
|
||||
@ -723,7 +723,7 @@ public function __construct()
|
||||
*/
|
||||
protected function hasMethod($method, ClassMetadataInfo $metadata)
|
||||
{
|
||||
if ($this->extendsClass() || class_exists($metadata->name)) {
|
||||
if ($this->extendsClass() || (!$this->isNew && class_exists($metadata->name))) {
|
||||
// don't generate method if its already on the base class.
|
||||
$reflClass = new \ReflectionClass($this->getClassToExtend() ?: $metadata->name);
|
||||
|
||||
|
@ -527,7 +527,25 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->assertFalse($rc3->hasMethod('getCreatedAt'));
|
||||
$this->assertFalse($rc3->hasMethod('setCreatedAt'));
|
||||
}
|
||||
|
||||
|
||||
public function testRegenerateEntityClass()
|
||||
{
|
||||
$metadata = $this->generateBookEntityFixture();
|
||||
$this->loadEntityClass($metadata);
|
||||
|
||||
$className = basename(str_replace('\\', '/', $metadata->name));
|
||||
$path = $this->_tmpDir . '/' . $this->_namespace . '/' . $className . '.php';
|
||||
$classTest = file_get_contents($path);
|
||||
|
||||
$this->_generator->setRegenerateEntityIfExists(true);
|
||||
$this->_generator->setBackupExisting(false);
|
||||
|
||||
$this->_generator->writeEntityClass($metadata, $this->_tmpDir);
|
||||
$classNew = file_get_contents($path);
|
||||
|
||||
$this->assertSame($classTest,$classNew);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@ -639,6 +657,19 @@ class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMetadataInfo $metadata
|
||||
*/
|
||||
private function loadEntityClass(ClassMetadataInfo $metadata)
|
||||
{
|
||||
$className = basename(str_replace('\\', '/', $metadata->name));
|
||||
$path = $this->_tmpDir . '/' . $this->_namespace . '/' . $className . '.php';
|
||||
|
||||
$this->assertFileExists($path);
|
||||
|
||||
require_once $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param \ReflectionProperty $property
|
||||
|
Loading…
Reference in New Issue
Block a user