8000 fix EntityGenerator RegenerateEntityIfExists by Fedik · Pull Request #1352 · doctrine/orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix EntityGenerator RegenerateEntityIfExists #1352

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

Merged
merged 1 commit into from
Mar 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Tools/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ protected function parseTokensInEntityFile($src)
*/
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)) {
Expand Down Expand Up @@ -878,7 +878,7 @@ protected function hasProperty($property, ClassMetadataInfo $metadata)
*/
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);

Expand Down
18 changes: 18 additions & 0 deletions tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,24 @@ public function testGeneratedImmutableEmbeddablesClass()
$this->assertTrue($reflParameters[3]->isOptional());
}

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
*/
Expand Down
0