@@ -558,6 +558,52 @@ public function testSoftDeletedObjectIsRemovedPostFlush(): void
558
558
static ::assertNull ($ commentRepo ->find ($ comment ->getId ()));
559
559
}
560
560
561
+ public function testSoftDeletedObjectNotRemovedPostFlush (): void
562
+ {
563
+ $ this ->em ->getFilters ()->disable (self ::SOFT_DELETEABLE_FILTER_NAME );
564
+
565
+ $ repo = $ this ->em ->getRepository (Article::class);
566
+ $ commentRepo = $ this ->em ->getRepository (Comment::class);
567
+
568
+ $ comment = new Comment ();
569
+ $ commentValue = 'Comment 1 ' ;
570
+ $ comment ->setComment ($ commentValue );
571
+
572
+ $ art0 = new Article ();
573
+ $ field = 'title ' ;
574
+ $ value = 'Title 1 ' ;
575
+ $ art0 ->setTitle ($ value );
576
+ $ art0 ->addComment ($ comment );
577
+
578
+ $ this ->em ->persist ($ art0 );
579
+ $ this ->em ->flush ();
580
+
581
+ $ art = $ repo ->findOneBy ([$ field => $ value ]);
582
+
583
+ static ::assertNull ($ art ->getDeletedAt ());
584
+ static ::assertNull ($ comment ->getDeletedAt ());
585
+ static ::assertCount (1 , $ art ->getComments ());
586
+
587
+ $ this ->em ->remove ($ comment );
588
+
589
+ // The Comment has been marked for removal, but not yet flushed. This means the
590
+ // Comment should still be available.
591
+ $ sameComment = $ commentRepo ->find ($ comment ->getId ());
592
+ static ::assertInstanceOf (Comment::class, $ sameComment );
593
+ static ::assertSame ($ comment , $ sameComment );
594
+
595
+ $ this ->em ->flush ();
596
+
597
+ // Now that we've flushed, but the soft-deleteable filter is
598
+ // deactivated. Hence the comment should still be available and find()
599
+ // should return the same instance.
600
+ $ sameComment = $ commentRepo ->find ($ comment ->getId ());
601
+ static ::assertInstanceOf (Comment::class, $ sameComment );
602
+ static ::assertSame ($ comment , $ sameComment );
603
+
604
+ $ this ->em ->getFilters ()->enable (self ::SOFT_DELETEABLE_FILTER_NAME );
605
+ }
606
+
561
607
public function testPostSoftDeleteEventIsDispatched (): void
562
608
{
563
609
$ this ->em ->getEventManager ()->addEventSubscriber (new WithPreAndPostSoftDeleteEventArgsTypeListener ());
0 commit comments