forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 1
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 doctrine#10869
- Loading branch information
Showing
2 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
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
75 changes: 75 additions & 0 deletions
75
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,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\ORM\Event\PostPersistEventArgs; | ||
use Doctrine\ORM\Events; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
use function sprintf; | ||
|
||
class GH10869Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpEntitySchema([ | ||
GH10869Entity::class, | ||
]); | ||
} | ||
|
||
public function testPostPersistListenerUpdatingObjectFieldWhileOtherInsertPending(): void | ||
{ | ||
$entity1 = new GH10869Entity(); | ||
$this->_em->persist($entity1); | ||
|
||
$entity2 = new GH10869Entity(); | ||
$this->_em->persist($entity2); | ||
|
||
$this->_em->getEventManager()->addEventListener(Events::postPersist, new class { | ||
public function postPersist(PostPersistEventArgs $args): void | ||
{ | ||
$object = $args->getObject(); | ||
|
||
$objectManager = $args->getObjectManager(); | ||
$object->field = sprintf('test %s', $object->id); | ||
$objectManager->flush(); | ||
} | ||
}); | ||
|
||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
$entity1Reloaded = $this->_em->find(GH10869Entity::class, $entity1->id); | ||
self::assertSame($entity1->field, $entity1Reloaded->field); | ||
|
||
$entity2Reloaded = $this->_em->find(GH10869Entity::class, $entity2->id); | ||
self::assertSame($entity2->field, $entity2Reloaded->field); | ||
} | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH10869Entity | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
* | ||
* @var ?int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\Column(type="text", nullable=true) | ||
* | ||
* @var ?string | ||
*/ | ||
public $field; | ||
} |