Skip to content
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

Fix attach entity listener when reset class metadata factory #10786

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 0 additions & 2 deletions lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,5 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event)
$metadata->addEntityListener($listener['event'], $listener['class'], $listener['method']);
}
}

unset($this->entityListeners[$metadata->name]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this listener, what it does is attach entity listeners as soon as class metadata is loaded. After that, it considers its job done forever, hence the unset (to save memory I guess).

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ public function testAttachEntityListeners(): void
self::assertCount(1, $metadata->entityListeners['postLoad']);
self::assertEquals('postLoadHandler', $metadata->entityListeners['postLoad'][0]['method']);
self::assertEquals(AttachEntityListenersListenerTestListener::class, $metadata->entityListeners['postLoad'][0]['class']);

// Can reattach entity listeners even class metadata factory recreated.
$factory2 = new ClassMetadataFactory();
$factory2->setEntityManager($this->em);

$metadata2 = $factory2->getMetadataFor(AttachEntityListenersListenerTestFooEntity::class);

self::assertArrayHasKey('postLoad', $metadata2->entityListeners);
self::assertEquals(AttachEntityListenersListenerTestListener::class, $metadata2->entityListeners['postLoad'][0]['class']);
self::assertCount(1, $metadata2->entityListeners['postLoad']);
vuongxuongminh marked this conversation as resolved.
Show resolved Hide resolved
self::assertEquals('postLoadHandler', $metadata2->entityListeners['postLoad'][0]['method']);
}

public function testAttachToExistingEntityListeners(): void
Expand Down