Skip to content

Commit

Permalink
(Try to) add a reproducer for #10869
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdude committed Aug 10, 2023
1 parent 597a63a commit 04cb7e0
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH10869Test.php
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);
}
}

0 comments on commit 04cb7e0

Please sign in to comment.