File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the zenstruck/foundry package.
5+ *
6+ * (c) Kevin Bond <[email protected] > 7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Zenstruck \Foundry \Tests \Fixture \Entity \EdgeCases ;
13+
14+ use Doctrine \ORM \Mapping as ORM ;
15+
16+ #[ORM \Entity]
17+ #[ORM \HasLifecycleCallbacks]
18+ class EntityWithLifecycleCallback
19+ {
20+ #[ORM \Id]
21+ #[ORM \GeneratedValue]
22+ #[ORM \Column(type: 'integer ' )]
23+ public ?int $ id = null ;
24+
25+ #[ORM \Column(nullable: true )]
26+ public ?string $ prop = null ;
27+
28+ #[ORM \PrePersist]
29+ public function prePersist (): void
30+ {
31+ $ this ->prop = 'pre-persist ' ;
32+ }
33+ }
Original file line number Diff line number Diff line change 2323use Zenstruck \Foundry \Test \ResetDatabase ;
2424use Zenstruck \Foundry \Tests \Fixture \DoctrineCascadeRelationship \ChangesEntityRelationshipCascadePersist ;
2525use Zenstruck \Foundry \Tests \Fixture \DoctrineCascadeRelationship \UsingRelationships ;
26+ use Zenstruck \Foundry \Tests \Fixture \Entity \EdgeCases \EntityWithLifecycleCallback ;
2627use Zenstruck \Foundry \Tests \Fixture \Entity \EdgeCases \IndexedOneToMany ;
2728use Zenstruck \Foundry \Tests \Fixture \Entity \EdgeCases \InversedOneToOneWithManyToOne ;
2829use Zenstruck \Foundry \Tests \Fixture \Entity \EdgeCases \InversedOneToOneWithNonNullableOwning ;
3839use Zenstruck \Foundry \Tests \Integration \RequiresORM ;
3940
4041use function Zenstruck \Foundry \Persistence \persistent_factory ;
42+ use function Zenstruck \Foundry \Persistence \refresh ;
4143
4244/**
4345 * @author Nicolas PHILIPPE <[email protected] > @@ -319,6 +321,19 @@ public function it_can_find_and_object_with_ulid_as_id(): void
319321 persistent_factory (ManyToOneWithAutoGeneratedUlid \OwningSide::class)::random (['inverseSide ' => $ inverseSide ]);
320322 }
321323
324+ /**
325+ * @test
326+ */
327+ #[Test]
328+ public function it_works_with_doctrine_lifecycle_callbacks (): void
329+ {
330+ $ entity = persistent_factory (EntityWithLifecycleCallback::class)->create ();
331+ self ::assertSame ('pre-persist ' , $ entity ->prop );
332+
333+ refresh ($ entity );
334+ self ::assertSame ('pre-persist ' , $ entity ->prop );
335+ }
336+
322337 /**
323338 * @test
324339 */
You can’t perform that action at this time.
0 commit comments