-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Try to) add a reproducer for #10869
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
tests/Doctrine/Tests/ORM/Functional/Ticket/GH10869Test.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,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\ORM\Event\PostPersistEventArgs; | ||
use Doctrine\ORM\Events; | ||
use Doctrine\Tests\Models\CMS\CmsUser; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
use function sprintf; | ||
|
||
class GH10869Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->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); | ||
} | ||
} |