@@ -653,6 +653,110 @@ private function loadFixture()
653
653
654
654
$ this ->topic = $ article1 ->topic ;
655
655
$ this ->phonenumber = $ phonenumber1 ->phonenumber ;
656
+
657
+ }
658
+
659
+ /**
660
+ * @group DDC-3343
661
+ */
662
+ public function testRemoveManagedElementFromOneToManyExtraLazyCollectionIsNoOp ()
663
+ {
664
+ list ($ userId , $ tweetId ) = $ this ->loadTweetFixture ();
665
+
666
+ /* @var $user User */
667
+ $ user = $ this ->_em ->find (User::CLASSNAME , $ userId );
668
+
669
+ $ user ->tweets ->removeElement ($ this ->_em ->find (Tweet::CLASSNAME , $ tweetId ));
670
+
671
+ $ this ->_em ->clear ();
672
+
673
+ /* @var $user User */
674
+ $ user = $ this ->_em ->find (User::CLASSNAME , $ userId );
675
+
676
+ $ this ->assertCount (1 , $ user ->tweets , 'Element was not removed - need to update the owning side first ' );
677
+ }
678
+
679
+ /**
680
+ * @group DDC-3343
681
+ */
682
+ public function testRemoveManagedElementFromOneToManyExtraLazyCollectionWithoutDeletingTheTargetEntityEntryIsNoOp ()
683
+ {
684
+ list ($ userId , $ tweetId ) = $ this ->loadTweetFixture ();
685
+
686
+ /* @var $user User */
687
+ $ user = $ this ->_em ->find (User::CLASSNAME , $ userId );
688
+
689
+ $ e = $ this ->_em ->find (Tweet::CLASSNAME , $ tweetId );
690
+
691
+ $ user ->tweets ->removeElement ($ e );
692
+
693
+ $ this ->_em ->clear ();
694
+
695
+ /* @var $tweet Tweet */
696
+ $ tweet = $ this ->_em ->find (Tweet::CLASSNAME , $ tweetId );
697
+ $ this ->assertInstanceOf (
698
+ Tweet::CLASSNAME ,
699
+ $ tweet ,
700
+ 'Even though the collection is extra lazy, the tweet should not have been deleted '
701
+ );
702
+
703
+ $ this ->assertInstanceOf (
704
+ User::CLASSNAME ,
705
+ $ tweet ->author ,
706
+ 'Tweet author link has not been removed - need to update the owning side first '
707
+ );
708
+ }
709
+
710
+ /**
711
+ * @group DDC-3343
712
+ */
713
+ public function testRemovingManagedLazyProxyFromExtraLazyOneToManyDoesRemoveTheAssociationButNotTheEntity ()
714
+ {
715
+ list ($ userId , $ tweetId ) = $ this ->loadTweetFixture ();
716
+
717
+ /* @var $user User */
718
+ $ user = $ this ->_em ->find (User::CLASSNAME , $ userId );
719
+ $ tweet = $ this ->_em ->getReference (Tweet::CLASSNAME , $ tweetId );
720
+
721
+ $ user ->tweets ->removeElement ($ this ->_em ->getReference (Tweet::CLASSNAME , $ tweetId ));
722
+
723
+ $ this ->_em ->clear ();
724
+
725
+ /* @var $tweet Tweet */
726
+ $ tweet = $ this ->_em ->find (Tweet::CLASSNAME , $ tweet ->id );
727
+ $ this ->assertInstanceOf (
728
+ Tweet::CLASSNAME ,
729
+ $ tweet ,
730
+ 'Even though the collection is extra lazy, the tweet should not have been deleted '
731
+ );
732
+
733
+ $ this ->assertNull ($ tweet ->author );
734
+
735
+ /* @var $user User */
736
+ $ user = $ this ->_em ->find (User::CLASSNAME , $ userId );
737
+
738
+ $ this ->assertCount (1 , $ user ->tweets , 'Element was not removed - need to update the owning side first ' );
739
+ }
740
+
741
+ /**
742
+ * @return int[] ordered tuple: user id and tweet id
743
+ */
744
+ private function loadTweetFixture ()
745
+ {
746
+ $ user = new User ();
747
+ $ tweet = new Tweet ();
748
+
749
+ $ user ->name = 'ocramius ' ;
750
+ $ tweet ->content = 'The cat is on the table ' ;
751
+
752
+ $ user ->addTweet ($ tweet );
753
+
754
+ $ this ->_em ->persist ($ user );
755
+ $ this ->_em ->persist ($ tweet );
756
+ $ this ->_em ->flush ();
757
+ $ this ->_em ->clear ();
758
+
759
+ return array ($ user ->id , $ tweet ->id );
656
760
}
657
761
658
762
/**
0 commit comments