Backport 'Merge pull request #1098 from encoder32/DDC-1590' to 2.4 branch
This commit is contained in:
parent
71f446f23b
commit
4c8abd5d83
@ -701,9 +701,9 @@ public function __construct()
|
|||||||
*/
|
*/
|
||||||
protected function hasProperty($property, ClassMetadataInfo $metadata)
|
protected function hasProperty($property, ClassMetadataInfo $metadata)
|
||||||
{
|
{
|
||||||
if ($this->extendsClass()) {
|
if ($this->extendsClass() || class_exists($metadata->name)) {
|
||||||
// don't generate property if its already on the base class.
|
// don't generate property if its already on the base class.
|
||||||
$reflClass = new \ReflectionClass($this->getClassToExtend());
|
$reflClass = new \ReflectionClass($this->getClassToExtend() ?: $metadata->name);
|
||||||
if ($reflClass->hasProperty($property)) {
|
if ($reflClass->hasProperty($property)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -723,9 +723,9 @@ public function __construct()
|
|||||||
*/
|
*/
|
||||||
protected function hasMethod($method, ClassMetadataInfo $metadata)
|
protected function hasMethod($method, ClassMetadataInfo $metadata)
|
||||||
{
|
{
|
||||||
if ($this->extendsClass()) {
|
if ($this->extendsClass() || class_exists($metadata->name)) {
|
||||||
// don't generate method if its already on the base class.
|
// don't generate method if its already on the base class.
|
||||||
$reflClass = new \ReflectionClass($this->getClassToExtend());
|
$reflClass = new \ReflectionClass($this->getClassToExtend() ?: $metadata->name);
|
||||||
|
|
||||||
if ($reflClass->hasMethod($method)) {
|
if ($reflClass->hasMethod($method)) {
|
||||||
return true;
|
return true;
|
||||||
|
56
tests/Doctrine/Tests/Models/DDC1590/DDC1590Entity.php
Normal file
56
tests/Doctrine/Tests/Models/DDC1590/DDC1590Entity.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\Models\DDC1590;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @MappedSuperClass
|
||||||
|
*/
|
||||||
|
abstract class DDC1590Entity
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(type="integer")
|
||||||
|
* @GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Column(type="datetime")
|
||||||
|
*/
|
||||||
|
protected $created_at;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get id
|
||||||
|
*
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set createdAt
|
||||||
|
*
|
||||||
|
* @param \DateTime $createdAt
|
||||||
|
*
|
||||||
|
* @return DDC1590User
|
||||||
|
*/
|
||||||
|
public function setCreatedAt($createdAt)
|
||||||
|
{
|
||||||
|
$this->created_at = $createdAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get createdAt
|
||||||
|
*
|
||||||
|
* @return \DateTime
|
||||||
|
*/
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->created_at;
|
||||||
|
}
|
||||||
|
}
|
18
tests/Doctrine/Tests/Models/DDC1590/DDC1590User.php
Normal file
18
tests/Doctrine/Tests/Models/DDC1590/DDC1590User.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\Models\DDC1590;
|
||||||
|
|
||||||
|
use Doctrine\Tests\Models\DDC1590\DDC1590Entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @Table(name="users")
|
||||||
|
*/
|
||||||
|
class DDC1590User extends DDC1590Entity
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Column(type="string", length=255)
|
||||||
|
*/
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Doctrine\Tests\ORM\Tools;
|
namespace Doctrine\Tests\ORM\Tools;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping\ClassMetadataFactory;
|
||||||
use Doctrine\ORM\Tools\SchemaTool,
|
use Doctrine\ORM\Tools\SchemaTool,
|
||||||
Doctrine\ORM\Tools\EntityGenerator,
|
Doctrine\ORM\Tools\EntityGenerator,
|
||||||
Doctrine\ORM\Tools\Export\ClassMetadataExporter,
|
Doctrine\ORM\Tools\Export\ClassMetadataExporter,
|
||||||
@ -454,6 +455,79 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$this->assertEquals($value, $entity->{$getter}());
|
$this->assertEquals($value, $entity->{$getter}());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1590
|
||||||
|
*/
|
||||||
|
public function testMethodsAndPropertiesAreNotDuplicatedInChildClasses()
|
||||||
|
{
|
||||||
|
$cmf = new ClassMetadataFactory();
|
||||||
|
$em = $this->_getTestEntityManager();
|
||||||
|
|
||||||
|
$cmf->setEntityManager($em);
|
||||||
|
|
||||||
|
$ns = $this->_namespace;
|
||||||
|
$nsdir = $this->_tmpDir . '/' . $ns;
|
||||||
|
|
||||||
|
$content = str_replace(
|
||||||
|
'namespace Doctrine\Tests\Models\DDC1590',
|
||||||
|
'namespace ' . $ns,
|
||||||
|
file_get_contents(__DIR__ . '/../../Models/DDC1590/DDC1590User.php')
|
||||||
|
);
|
||||||
|
|
||||||
|
$fname = $nsdir . "/DDC1590User.php";
|
||||||
|
file_put_contents($fname, $content);
|
||||||
|
require $fname;
|
||||||
|
|
||||||
|
|
||||||
|
$metadata = $cmf->getMetadataFor($ns . '\DDC1590User');
|
||||||
|
$this->_generator->writeEntityClass($metadata, $this->_tmpDir);
|
||||||
|
|
||||||
|
// class DDC1590User extends DDC1590Entity { ... }
|
||||||
|
$source = file_get_contents($fname);
|
||||||
|
|
||||||
|
// class _DDC1590User extends DDC1590Entity { ... }
|
||||||
|
$source2 = str_replace('class DDC1590User', 'class _DDC1590User', $source);
|
||||||
|
$fname2 = $nsdir . "/_DDC1590User.php";
|
||||||
|
file_put_contents($fname2, $source2);
|
||||||
|
require $fname2;
|
||||||
|
|
||||||
|
// class __DDC1590User { ... }
|
||||||
|
$source3 = str_replace('class DDC1590User extends DDC1590Entity', 'class __DDC1590User', $source);
|
||||||
|
$fname3 = $nsdir . "/__DDC1590User.php";
|
||||||
|
file_put_contents($fname3, $source3);
|
||||||
|
require $fname3;
|
||||||
|
|
||||||
|
|
||||||
|
// class _DDC1590User extends DDC1590Entity { ... }
|
||||||
|
$rc2 = new \ReflectionClass($ns.'\_DDC1590User');
|
||||||
|
|
||||||
|
$this->assertTrue($rc2->hasProperty('name'));
|
||||||
|
$this->assertTrue($rc2->hasProperty('id'));
|
||||||
|
$this->assertTrue($rc2->hasProperty('created_at'));
|
||||||
|
|
||||||
|
$this->assertTrue($rc2->hasMethod('getName'));
|
||||||
|
$this->assertTrue($rc2->hasMethod('setName'));
|
||||||
|
$this->assertTrue($rc2->hasMethod('getId'));
|
||||||
|
$this->assertFalse($rc2->hasMethod('setId'));
|
||||||
|
$this->assertTrue($rc2->hasMethod('getCreatedAt'));
|
||||||
|
$this->assertTrue($rc2->hasMethod('setCreatedAt'));
|
||||||
|
|
||||||
|
|
||||||
|
// class __DDC1590User { ... }
|
||||||
|
$rc3 = new \ReflectionClass($ns.'\__DDC1590User');
|
||||||
|
|
||||||
|
$this->assertTrue($rc3->hasProperty('name'));
|
||||||
|
$this->assertFalse($rc3->hasProperty('id'));
|
||||||
|
$this->assertFalse($rc3->hasProperty('created_at'));
|
||||||
|
|
||||||
|
$this->assertTrue($rc3->hasMethod('getName'));
|
||||||
|
$this->assertTrue($rc3->hasMethod('setName'));
|
||||||
|
$this->assertFalse($rc3->hasMethod('getId'));
|
||||||
|
$this->assertFalse($rc3->hasMethod('setId'));
|
||||||
|
$this->assertFalse($rc3->hasMethod('getCreatedAt'));
|
||||||
|
$this->assertFalse($rc3->hasMethod('setCreatedAt'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user