Skip to content

Commit 2a953c5

Browse files
committed
fix: PrePersistEventTest and cs
1 parent abc6a40 commit 2a953c5

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/UnitOfWork.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ private function persistNew(ClassMetadata $class, $entity): void
10601060
$this->entityStates[$oid] = self::STATE_MANAGED;
10611061

10621062
if (!isset($this->entityInsertions[$oid])) {
1063-
$this->scheduleForInsert($entity);;
1063+
$this->scheduleForInsert($entity);
10641064
}
10651065
}
10661066

tests/Tests/ORM/Functional/PrePersistEventTest.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Doctrine\ORM\Mapping\ManyToOne;
1414
use Doctrine\Tests\OrmFunctionalTestCase;
1515

16+
use function uniqid;
17+
1618
/**
1719
* PrePersistEventTest
1820
*/
@@ -24,19 +26,19 @@ protected function setUp(): void
2426

2527
$this->createSchemaForModels(
2628
EntityWithUnmapEntity::class,
27-
EntityWithCascadeAssociation::class,
29+
EntityWithCascadeAssociation::class
2830
);
2931
}
3032

3133
public function testCallingPersistInPrePersistHook(): void
3234
{
3335
$entityWithUnmapped = new EntityWithUnmapEntity();
34-
$entityWithCascade = new EntityWithCascadeAssociation();
36+
$entityWithCascade = new EntityWithCascadeAssociation();
3537

3638
$entityWithUnmapped->unmapped = $entityWithCascade;
37-
$entityWithCascade->cascaded = $entityWithUnmapped;
39+
$entityWithCascade->cascaded = $entityWithUnmapped;
3840

39-
$this->_em->getEventManager()->addEventListener(Events::prePersist, new PrePersistUnmappedPersistListener);
41+
$this->_em->getEventManager()->addEventListener(Events::prePersist, new PrePersistUnmappedPersistListener());
4042
$this->_em->persist($entityWithUnmapped);
4143

4244
$this->assertTrue($this->_em->getUnitOfWork()->isScheduledForInsert($entityWithCascade));
@@ -53,39 +55,58 @@ public function prePersist(PrePersistEventArgs $args): void
5355
if ($object instanceof EntityWithUnmapEntity) {
5456
$uow = $args->getObjectManager()->getUnitOfWork();
5557

56-
if (!$uow->isInIdentityMap($object->unmapped) && !$uow->isScheduledForInsert($object->unmapped) && $object->unmapped) {
58+
if (! $uow->isInIdentityMap($object->unmapped) && ! $uow->isScheduledForInsert($object->unmapped) && $object->unmapped) {
5759
$args->getObjectManager()->persist($object->unmapped);
5860
}
5961
}
6062
}
6163
}
6264

65+
/** @Entity */
6366
#[Entity]
6467
class EntityWithUnmapEntity
6568
{
69+
/**
70+
* @var string
71+
* @Id
72+
* @Column(type="string", length=255)
73+
* @GeneratedValue(strategy="NONE")
74+
*/
6675
#[Id]
6776
#[Column(type: 'string', length: 255)]
6877
#[GeneratedValue(strategy: 'NONE')]
69-
public string $id;
78+
public $id;
7079

71-
public EntityWithCascadeAssociation|null $unmapped = null;
80+
/** @var ?EntityWithCascadeAssociation */
81+
public $unmapped = null;
7282

7383
public function __construct()
7484
{
7585
$this->id = uniqid(self::class, true);
7686
}
7787
}
7888

89+
/** @Entity */
7990
#[Entity]
8091
class EntityWithCascadeAssociation
8192
{
93+
/**
94+
* @var string
95+
* @Id
96+
* @Column(type="string", length=255)
97+
* @GeneratedValue(strategy="NONE")
98+
*/
8299
#[Id]
83100
#[Column(type: 'string', length: 255)]
84101
#[GeneratedValue(strategy: 'NONE')]
85-
public string $id;
102+
public $id;
86103

104+
/**
105+
* @var ?EntityWithUnmapEntity
106+
* @ManyToOne(targetEntity=EntityWithUnmapEntity::class, cascade={"persist"})
107+
*/
87108
#[ManyToOne(targetEntity: EntityWithUnmapEntity::class, cascade: ['persist'])]
88-
public EntityWithUnmapEntity|null $cascaded = null;
109+
public $cascaded = null;
89110

90111
public function __construct()
91112
{

0 commit comments

Comments
 (0)