Skip to content

Commit

Permalink
fix: attach entity listener when reset metadata factory
Browse files Browse the repository at this point in the history
  • Loading branch information
vuongxuongminh committed Jun 22, 2023
1 parent 829d5fb commit 338deac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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]);
}
}
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']);
self::assertEquals('postLoadHandler', $metadata2->entityListeners['postLoad'][0]['method']);
}

public function testAttachToExistingEntityListeners(): void
Expand Down

0 comments on commit 338deac

Please sign in to comment.