-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
entity generator - ignore trait properties and methods #632
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
521276f
entity generator - ignore trait properties and methods
Padam87 bb5bdcf
only use already existing reflections
Padam87 8e3e2e7
Revert "only use already existing reflections"
Padam87 8898c91
only check for traits when class exists
Padam87 9797177
check if ReflectionClass::getTraits() method exists
Padam87 937ba63
fixed code duplication issue
Padam87 b3414e3
added unit test
Padam87 3b7b457
minor fixes
Padam87 b7b107b
moved test entities from sandbox
Padam87 bf92a40
skip test if php 5.3
Padam87 73e2aa5
moved php version check
Padam87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\DDC2372; | ||
|
||
/** @Entity @Table(name="addresses") */ | ||
class DDC2372Address | ||
{ | ||
/** | ||
* @Id @Column(type="integer") | ||
* @GeneratedValue(strategy="AUTO") | ||
*/ | ||
private $id; | ||
/** @Column(type="string", length=255) */ | ||
private $street; | ||
/** @OneToOne(targetEntity="User", mappedBy="address") */ | ||
private $user; | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getStreet() | ||
{ | ||
return $this->street; | ||
} | ||
|
||
public function setStreet($street) | ||
{ | ||
$this->street = $street; | ||
} | ||
|
||
public function getUser() | ||
{ | ||
return $this->user; | ||
} | ||
|
||
public function setUser(User $user) | ||
{ | ||
if ($this->user !== $user) { | ||
$this->user = $user; | ||
$user->setAddress($this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\DDC2372; | ||
|
||
use Doctrine\Tests\Models\DDC2372\Traits\DDC2372AddressTrait; | ||
|
||
/** @Entity @Table(name="users") */ | ||
class DDC2372User | ||
{ | ||
use DDC2372AddressTrait; | ||
|
||
/** | ||
* @Id @Column(type="integer") | ||
* @GeneratedValue(strategy="AUTO") | ||
*/ | ||
private $id; | ||
/** @Column(type="string", length=50) */ | ||
private $name; | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName($name) | ||
{ | ||
$this->name = $name; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/Doctrine/Tests/Models/DDC2372/Traits/DDC2372AddressTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\DDC2372\Traits; | ||
|
||
trait DDC2372AddressTrait | ||
{ | ||
/** | ||
* @OneToOne(targetEntity="Doctrine\Tests\Models\DDC2372\DDC2372Address", inversedBy="user") | ||
* @JoinColumn(name="address_id", referencedColumnName="id") | ||
*/ | ||
private $address; | ||
|
||
public function getAddress() | ||
{ | ||
return $this->address; | ||
} | ||
|
||
public function setAddress(Address $address) | ||
{ | ||
if ($this->address !== $address) { | ||
$this->address = $address; | ||
$address->setUser($this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,12 @@ | |
|
||
namespace Doctrine\Tests\ORM\Tools; | ||
|
||
use Doctrine\ORM\Tools\SchemaTool, | ||
Doctrine\ORM\Tools\EntityGenerator, | ||
Doctrine\ORM\Tools\Export\ClassMetadataExporter, | ||
Doctrine\ORM\Mapping\ClassMetadataInfo; | ||
use Doctrine\ORM\Tools\SchemaTool; | ||
use Doctrine\ORM\Tools\EntityGenerator; | ||
use Doctrine\ORM\Tools\Export\ClassMetadataExporter; | ||
use Doctrine\ORM\Mapping\ClassMetadataInfo; | ||
use Doctrine\ORM\Mapping\ClassMetadataFactory; | ||
use Doctrine\Tests\Models\DDC2372\DDC2372User; | ||
|
||
require_once __DIR__ . '/../../TestInit.php'; | ||
|
||
|
@@ -282,7 +284,7 @@ public function testGenerateEntityWithSequenceGenerator() | |
|
||
$filename = $this->_tmpDir . DIRECTORY_SEPARATOR | ||
. $this->_namespace . DIRECTORY_SEPARATOR . 'DDC1784Entity.php'; | ||
|
||
$this->assertFileExists($filename); | ||
require_once $filename; | ||
|
||
|
@@ -330,7 +332,7 @@ public function testGenerateEntityWithMultipleInverseJoinColumns() | |
|
||
$property = new \ReflectionProperty($metadata->name, 'centroCustos'); | ||
$docComment = $property->getDocComment(); | ||
|
||
//joinColumns | ||
$this->assertContains('@JoinColumn(name="idorcamento", referencedColumnName="idorcamento"),', $docComment); | ||
$this->assertContains('@JoinColumn(name="idunidade", referencedColumnName="idunidade")', $docComment); | ||
|
@@ -436,7 +438,7 @@ public function testEntityTypeAlias(array $field) | |
|
||
$entity = new $metadata->name; | ||
$reflClass = new \ReflectionClass($metadata->name); | ||
|
||
$type = $field['phpType']; | ||
$name = $field['fieldName']; | ||
$value = $field['value']; | ||
|
@@ -451,6 +453,34 @@ public function testEntityTypeAlias(array $field) | |
$this->assertEquals($value, $entity->{$getter}()); | ||
} | ||
|
||
/** | ||
* @group DDC-2372 | ||
*/ | ||
public function testTraitPropertiesAndMethodsAreNotDuplicated() | ||
{ | ||
if (PHP_VERSION_ID >= 50400) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO better mark test skipped in other case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed |
||
$cmf = new ClassMetadataFactory(); | ||
$em = $this->_getTestEntityManager(); | ||
$cmf->setEntityManager($em); | ||
|
||
$user = new DDC2372User(); | ||
$metadata = $cmf->getMetadataFor(get_class($user)); | ||
$metadata->name = $this->_namespace . "\DDC2372User"; | ||
$metadata->namespace = $this->_namespace; | ||
|
||
$this->_generator->writeEntityClass($metadata, $this->_tmpDir); | ||
|
||
$this->assertFileExists($this->_tmpDir . "/" . $this->_namespace . "/DDC2372User.php"); | ||
require $this->_tmpDir . "/" . $this->_namespace . "/DDC2372User.php"; | ||
|
||
$reflClass = new \ReflectionClass($metadata->name); | ||
|
||
$this->assertSame($reflClass->hasProperty('address'), false); | ||
$this->assertSame($reflClass->hasMethod('setAddress'), false); | ||
$this->assertSame($reflClass->hasMethod('getAddress'), false); | ||
} | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
|
@@ -470,43 +500,43 @@ public function getEntityTypeAliasDataProvider() | |
'value' => new \DateTime | ||
)), | ||
array(array( | ||
'fieldName' => 'date', | ||
'fieldName' => 'date', | ||
'phpType' => '\\DateTime', | ||
'dbType' => 'date', | ||
'value' => new \DateTime | ||
)), | ||
array(array( | ||
'fieldName' => 'time', | ||
'fieldName' => 'time', | ||
'phpType' => '\DateTime', | ||
'dbType' => 'time', | ||
'value' => new \DateTime | ||
)), | ||
array(array( | ||
'fieldName' => 'object', | ||
'fieldName' => 'object', | ||
'phpType' => '\stdClass', | ||
'dbType' => 'object', | ||
'value' => new \stdClass() | ||
)), | ||
array(array( | ||
'fieldName' => 'bigint', | ||
'fieldName' => 'bigint', | ||
'phpType' => 'integer', | ||
'dbType' => 'bigint', | ||
'value' => 11 | ||
)), | ||
array(array( | ||
'fieldName' => 'smallint', | ||
'fieldName' => 'smallint', | ||
'phpType' => 'integer', | ||
'dbType' => 'smallint', | ||
'value' => 22 | ||
)), | ||
array(array( | ||
'fieldName' => 'text', | ||
'fieldName' => 'text', | ||
'phpType' => 'string', | ||
'dbType' => 'text', | ||
'value' => 'text' | ||
)), | ||
array(array( | ||
'fieldName' => 'blob', | ||
'fieldName' => 'blob', | ||
'phpType' => 'string', | ||
'dbType' => 'blob', | ||
'value' => 'blob' | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move this check at the beginning of the method and return early