diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH10869Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH10869Test.php new file mode 100644 index 00000000000..e1610e66469 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH10869Test.php @@ -0,0 +1,56 @@ +useModelSet('cms'); + + parent::setUp(); + } + + public function testPostPersistListenerUpdatingObject(): void + { + $joe = new CmsUser(); + $joe->username = 'joe'; + $joe->name = 'Joe'; + $this->_em->persist($joe); + + $this->_em->getEventManager()->addEventListener(Events::postPersist, new class { + public function postPersist(PostPersistEventArgs $args): void + { + $object = $args->getObject(); + + if (! $object instanceof CmsUser) { + return; + } + + $objectManager = $args->getObjectManager(); + + if ($object->status === null) { + $object->status = sprintf('joe-id=%s', $object->id); + $objectManager->flush(); + } + } + }); + + $this->_em->flush(); + $this->_em->clear(); + + $joeReloaded = $this->_em->find(CmsUser::class, $joe->id); + + self::assertNotNull($joeReloaded->status); + self::assertSame($joe->status, $joeReloaded->status); + } +}